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