From 52d3c36e3590c83cfe5f36454e5a674054fda34c Mon Sep 17 00:00:00 2001 From: ArkadiuszMichalski <2730894+ArkadiuszMichalski@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:30:54 +0100 Subject: [PATCH] Make tray icon context menu translatable Fix #11628, close #13241 --- PowerEditor/installer/nativeLang/english.xml | 10 ++++- .../nativeLang/english_customizable.xml | 10 ++++- PowerEditor/src/NppBigSwitch.cpp | 1 + PowerEditor/src/localization.cpp | 27 +++++++++++++ PowerEditor/src/localization.h | 39 ++++++++++--------- 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index f3886e610..16fb5554e 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -385,8 +385,6 @@ The comments are here for explanation, it's not necessary to translate them. - - @@ -424,6 +422,14 @@ The comments are here for explanation, it's not necessary to translate them. + + + + + + + + diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index 5993450a5..558a5d42b 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -385,8 +385,6 @@ The comments are here for explanation, it's not necessary to translate them. - - @@ -424,6 +422,14 @@ The comments are here for explanation, it's not necessary to translate them. + + + + + + + + diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index e9a042344..d45bb1d1b 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2597,6 +2597,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa HMENU hTrayIconMenu; // shortcut menu hmenu = ::LoadMenu(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDR_SYSTRAYPOPUP_MENU)); hTrayIconMenu = ::GetSubMenu(hmenu, 0); + _nativeLangSpeaker.changeLangTrayIconContexMenu(hTrayIconMenu); SetForegroundWindow(hwnd); TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, hwnd, NULL); PostMessage(hwnd, WM_NULL, 0, 0); diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 917de22ab..430aaca3e 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -489,6 +489,33 @@ void NativeLangSpeaker::changeLangTabDropContextMenu(HMENU hCM) } } +void NativeLangSpeaker::changeLangTrayIconContexMenu(HMENU hCM) +{ + if (!_nativeLangA) return; + + TiXmlNodeA *tryIconMenu = _nativeLangA->FirstChild("Menu"); + if (!tryIconMenu) return; + + tryIconMenu = tryIconMenu->FirstChild("TrayIcon"); + if (!tryIconMenu) return; + + WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); + + for (TiXmlNodeA *childNode = tryIconMenu->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(hCM, id, MF_BYCOMMAND, id, nameW); + } + } +} void NativeLangSpeaker::changeConfigLang(HWND hDlg) { diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index b93a1227c..2d3c74d8a 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -38,13 +38,14 @@ public: class NativeLangSpeaker { public: - NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){}; - void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false); + NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){}; + void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false); void changeConfigLang(HWND hDlg); void changeLangTabContextMenu(HMENU hCM); TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL, size_t titleMaxSize = 0); void changeLangTabDropContextMenu(HMENU hCM); + void changeLangTrayIconContexMenu(HMENU hCM); generic_string getSubMenuEntryName(const char *nodeName) const; generic_string getNativeLangMenuString(int itemID) const; generic_string getShortcutNameString(int itemID) const; @@ -52,29 +53,29 @@ public: void changeMenuLang(HMENU menuHandle); void changeShortcutLang(); void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); - void changeUserDefineLang(UserDefineDialog *userDefineDlg); + void changeUserDefineLang(UserDefineDialog *userDefineDlg); void changeUserDefineLangPopupDlg(HWND hDlg); - void changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg); - void changePrefereceDlgLang(PreferenceDlg & preference); + void changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg); + void changePrefereceDlgLang(PreferenceDlg & preference); void changePluginsAdminDlgLang(PluginsAdminDlg & pluginsAdminDlg); bool getDoSaveOrNotStrings(generic_string& title, generic_string& msg); - bool isRTL() const { - return _isRTL; - }; + bool isRTL() const { + return _isRTL; + }; - const char * getFileName() const { - return _fileName; - }; + const char * getFileName() const { + return _fileName; + }; - const TiXmlNodeA * getNativeLangA() { - return _nativeLangA; - }; + const TiXmlNodeA * getNativeLangA() { + return _nativeLangA; + }; - int getLangEncoding() const { - return _nativeLangEncoding; - }; + int getLangEncoding() const { + return _nativeLangEncoding; + }; bool getMsgBoxLang(const char *msgBoxTagName, generic_string & title, generic_string & message); generic_string getShortcutMapperLangStr(const char *nodeName, const TCHAR *defaultStr) const; generic_string getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const TCHAR *defaultStr) const; @@ -87,8 +88,8 @@ public: private: TiXmlNodeA *_nativeLangA; int _nativeLangEncoding; - bool _isRTL; - const char *_fileName; + bool _isRTL; + const char *_fileName; };