localization strings

Hi,
I wrote a simple string-table (extension: string) in text wrangler to translate english months in german months like in the current case. I don’t want to put these translations inside any app, but want these more as help for some applescript apps i wrote. Unfortunately, it doesn’t work outside an app. What is missing ?

Put the lines below into ‘Textwrangler’ and name it months.strings

[center]“January” = “Jänner”;
“February” = “Februar”;
“March” = “März”;
“April” = “April”;
“May” = “Mai”;
“June” = “Juni”;
“July” = “Juli”;
“August” = “August”;
“September” = “September”;
“October” = “Oktober”;
“November” = “November”;
“December” = “Dezember”;[/center]

run the lines below to get results from :

set cu_dt to current date
set pt to ((path to scripts folder from user domain as text) & "German.lproj:months.strings" as text)
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
set d to localized string of getmth in bundle file pt

Another question:
is return equal to exit repeat ?

Hi,

as far as I know the parameter bundle expects a reference to a real Cocoa bundle.
So save a script as application bundle and put your localized strings in there

No.
Return will continue script execution one level up; when in a handler it will go to the caller. When in main script it will go to AppleScript itself, which effectively terminates the script.
Exit repeat will continue execution with the first statement after end repeat.

I’m sure Matt Neuburg has lots more to say about this :wink:

About your strings file: I’d suggest not naming it “months”, as that is a reserved word in AppleScript.

No need for a new resource file.
iPhoto is delivered with every Mac so you may use :


set cu_dt to current date
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
tell application "iPhoto" to set d to localized string "CalInfo" & getmth

When I run it on my French system on 2012/06/14, it returns “Octobre”

If you want to get the abbreviated monthname, use :


set cu_dt to current date
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
tell application "iPhoto" to set d to localized string "CalInfo" & getmth&"Abbr"

When I run it on my French system on 2012/06/14, it returns “Oct”

Yvan KOENIG (VALLAURIS, France) jeudi 14 juin 2012 11:57:49

This works in Snow Leopard:

set cu_dt to current date
set pt to ((path to scripts folder as text) & "German.lproj:")
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
set d to localized string getmth from table "months" in bundle file pt

NB:
No ‘of’ before ‘getmth’ in the last line.
‘from table’ + the “.strings” file name without “.strings”.

Presumably “Jänner” is “Januar” in the Tyrolean dialect?

Jänner is officially used in whole Austria and also in South Tyrol (which is actually Italy)

Interessant. Vielen Dank!

Playing around with this I see that it seems to depend on the primary language set in Preferences. I normally have ‘British English’ set as my primary language although the Region is specified as ‘Germany’ in Formats, so it just returned ‘October’ when I ran the script. To get ‘Oktober’ I had to move ‘Deutsch’ to the first position in Languages.

Is there any way of specifying the language to be used directly when localizing? I have seen things like language code and script code in the AppleScript dictionary but haven’t understood how you can use them.

I had hoped or imagined that there might be something like

set myLang to current language
set current language to Deutsch

to allow you to dynamically determine what language is used (where Deutsch would be defined in an enumeration of the available languages).

Of course it does. This is the intended behavior of localization

If my script above works as well in Lion as it does in Snow Leopard, then the following could be used to read month names from iPhoto’s German resources. It has the advantage that it doesn’t require iPhoto actually to be open:

set cu_dt to current date
tell application "Finder" to set pt to ((application file id "com.apple.iPhoto") as alias as text) & "Contents:Resources:German.lproj:"
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
set d to localized string ("CalInfo" & getmth) from table "Localizable" in bundle file pt

Hello

I was assuming that the original asker was using his system in Deutch and wanted to get the localized month names in scripts.

If you want to get the localized string in a language which is not the used one, you may use this other script :


set cu_dt to current date
set getmth to (month of ((cu_dt) + 16 * weeks) as text)
my getLocalizedMonth("CalInfo" & getmth, "German")


on getLocalizedMonth(theKey, theLoc)
	(*
Languages available :
ca
cs
da
Dutch
el
English
fi
French
German
hr
hu
Italian
Japanese
ko
no
pl
pt_PT
pt
ro
ru
sk
Spanish
sv
th
tr
uk
zh_CN
zh_TW
*)
	set thePlist to ((path to applications folder) as text) & "iPhoto.app:Contents:Resources:" & theLoc & ".lproj:Localizable.strings"
	
	tell application "System Events"
		if exists file thePlist then
			tell contents of property list file thePlist
				try
					value of property list item theKey (* Unicode Text *)
				on error
					theKey & " is not localized"
				end try
			end tell -- to contents of.
		else
			theKey & " is not localized"
		end if
	end tell -- to system events
	return result
end getLocalizedMonth

Yvan KOENIG (VALLAURIS, France) vendredi 15 juin 2012 12:19:21

But consider Nigel, South Tyrol is like the one, very well known little Gallian village under occupation by Rome
:smiley:
-i hoped to get string tables like you did. Thank you for the input!

Hi Yvan,
thanks for your contribution, it is interesting. My intent was to use a minimalistic approach, like i do most of the time-calling applications only if i really need them.
a similar command is:

set app_pt to path to application "x" 

which calls the specified app to get the path in return and it is annoyingly.
i prefer to do the same with:

set nm_app to "x"
set res to paragraph 1 of (do shell script "mdfind -onlyin /Applications/ -name '" & nm_app & "'")

By the way, iPhoto isn’t always on every Os, like by me, but its not relevant. Sorry if i diverge from my initial post, lets return back.

For now, i’m happy with Nigel’s answer, and i’ll try to get later something more. Only yesterday I downloaded the sqlite3 bins. :slight_smile:

Thanks to Nigel and Yvan for the solutions. It does look, though, as you need quite an understanding of iPhoto and its resources to dream them up - more than I have :frowning: