How to localize dialogs in ASS?

Hi all,

I’ve been trying to localize the dialogs in my app, but nothing seems to work. Here’s what I did:

  • Created a “Localizable.strings” in 2 languages in my project, directly from Xcode.

  • Did something like : “Message1” = “Please, Give the file name”; in english
    “Message1” = “Veuillez, donner le nom du fichier”; in french

  • in my script, looks like this:

set  messageOne to  localized string "Message1" from table "Localizable"
display dialog messageOne 

When I try the app, the dialog says “Message1” instead of the string …

Am I missing something ? Do I need to add a key to my Info.Plist file or something ?

Nevermind, problem fixed: my localizable.strings file wasnt UTF-16, it works now

Well it works so-so : I was planning on returning variables in my dialogs, like the text entered by the user.

But when I add that to my localizable.strings file, it doesnt work anymore and the dialogs display the way i described in my first message … does anyone know a way to do that ?

Here’s what I’d like to do

-- English 
"done" = "You're done! 
All occurrences of \"" & textEntered & "\" were replaced in " & numberOfFiles & " files successfully...";
-- French
"done" = "C'est fini! 
Tous les \"" & textEntered & "\" ont bien été remplacés dans " & numberOfFiles & " fichiers...";


localized strings are strings, as the name implies, it’s not possible to use Apple Script or other variables.
You must do it this way

** localizable.strings **

-- English "DONE" = "You're done!"; "OCC" = "All occurrences of "; "REPLACED" = " were replaced in "; "SUCCESS" = " files successfully...";
** AppleScript Code **

display dialog (localized string "DONE") & return & (localized string "OCC") & quote & textEntered & quote & (localized string "REPLACED") & numberOfFiles & (localized string "SUCCESS")

Note: to determine the literal strings from the localized tokens, I use always uppercase strings for the tokens

I never thought of putting it like that … thanks a lot :slight_smile:

Or you could do something like this:

-- A simple demo of how to use LocalizedString
set myApp to name of current application
set foo to LocalizedString("%@ is running at %@ local time.  I like the %@ forums", {myApp, current date, "MacScripter"})
-- The result is something like:
-- Script Debugger 4.5 is running at Thursday, March 5, 2009 6:59:40 AM local time.  I like the MacScripter forums

on LocalizedString(theString, theVars)
	my atid("%@")
	set theList to (every text item of theString) as list
	-- error if # vars doesn't match # %@'s
	if (count theVars) + 1 is not equal to (count theList) then error ("Incorrect number of arguments for string replacement")
	set newList to {}
	repeat with i from 1 to count theVars
		copy item i of theList to end of newList
		copy item i of theVars to end of newList
	end repeat
	copy last item of theList to end of newList
	my atid("")
	return (every text item of newList) as string
end LocalizedString

on atid(the_delim)
	set AppleScript's text item delimiters to the_delim
end atid

The function doesn’t handle all substitution cases (only %@, no %d, %f, etc) but it’s a much cleaner way to handle the strings coming in from a Localizable strings file.