internationalizationapplescripttranslation

Strings in Applescript depends on the system language - are there universal names?


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.


Solution

  • 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:


    localized string has two optional parameters: