Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 56 additions & 40 deletions src/NppJsonViewer/Define.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "PluginInterface.h"
#include <windows.h>

// Define the number of plugin commands here
enum class CallBackID : int
Expand All @@ -14,48 +15,62 @@ enum class CallBackID : int
};
constexpr const int nTotalCommandCount = static_cast<int>(CallBackID::ABOUT) + 1;

// Define plugin name here
const TCHAR PLUGIN_NAME[] = TEXT("JSON Viewer");
const TCHAR PLUGIN_CONFIG[] = TEXT("JSONViewer.ini");
// ---------------------------------------------------------------------------
// Localizable UI strings.
// These are loaded from the STRINGTABLE resource at init time, so they
// automatically follow the system's UI language (English, Chinese, etc.)
// ---------------------------------------------------------------------------
void LoadLocalizedStrings(HMODULE hModule);

// Text which can be considered for localization
const TCHAR TITLE_JSON_PANEL[] = TEXT("JSON Viewer");
const TCHAR MENU_SHOW_JSON_PANEL[] = TEXT("Show &JSON Viewer");
const TCHAR MENU_FORMAT_JSON[] = TEXT("&Format JSON");
const TCHAR MENU_COMPRESS_JSON[] = TEXT("&Compress JSON");
const TCHAR MENU_SORT_BY_KEY[] = TEXT("Sort by &key (ascending)");
const TCHAR MENU_SETTING[] = TEXT("&Settings");
const TCHAR MENU_ABOUT[] = TEXT("&About");
const TCHAR MENU_SEPERATOR[] = TEXT("-SEPARATOR-");

const TCHAR TOOLTIP_REFRESH[] = TEXT("Refresh JSON tree");
const TCHAR TOOLTIP_VALIDATE[] = TEXT("Validate JSON to detect any errors");
const TCHAR TOOLTIP_FORMAT[] = TEXT("Format JSON to beautify it");
const TCHAR TOOLTIP_SEARCH[] = TEXT("Search in JSON");
// Plugin name and config filename (config filename must not be localized)
extern const TCHAR* PLUGIN_NAME;
const TCHAR PLUGIN_CONFIG[] = TEXT("JSONViewer.ini");

// Menu and panel
extern const TCHAR* TITLE_JSON_PANEL;
extern const TCHAR* MENU_SHOW_JSON_PANEL;
extern const TCHAR* MENU_FORMAT_JSON;
extern const TCHAR* MENU_COMPRESS_JSON;
extern const TCHAR* MENU_SORT_BY_KEY;
extern const TCHAR* MENU_SETTING;
extern const TCHAR* MENU_ABOUT;
extern const TCHAR* MENU_SEPERATOR;

// Tooltips
extern const TCHAR* TOOLTIP_REFRESH;
extern const TCHAR* TOOLTIP_VALIDATE;
extern const TCHAR* TOOLTIP_FORMAT;
extern const TCHAR* TOOLTIP_SEARCH;

// URLs (not localized)
const TCHAR URL_SOURCE_CODE[] = TEXT("https://github.com/NPP-JSONViewer/JSON-Viewer");
const TCHAR URL_REPORT_ISSUE[] = TEXT("https://github.com/NPP-JSONViewer/JSON-Viewer/issues/new");

const TCHAR JSON_ROOT[] = TEXT("JSON");

const TCHAR JSON_ERROR_TITLE[] = TEXT("JSON Viewer: Error");
const TCHAR JSON_WARNING_TITLE[] = TEXT("JSON Viewer: Warning");
const TCHAR JSON_INFO_TITLE[] = TEXT("JSON Viewer: Information");

const TCHAR JSON_ERR_PARSE[] = TEXT("Unable to parse JSON. Please ensure a valid JSON string is selected.");
const TCHAR JSON_ERR_VALIDATE[] = TEXT("An error occurred while parsing the JSON. Check the current selection for the potential issue.");
const TCHAR JSON_ERR_VALIDATE_SUCCESS[] = TEXT("The JSON appears valid. No errors were found during validation.");
const TCHAR JSON_ERR_SAVE_SETTING[] = TEXT("Could not save the settings. Please try again.");
const TCHAR JSON_ERR_MULTI_SELECTION[] = TEXT("JSON-Viewer does not currently support multiple selections.");

const TCHAR STR_VERSION[] = TEXT("Version: ");
const TCHAR STR_COPY[] = TEXT("Copy");
const TCHAR STR_COPYNAME[] = TEXT("Copy name");
const TCHAR STR_COPYVALUE[] = TEXT("Copy value");
const TCHAR STR_COPYPATH[] = TEXT("Copy path");
const TCHAR STR_EXPANDALL[] = TEXT("Expand all");
const TCHAR STR_COLLAPSEALL[] = TEXT("Collapse all");

