I want to add a contextual menu in InDesign. I use this command: app.menus.item("Text Context Menu").submenus.item("MY_MENU")
It works, but when I switch my local to another than english (ex.: fr_FR) , it won’t add because I have to use this: app.menus.item("Menu contextuel Texte").submenus.item("MY_MENU")
I’ve tried with ‘index’ attribut, but it changes depending on the language.
How can I add menu items without knowing the name which is language dependent.
As a smart solution here is to identify the Menu using UXP API you can use the menuID property rather than the menu name, wich is consistent across different languages. then you can use entrypoints in your manifest file to define commands and panels dynamically. this method ensures the proper integration of menu items irrespective of the language settings.
I don’t know where @YesserKira got that constant, and whether it works for the particular InDesign menu. Even when it does, I’d find it suboptimal if UXP reinvents the wheel of string IDs referring to the application string database.
On the other hand, I’d appreciate a UXP subsystem supporting third party localizations similar to ExtendScript’s ScriptUI localization features. Sorry, I digress.
If you continue with the traditional way to refer to translatable strings with the “$ID/” prefix, as mentioned by @PeterKahrel , have a look at app.findKeyStrings() to find key string candidates from your localized string, and use app.translateKeyString() to resolve that key string. e.g. app.translateKeyString(“Text Context Menu”) should yield the menu name, even if the prefix approach fails for UXP.