Skip to content

Commit 3ea62bd

Browse files
committed
Make dialogs localizable
Closes #5 [^1] --- [^1]: Esp. wrt dialogs, cf. #5 (comment)
1 parent 7d08602 commit 3ea62bd

29 files changed

Lines changed: 1526 additions & 11 deletions

src/Forms/AboutDlg.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "TextConv.h"
1212
#include "HtmlTag.h"
1313
#include "AboutDlg.h"
14+
#include "dialogs.h"
1415

1516
// Handle static text in default theme mode
1617
#define WM_CTLCOLORSTATIC_LITE WM_CTLCOLORSTATIC
@@ -27,12 +28,17 @@ struct DialogHyperlink {
2728
WNDPROC defWndProc;
2829
};
2930

31+
struct LocalizedResource {
32+
const char *locale;
33+
int dialog, modal;
34+
};
35+
3036
INT_PTR CALLBACK modalDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
3137
INT_PTR CALLBACK linkCtrlWndProc(HWND hLink, UINT message, WPARAM wParam, LPARAM lParam);
38+
LocalizedResource getLocalizedResource();
3239

3340
Version pluginVersion;
3441
HFONT hDefaultFont, hActiveLinkFont;
35-
bool themeInitialized = false;
3642

3743
DialogHyperlink linkCtrls[] = {
3844
{ ID_RELEASE_NOTES_LINK, nullptr },
@@ -45,6 +51,32 @@ DialogHyperlink linkCtrls[] = {
4551
{ ID_TINYXML_LINK, nullptr },
4652
};
4753
constexpr size_t nbLinkCtrls = ARRAYSIZE(linkCtrls);
54+
55+
constexpr LocalizedResource dialogLocales[] = {
56+
{ "arabic", AR_ABOUT_DLG, AR_UNICODE_DLG },
57+
{ "catalan", CA_ABOUT_DLG, CA_UNICODE_DLG },
58+
{ "chineseSimplified", ZH_ABOUT_DLG, ZH_UNICODE_DLG },
59+
{ "dutch", NL_ABOUT_DLG, NL_UNICODE_DLG },
60+
{ "farsi", FA_ABOUT_DLG, FA_UNICODE_DLG },
61+
{ "french", FR_ABOUT_DLG, FR_UNICODE_DLG },
62+
{ "german", DE_ABOUT_DLG, DE_UNICODE_DLG },
63+
{ "hebrew", HE_ABOUT_DLG, HE_UNICODE_DLG },
64+
{ "hindi", HI_ABOUT_DLG, HI_UNICODE_DLG },
65+
{ "italian", IT_ABOUT_DLG, IT_UNICODE_DLG },
66+
{ "japanese", JP_ABOUT_DLG, JP_UNICODE_DLG },
67+
{ "korean", KO_ABOUT_DLG, KO_UNICODE_DLG },
68+
{ "polish", PL_ABOUT_DLG, PL_UNICODE_DLG },
69+
{ "portuguese", PT_ABOUT_DLG, PT_UNICODE_DLG },
70+
{ "brazilian_portuguese", BR_PT_ABOUT_DLG, BR_PT_UNICODE_DLG },
71+
{ "romanian", RO_ABOUT_DLG, RO_UNICODE_DLG },
72+
{ "russian", RU_ABOUT_DLG, RU_UNICODE_DLG },
73+
{ "sinhala", SI_ABOUT_DLG, SI_UNICODE_DLG },
74+
{ "spanish", ES_ABOUT_DLG, ES_UNICODE_DLG },
75+
{ "spanish_ar", ES_ABOUT_DLG, ES_UNICODE_DLG },
76+
{ "tamil", TA_ABOUT_DLG, TA_UNICODE_DLG },
77+
{ "ukrainian", UK_ABOUT_DLG, UK_UNICODE_DLG },
78+
};
79+
constexpr size_t nbDialogLocales = ARRAYSIZE(dialogLocales);
4880
}
4981

5082
// --------------------------------------------------------------------------------------
@@ -57,7 +89,7 @@ AboutDlg::AboutDlg(HINSTANCE hInst, NppData const &data) : StaticDialog() {
5789
// --------------------------------------------------------------------------------------
5890
void AboutDlg::show() {
5991
if (!isCreated())
60-
create(ID_ABOUT_HTML_TAG_DLG);
92+
create(getLocalizedResource().dialog);
6193

6294
goToCenter();
6395
}
@@ -133,8 +165,8 @@ INT_PTR CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
133165
prefixTxt.append(L"0000");
134166
::SetDlgItemTextW(_hSelf, ID_UNICODE_USER_FMT_TXT, &(prefixTxt)[0]);
135167
}
136-
toggleDarkMode(_hSelf, themeInitialized ? dmfHandleChange : dmfInit);
137-
themeInitialized = true;
168+
toggleDarkMode(_hSelf, _themeInitialized ? dmfHandleChange : dmfInit);
169+
_themeInitialized = true;
138170
result = TRUE;
139171
break;
140172
}
@@ -172,7 +204,7 @@ INT_PTR CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
172204
bool hideOnReturn = true;
173205
switch (wParam & 0xffff) {
174206
case ID_UNICODE_CONFIG_LINK:
175-
::DialogBoxParamW(_hInst, MAKEINTRESOURCE(ID_UNICODE_FMT_CONFIG_DLG), _hSelf,
207+
::DialogBoxParamW(_hInst, MAKEINTRESOURCE(getLocalizedResource().modal), _hSelf,
176208
(DLGPROC)modalDlgProc, reinterpret_cast<LPARAM>(this));
177209
hideOnReturn = false;
178210
break;
@@ -285,4 +317,19 @@ INT_PTR CALLBACK linkCtrlWndProc(HWND hCtrl, UINT message, WPARAM wParam, LPARAM
285317
}
286318
return defWndProc(hCtrl, message, wParam, lParam);
287319
}
320+
// --------------------------------------------------------------------------------------
321+
LocalizedResource getLocalizedResource() {
322+
LocalizedResource res{
323+
LocalizedPlugin::defaultLangId.c_str(),
324+
ID_ABOUT_HTML_TAG_DLG,
325+
ID_UNICODE_FMT_CONFIG_DLG,
326+
};
327+
for (size_t i = 0; i < nbDialogLocales; i++) {
328+
if (plugin.menuLocale() == dialogLocales[i].locale) {
329+
res = dialogLocales[i];
330+
break;
331+
}
332+
}
333+
return res;
334+
}
288335
}

src/Forms/AboutDlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AboutDlg final : public StaticDialog {
2121
void show();
2222

2323
private:
24+
bool _themeInitialized = false;
2425
INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
2526
};
2627
#endif // ~ABOUT_DLG_H

0 commit comments

Comments
 (0)