I have created an Automator workflow service (not Automator application!) under Mac OS X 10.7 (Lion) whose core is an AppleScript action. The action needs to notify the user at several points about its operations (including a possible abort) and I would like the messages to be localized in the user’s language.
Following Apple‘s string localization guidelines, I have created locale resource folders inside the workflow bundle (i.e. <bundle>/Contents/Resources/<lang>.lproj/ folders) and placed Localizable.strings files inside containing string mappings in UTF-16 encoding. I call these using the localized string of <string_mapping_token> construct of AppleScript.
This works just fine when packed into an AppleScript application bundle (tested and confirmed), but localization fails when the exact same script and structure are used inside an Automator generated service – all I get are the raw tokens (note the localized menu names in ServicesMenu.strings are picked up just fine – the resource folder structure itself does not seem to be the problem).
My guess is the issue is that inside an Automator workflow, as opposed to an application bundle, the context of localized string is Automator (or Automator Runner, as it may be), not the bundle proper, and thus localization lookup fails. I have tried adding a Bundle identifier (CFBundleIdentifier) to the service and referring to that via Automator’s own localized string in bundle with identifier <identifier> construct, but that seems to be restricted to action bundles registered with Automator.
Is there a workaround for this issue allowing me to use AppleScript’s native localization mechanism inside a self contained AppleScript service?
The localized string command doesn’t seem to have the right context in an Automator service, but you can use any bundle that has the resources in the usual places. If you know where the bundle is (your service workflow, a containing application, etc), you can specify that path in the command, e.g.
EDIT: the following is an example of what works for me:
I created a new service workflow that receives text in any application, consisting of a Run AppleScript action:
I named the workflow “localize test”, and saved it in the default ~/Library/Services folder (this is the path is in the myPath property). Next, a Localizable.strings file (UTF-16 created with BBEdit) was placed in the service bundle in the /Contents/Resources/English.lproj folder that contains the following:
An additional test using an AppleScript script bundle on my Desktop with the same resources added also worked OK, so it looks like anything will do as long as you use a path to a valid bundle directory structure.