// Misc
extern const TCHAR* JSON_ROOT;

// Message titles
extern const TCHAR* JSON_ERROR_TITLE;
extern const TCHAR* JSON_WARNING_TITLE;
extern const TCHAR* JSON_INFO_TITLE;

// Message content
extern const TCHAR* JSON_ERR_PARSE;
extern const TCHAR* JSON_ERR_VALIDATE;
extern const TCHAR* JSON_ERR_VALIDATE_SUCCESS;
extern const TCHAR* JSON_ERR_SAVE_SETTING;
extern const TCHAR* JSON_ERR_MULTI_SELECTION;

// Context menu and misc
extern const TCHAR* STR_VERSION;
extern const TCHAR* STR_COPY;
extern const TCHAR* STR_COPYNAME;
extern const TCHAR* STR_COPYVALUE;
extern const TCHAR* STR_COPYPATH;
extern const TCHAR* STR_EXPANDALL;
extern const TCHAR* STR_COLLAPSEALL;

// INI section/key names (must NOT be localized - config compatibility)
const TCHAR STR_INI_FORMATTING_SEC[] = TEXT("Formatting");
const TCHAR STR_INI_FORMATTING_EOL[] = TEXT("EOL");
const TCHAR STR_INI_FORMATTING_LINE[] = TEXT("LINE_FORMATTING");
Expand All @@ -70,9 +85,10 @@ const TCHAR STR_INI_OTHER_IGNORE_COMMENT[] = TEXT("IGNORE_COMMENT");
const TCHAR STR_INI_OTHER_IGNORE_COMMA[] = TEXT("IGNORE_TRAILLING_COMMA");
const TCHAR STR_INI_OTHER_REPLACE_UNDEFINED[] = TEXT("REPLACE_VALUE_UNDEFINED");

const TCHAR STR_SRCH_SEARCHING[] = TEXT("Searching for: ");
const TCHAR STR_SRCH_NOTFOUND[] = TEXT("Not found: ");
const TCHAR STR_SRCH_NOMOREFOUND[] = TEXT("No more found: ");
// Search status
extern const TCHAR* STR_SRCH_SEARCHING;
extern const TCHAR* STR_SRCH_NOTFOUND;
extern const TCHAR* STR_SRCH_NOMOREFOUND;

