diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index e405e615f5f..ac8c32a764d 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -641,17 +641,7 @@ Translation note: - - - - - - - - - - diff --git a/PowerEditor/installer/nativeLang/french.xml b/PowerEditor/installer/nativeLang/french.xml index 1ada21f6367..bae93c70687 100644 --- a/PowerEditor/installer/nativeLang/french.xml +++ b/PowerEditor/installer/nativeLang/french.xml @@ -641,17 +641,7 @@ Translation note: - - - - - - - - - - diff --git a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml index 6a0a8c30fd6..86a8bc98041 100644 --- a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml +++ b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml @@ -614,7 +614,7 @@ - + diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index cfd4d50b6f6..71a3f500600 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -6997,6 +6997,7 @@ bool Notepad_plus::reloadLang() } } + _nativeLangSpeaker.resetShortcutMenuNameMap(); updateCommandShortcuts(); _accelerator.updateFullMenu(); @@ -8711,12 +8712,9 @@ void Notepad_plus::createMonitoringThread(Buffer* pBuf) void Notepad_plus::updateCommandShortcuts() { NppParameters& nppParam = NppParameters::getInstance(); - vector & shortcuts = nppParam.getUserShortcuts(); - size_t len = shortcuts.size(); - for (size_t i = 0; i < len; ++i) + for (CommandShortcut& csc : nppParam.getUserShortcuts()) { - CommandShortcut & csc = shortcuts[i]; unsigned long id = csc.getID(); generic_string localizedMenuName = _nativeLangSpeaker.getNativeLangMenuString(id); generic_string menuName = localizedMenuName; @@ -8742,6 +8740,8 @@ void Notepad_plus::updateCommandShortcuts() } csc.setName(wstring2string(menuName, CP_UTF8).c_str(), wstring2string(shortcutName, CP_UTF8).c_str()); + + csc.setCategoryFromMenu(_mainMenuHandle); } } diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index 97f6130eae2..da7f0a95d6b 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -300,9 +300,7 @@ void ShortcutMapper::fillOutBabyGrid() if (cshortcuts[i].isEnabled()) //avoid empty strings for better performance _babygrid.setText(cs_index, 2, string2wstring(cshortcuts[i].toString(), CP_UTF8).c_str()); - const TCHAR* category = cshortcuts[i].getCategory(); - generic_string categoryStr = nativeLangSpeaker->getShortcutMapperLangStr((std::string(wstring2string(category, CP_UTF8)) + "Category").c_str(), category); - _babygrid.setText(cs_index, 3, categoryStr.c_str()); + _babygrid.setText(cs_index, 3, cshortcuts[i].getCategory()); if (isMarker) isMarker = _babygrid.setMarker(false); diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index c9b39ba6531..47e275ccecc 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -1224,34 +1224,48 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR return FALSE; } -CommandShortcut::CommandShortcut(const Shortcut& sc, long id) : Shortcut(sc), _id(id) +void CommandShortcut::setCategoryFromMenu(HMENU hMenu) { - _shortcutName = string2wstring(sc.getName(), CP_UTF8); + NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); + if ( _id >= IDM_WINDOW_SORT_FN_ASC and _id <= IDM_WINDOW_SORT_FS_DSC) - _category = TEXT("Window"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "Window", L"Window"); + else if ( _id >= IDM_VIEW_GOTO_ANOTHER_VIEW and _id <= IDM_VIEW_LOAD_IN_NEW_INSTANCE) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View"); + else if (_id == IDM_EDIT_LTR || _id == IDM_EDIT_RTL) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View"); + else if (_id == IDC_PREV_DOC || _id == IDC_NEXT_DOC) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View"); + else if (_id == IDM_FORMAT_TODOS || _id == IDM_FORMAT_TOUNIX || _id == IDM_FORMAT_TOMAC) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit", L"Edit"); + else if (_id == IDM_EDIT_AUTOCOMPLETE || _id == IDM_EDIT_AUTOCOMPLETE_CURRENTFILE || _id == IDM_EDIT_FUNCCALLTIP || + _id == IDM_EDIT_AUTOCOMPLETE_PATH || _id == IDM_EDIT_FUNCCALLTIP_PREVIOUS || _id == IDM_EDIT_FUNCCALLTIP_NEXT) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit", L"Edit"); + else if (_id == IDM_LANGSTYLE_CONFIG_DLG) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "settings", L"Settings"); + else if (_id == IDM_MACRO_STARTRECORDINGMACRO ||_id == IDM_MACRO_STOPRECORDINGMACRO || _id == IDM_MACRO_RUNMULTIMACRODLG || + _id == IDM_MACRO_PLAYBACKRECORDEDMACRO ||_id == IDM_MACRO_SAVECURRENTMACRO || _id == IDC_EDIT_TOGGLEMACRORECORDING) + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "macro", L"Macro"); + + else if ( _id < IDM_EDIT) - _category = TEXT("File"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "file", L"File"); else if ( _id < IDM_SEARCH) - _category = TEXT("Edit"); - else if (((_id >= IDM_EDIT_AUTOCOMPLETE) && (_id <= IDM_EDIT_AUTOCOMPLETE_PATH)) || - ((_id >= IDM_EDIT_FUNCCALLTIP_PREVIOUS) && (_id <= IDM_EDIT_FUNCCALLTIP_NEXT))) - _category = TEXT("Edit"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit",L"Edit"); else if ( _id < IDM_VIEW) - _category = TEXT("Search"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "search", L"Search"); else if ( _id < IDM_FORMAT) - _category = TEXT("View"); - else if ( _id >= IDM_VIEW_GOTO_ANOTHER_VIEW and _id <= IDM_VIEW_LOAD_IN_NEW_INSTANCE) - _category = TEXT("View"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View"); else if ( _id < IDM_LANG) - _category = TEXT("Format"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "encoding", L"Encoding"); else if ( _id < IDM_ABOUT) - _category = TEXT("Lang"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "language", L"Language"); else if ( _id < IDM_SETTING) - _category = TEXT("About"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "about", L"About"); else if ( _id < IDM_TOOL) - _category = TEXT("Setting"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "settings", L"Settings"); else if ( _id < IDM_EXECUTE) - _category = TEXT("Tool"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "tools", L"Tools"); else - _category = TEXT("Execute"); + pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "run", L"Run"); } diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index bb10eeff369..a7157e4e2f3 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -184,7 +184,10 @@ protected : class CommandShortcut : public Shortcut { public: - CommandShortcut(const Shortcut& sc, long id); + CommandShortcut(const Shortcut& sc, long id) : Shortcut(sc), _id(id){ + _shortcutName = string2wstring(getName(), CP_UTF8); + }; + void setCategoryFromMenu(HMENU hMenu); unsigned long getID() const {return _id;}; void setID(unsigned long id) { _id = id;}; const TCHAR * getCategory() const { return _category.c_str(); }; diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 5c5a08ec6c0..408ecc4566f 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -284,6 +284,43 @@ MenuPosition & getMenuPosition(const char *id) return menuPos[nbSubMenuPos-1]; } +// Get string from map. +// If string not found, get string from menu, then put it into map for the next use. +void NativeLangSpeaker::getMainMenuEntryName(std::wstring& dest, HMENU hMenu, const char* menuId, const wchar_t* defaultDest) +{ + const auto iter = _shortcutMenuEntryNameMap.find(menuId); + if (iter == _shortcutMenuEntryNameMap.end()) + { + MenuPosition& menuPos = getMenuPosition(menuId); + if (menuPos._x != -1 && menuPos._y == -1 && menuPos._z == -1) + { + wchar_t str[MAX_PATH]; + GetMenuString(hMenu, menuPos._x, str, MAX_PATH, MF_BYPOSITION); + dest = str; + dest.erase(std::remove(dest.begin(), dest.end(), '&'), dest.end()); + _shortcutMenuEntryNameMap[menuId] = dest; + + } + else + { + if (strcmp(menuId, "about") == 0) + { + dest = getShortcutMapperLangStr("AboutCategory", defaultDest); + } + else + { + _shortcutMenuEntryNameMap[menuId] = defaultDest; + dest = defaultDest; + } + } + } + else + { + dest = iter->second; + } +} + + void NativeLangSpeaker::changeMenuLang(HMENU menuHandle) { if (nullptr == _nativeLangA) diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index 3be14cd35b5..62a70fded68 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -17,6 +17,7 @@ #pragma once +#include #include "Common.h" #include "tinyxmlA.h" @@ -83,6 +84,11 @@ class NativeLangSpeaker { generic_string getAttrNameStr(const TCHAR *defaultStr, const char *nodeL1Name, const char *nodeL2Name, const char *nodeL3Name = "name") const; generic_string getAttrNameByIdStr(const TCHAR *defaultStr, TiXmlNodeA *targetNode, const char *nodeL1Value, const char *nodeL1Name = "id", const char *nodeL2Name = "name") const; generic_string getLocalizedStrFromID(const char *strID, const generic_string& defaultString) const; + void getMainMenuEntryName(std::wstring& dest, HMENU hMenu, const char* menuIdStr, const wchar_t* defaultDest); + + void resetShortcutMenuNameMap() { + _shortcutMenuEntryNameMap.clear(); + }; int messageBox(const char *msgBoxTagName, HWND hWnd, const TCHAR *message, const TCHAR *title, int msgBoxType, int intInfo = 0, const TCHAR *strInfo = NULL); private: @@ -90,6 +96,7 @@ class NativeLangSpeaker { int _nativeLangEncoding; bool _isRTL; const char *_fileName; + std::map _shortcutMenuEntryNameMap; };