问题
I write some Applescripts that are gonna be deployed on machines set to different languages. I just realised that when I, for example, is waiting for an application to open a window (e.g., a Save/Open dialog) my scripts fail because on systems set to other languages these windows are not called Save or Open anymore, but rather have a translated name.
How do I handle this? Do windows have "universal base name" I can look for rather than the name I Accessibility Inspector shows? And I guess there are other strings that also are translated that I might need to access (menus, menu commands and so on) - my problem is not limited to just Open/Save dialogs.
回答1:
AppleScript supports NSLocalizedString
(localized string
). You need to refer to and pull out the strings from the corresponding framework bundles.
For example:
set finderPath to path to application "Finder"
(localized string "A16" in bundle finderPath)
The result is:
- in English: You can’t undo this action.
- in German: Diese Aktion kann nicht widerrufen werden.
localized string
has two optional parameters:
from table
: The name of the strings file excluding the “.strings” suffix (default is “Localizable”)in bundle
: An alias or file reference to the bundle containing the strings file (default is the current application/script bundle)
来源:https://stackoverflow.com/questions/42638429/strings-in-applescript-depends-on-the-system-language-are-there-universal-name