enum class LineEnding
{
Expand Down
178 changes: 178 additions & 0 deletions src/NppJsonViewer/LocalizedStrings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include "Define.h"
#include "resource.h"
#include <tchar.h>
#include <string.h>

// Storage for all localized strings loaded from STRINGTABLE resource.
// Sized generously to hold the longest expected string.
struct LocalizedStrings
{
TCHAR szPluginName[64];
TCHAR szTitleJsonPanel[64];
TCHAR szMenuShowJsonPanel[64];
TCHAR szMenuFormatJson[64];
TCHAR szMenuCompressJson[64];
TCHAR szMenuSortByKey[64];
TCHAR szMenuSeparator[64];
TCHAR szMenuSetting[64];
TCHAR szMenuAbout[64];
TCHAR szTooltipRefresh[64];
TCHAR szTooltipValidate[128];
TCHAR szTooltipFormat[128];
TCHAR szTooltipSearch[64];
TCHAR szJsonRoot[32];
TCHAR szJsonErrorTitle[64];
TCHAR szJsonWarningTitle[64];
TCHAR szJsonInfoTitle[64];
TCHAR szJsonErrParse[256];
TCHAR szJsonErrValidate[256];
TCHAR szJsonErrValidateSuccess[256];
TCHAR szJsonErrSaveSetting[128];
TCHAR szJsonErrMultiSelection[256];
TCHAR szStrVersion[32];
TCHAR szStrCopy[32];
TCHAR szStrCopyName[32];
TCHAR szStrCopyValue[32];
TCHAR szStrCopyPath[32];
TCHAR szStrExpandAll[32];
TCHAR szStrCollapseAll[32];
TCHAR szSrchSearching[64];
TCHAR szSrchNotFound[64];
TCHAR szSrchNoMoreFound[64];
};

static LocalizedStrings s_strings = {};
static bool s_bLoaded = false;

// Fallback (English) values - used if LoadString fails for any reason.
#define FALLBACK(name, val) static const TCHAR s_fallback_##name[] = TEXT(val)

FALLBACK(PluginName, "JSON Viewer");
FALLBACK(TitleJsonPanel, "JSON Viewer");
FALLBACK(MenuShowJsonPanel, "Show &JSON Viewer");
FALLBACK(MenuFormatJson, "&Format JSON");
FALLBACK(MenuCompressJson, "&Compress JSON");
FALLBACK(MenuSortByKey, "Sort by &key (ascending)");
FALLBACK(Separator, "-SEPARATOR-");
FALLBACK(Setting, "&Settings");
FALLBACK(About, "&About");
FALLBACK(TooltipRefresh, "Refresh JSON tree");
FALLBACK(TooltipValidate, "Validate JSON to detect any errors");
FALLBACK(TooltipFormat, "Format JSON to beautify it");
FALLBACK(TooltipSearch, "Search in JSON");
FALLBACK(JsonRoot, "JSON");
FALLBACK(ErrorTitle, "JSON Viewer: Error");
FALLBACK(WarningTitle, "JSON Viewer: Warning");
FALLBACK(InfoTitle, "JSON Viewer: Information");
FALLBACK(ErrParse, "Unable to parse JSON. Please ensure a valid JSON string is selected.");
FALLBACK(ErrValidate, "An error occurred while parsing the JSON. Check the current selection for the potential issue.");
FALLBACK(ErrValidateSuccess, "The JSON appears valid. No errors were found during validation.");
FALLBACK(ErrSaveSetting, "Could not save the settings. Please try again.");
FALLBACK(ErrMultiSelection, "JSON-Viewer does not currently support multiple selections.");
FALLBACK(StrVersion, "Version: ");
FALLBACK(StrCopy, "Copy");
FALLBACK(StrCopyName, "Copy name");
FALLBACK(StrCopyValue, "Copy value");
FALLBACK(StrCopyPath, "Copy path");
FALLBACK(StrExpandAll, "Expand all");
FALLBACK(StrCollapseAll, "Collapse all");
FALLBACK(SrchSearching, "Searching for: ");
FALLBACK(SrchNotFound, "Not found: ");
FALLBACK(SrchNoMoreFound, "No more found: ");

#undef FALLBACK

static int LoadStrSafe(HMODULE hMod, UINT uId, LPTSTR pszBuf, int cchBuf, const TCHAR* pszFallback)
{
int cch = LoadString(hMod, uId, pszBuf, cchBuf);
if (cch == 0)
{
// Fallback to default (English) string
lstrcpyn(pszBuf, pszFallback, cchBuf);
cch = static_cast<int>(_tcslen(pszBuf));
}
return cch;
}

void LoadLocalizedStrings(HMODULE hModule)
{
if (s_bLoaded)
return;
s_bLoaded = true;

#define LOAD(field, id, fallback) \
LoadStrSafe(hModule, id, s_strings.sz##field, _countof(s_strings.sz##field), s_fallback_##fallback)

LOAD(PluginName, IDS_PLUGIN_NAME, PluginName);
LOAD(TitleJsonPanel, IDS_TITLE_JSON_PANEL, TitleJsonPanel);
LOAD(MenuShowJsonPanel, IDS_MENU_SHOW_JSON_PANEL, MenuShowJsonPanel);
LOAD(MenuFormatJson, IDS_MENU_FORMAT_JSON, MenuFormatJson);
LOAD(MenuCompressJson, IDS_MENU_COMPRESS_JSON, MenuCompressJson);
LOAD(MenuSortByKey, IDS_MENU_SORT_BY_KEY, MenuSortByKey);
LOAD(MenuSeparator, IDS_MENU_SEPARATOR, Separator);
LOAD(MenuSetting, IDS_MENU_SETTING, Setting);
LOAD(MenuAbout, IDS_MENU_ABOUT, About);
LOAD(TooltipRefresh, IDS_TOOLTIP_REFRESH, TooltipRefresh);
LOAD(TooltipValidate, IDS_TOOLTIP_VALIDATE, TooltipValidate);
LOAD(TooltipFormat, IDS_TOOLTIP_FORMAT, TooltipFormat);
LOAD(TooltipSearch, IDS_TOOLTIP_SEARCH, TooltipSearch);
LOAD(JsonRoot, IDS_JSON_ROOT, JsonRoot);
LOAD(JsonErrorTitle, IDS_JSON_ERROR_TITLE, ErrorTitle);
LOAD(JsonWarningTitle, IDS_JSON_WARNING_TITLE, WarningTitle);
LOAD(JsonInfoTitle, IDS_JSON_INFO_TITLE, InfoTitle);
LOAD(JsonErrParse, IDS_JSON_ERR_PARSE, ErrParse);
LOAD(JsonErrValidate, IDS_JSON_ERR_VALIDATE, ErrValidate);
LOAD(JsonErrValidateSuccess, IDS_JSON_ERR_VALIDATE_SUCCESS, ErrValidateSuccess);
LOAD(JsonErrSaveSetting, IDS_JSON_ERR_SAVE_SETTING, ErrSaveSetting);
LOAD(JsonErrMultiSelection, IDS_JSON_ERR_MULTI_SELECTION, ErrMultiSelection);
LOAD(StrVersion, IDS_STR_VERSION, StrVersion);
LOAD(StrCopy, IDS_STR_COPY, StrCopy);
LOAD(StrCopyName, IDS_STR_COPYNAME, StrCopyName);
LOAD(StrCopyValue, IDS_STR_COPYVALUE, StrCopyValue);
LOAD(StrCopyPath, IDS_STR_COPYPATH, StrCopyPath);
LOAD(StrExpandAll, IDS_STR_EXPANDALL, StrExpandAll);
LOAD(StrCollapseAll, IDS_STR_COLLAPSEALL, StrCollapseAll);
LOAD(SrchSearching, IDS_SRCH_SEARCHING, SrchSearching);
LOAD(SrchNotFound, IDS_SRCH_NOTFOUND, SrchNotFound);
LOAD(SrchNoMoreFound, IDS_SRCH_NOMOREFOUND, SrchNoMoreFound);

#undef LOAD
}

// Extern variable definitions - point to the loaded buffer
#define DEFINE_STR(name, field) const TCHAR* name = s_strings.sz##field

DEFINE_STR(PLUGIN_NAME, PluginName);
DEFINE_STR(TITLE_JSON_PANEL, TitleJsonPanel);
DEFINE_STR(MENU_SHOW_JSON_PANEL, MenuShowJsonPanel);
DEFINE_STR(MENU_FORMAT_JSON, MenuFormatJson);
DEFINE_STR(MENU_COMPRESS_JSON, MenuCompressJson);
DEFINE_STR(MENU_SORT_BY_KEY, MenuSortByKey);
DEFINE_STR(MENU_SETTING, MenuSetting);
DEFINE_STR(MENU_ABOUT, MenuAbout);
DEFINE_STR(MENU_SEPERATOR, MenuSeparator);
DEFINE_STR(TOOLTIP_REFRESH, TooltipRefresh);
DEFINE_STR(TOOLTIP_VALIDATE, TooltipValidate);
DEFINE_STR(TOOLTIP_FORMAT, TooltipFormat);
DEFINE_STR(TOOLTIP_SEARCH, TooltipSearch);
DEFINE_STR(JSON_ROOT, JsonRoot);
DEFINE_STR(JSON_ERROR_TITLE, JsonErrorTitle);
DEFINE_STR(JSON_WARNING_TITLE, JsonWarningTitle);
DEFINE_STR(JSON_INFO_TITLE, JsonInfoTitle);
DEFINE_STR(JSON_ERR_PARSE, JsonErrParse);
DEFINE_STR(JSON_ERR_VALIDATE, JsonErrValidate);
DEFINE_STR(JSON_ERR_VALIDATE_SUCCESS, JsonErrValidateSuccess);
DEFINE_STR(JSON_ERR_SAVE_SETTING, JsonErrSaveSetting);
DEFINE_STR(JSON_ERR_MULTI_SELECTION, JsonErrMultiSelection);
DEFINE_STR(STR_VERSION, StrVersion);
DEFINE_STR(STR_COPY, StrCopy);
DEFINE_STR(STR_COPYNAME, StrCopyName);
DEFINE_STR(STR_COPYVALUE, StrCopyValue);
DEFINE_STR(STR_COPYPATH, StrCopyPath);
DEFINE_STR(STR_EXPANDALL, StrExpandAll);
DEFINE_STR(STR_COLLAPSEALL, StrCollapseAll);
DEFINE_STR(STR_SRCH_SEARCHING, SrchSearching);
DEFINE_STR(STR_SRCH_NOTFOUND, SrchNotFound);
DEFINE_STR(STR_SRCH_NOMOREFOUND, SrchNoMoreFound);

#undef DEFINE_STR
7 changes: 7 additions & 0 deletions src/NppJsonViewer/NPPJSONViewer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
Expand All @@ -123,6 +124,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
Expand All @@ -137,6 +139,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
Expand All @@ -149,6 +152,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
Expand All @@ -160,6 +164,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
Expand All @@ -172,6 +177,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NPPJSONVIEWER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
Expand Down Expand Up @@ -199,6 +205,7 @@
<ClCompile Include="SliderCtrl.cpp" />
<ClCompile Include="TreeViewCtrl.cpp" />
<ClCompile Include="npp_include\DockingFeature\StaticDialog.cpp" />
<ClCompile Include="LocalizedStrings.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AboutDlg.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/NppJsonViewer/NppJsonPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "NppJsonPlugin.h"
#include "resource.h"
#include "Profile.h"
#include "Define.h"
#include <tchar.h>

NppJsonPlugin* NppJsonPlugin::Callback::m_pNppJsonPlugin = nullptr;
Expand All @@ -14,6 +15,7 @@ NppJsonPlugin::NppJsonPlugin()
void NppJsonPlugin::PluginInit(HMODULE hModule)
{
m_hModule = hModule;
LoadLocalizedStrings(hModule);
}

void NppJsonPlugin::PluginCleanup() {}
Expand Down
Loading