Localised strings for Hook scripts

The Bear scripts for German kindly posted by @Heikau reminded me that Hook Scripts that depend on Menu strings far have, so far, been more Anglo-Saxon than self-localising.

On the whole it should, I think, be possible to do this with osascript (AppleScript, or JS for Automation) incantations of the form:

on localTerm(fpApp, strTerm)
    get localized string of strTerm in bundle (POSIX file fpApp)
end localTerm

So, for example to fetch Copier le lien vers la note from the localisation strings in the Bear.app bundle (in place of “Copy Link to Note”), we should be able to use the definition above and write:

localTerm("/Applications/Bear.app", "Copy Link To Note")

As in the Script Editor screenshot below:

2 Likes

Or in JS:

(() => {
    'use strict';

    // sa :: Standard Additions Library
    const sa = Object.assign(
        Application.currentApplication(), {
            includeStandardAdditions: true
        });

    // localTerm :: FilePath -> String -> String
    const localTerm = fpApp => strTerm =>
        sa.localizedString(strTerm, {
            inBundle: fpApp
        });

    return localTerm(Path('/Applications/Bear.app'))(
        'Copy Link To Note'
    );
})();

1 Like