Applescript中的字符串取决于系统语言-是否有通用名称? [英] Strings in Applescript depends on the system language - are there universal names?
问题描述
我写了一些Applescripts,这些Applescripts将被部署在设置为不同语言的机器上.我只是意识到,例如,当我等待应用程序打开一个窗口(例如,保存/打开"对话框)时,我的脚本会失败,因为在设置为其他语言的系统上,这些窗口不再称为保存"或打开",而是有一个翻译后的名字.
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.
我该如何处理? Windows是否具有我可以查找的通用基本名称",而不是我的Accessibility Inspector显示的名称?而且我想还有可能需要访问的其他字符串也已翻译(菜单,菜单命令等)-我的问题不仅限于打开/保存对话框.
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.
推荐答案
AppleScript支持NSLocalizedString
(localized string
).您需要参考并从相应的框架包中拉出字符串.
AppleScript supports NSLocalizedString
(localized string
). You need to refer to and pull out the strings from the corresponding framework bundles.
例如:
set finderPath to path to application "Finder"
(localized string "A16" in bundle finderPath)
结果是:
- 英语:您无法撤消此操作.
- 德语: Diese Aktion kann nicht widerufen werden.
- in English: You can’t undo this action.
- in German: Diese Aktion kann nicht widerrufen werden.
localized string
具有两个可选参数:
-
from table
:不包括后缀".strings"的字符串文件的名称(默认为"Localizable") -
in bundle
:对包含字符串文件的分发包的别名或文件引用(默认为当前应用程序/脚本分发包)
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)
这篇关于Applescript中的字符串取决于系统语言-是否有通用名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!