Overriding System Language

Can anyone tell me if it is possible to dynamically set the language in an OSX Application?
I use dynamic strings, but want to give the user the option to override the language used .
When I use the build settings I can get the system language used by the App,
but I want to be able to override that language with a popup menu.


an application in OS X use the current OS X language. If no local language is available, the en may be used.

For OS X running in French, the folder name is: fr.lproj (located in Contents:Resources:)
en.lproj name is for the English language.

That is how the OS works talking to languages.

Now, is it possible to do what you want ?

No way to override it and not do any work BUT there is something handy you CAN do with dynamic constants.
When you get the value of a dynamic constant you CAN supply a language code to get a specific localized version.

Try this
Create a new desktop project
Add a dynamic string constant to Window1 called “some string” with 3 localized values for English French & German.

	Constant, Name = somestring, Type = String, Dynamic = True, Default = "abc", Scope = Protected
		 Instance, Platform = Any, Language = en, Definition  = "english"
		 Instance, Platform = Any, Language = fr, Definition  = "french"
		 Instance, Platform = Any, Language = de, Definition  = "german"

Add a label to the window - label1 - and set the initial value it shows to #somestring
Now add a popup menu with the following code in its open event

Sub Open()
me.AddRow “English”
me.RowTag(me.ListCount-1) = “en”

	  me.AddRow "French"
	  me.RowTag(me.ListCount-1) = "fr"
	  me.AddRow "German"
	  me.RowTag(me.ListCount-1) = "de"
	End Sub[/code]

NOW here’s the important bit

In the change event of the popup menu put

		  Label1.Text = somestring(me.rowtag(me.listindex))

Since each row tag has a language code this will ask for the value of the dynamic constant in a specific language.

I’ve posted the sample on my web site

@Norman Palardy : Thanks for the quick response and sample. Much appreciated.

The biggest hassle with doing this is that there’s no way to set up UI controls in the IDE so they look up the value using whatever mechanism you decide to use for changing & storing the “currently selected language”

So you have to put a bit of code in each control to do that :frowning:

I had no idea you could do that with dynamic constants and I don’t see that it was ever documented. Adding it to the docs now!

[quote=42833:@Norman Palardy]…

		  Label1.Text = somestring(me.rowtag(me.listindex))

Since each row tag has a language code this will ask for the value of the dynamic constant in a specific language.
I’ve posted the sample on my web site[/quote]
Wow, nice! Didn’t know that. Thanks a lot!

Our secretaries work on one iMac which is set to English. But one lady wishes to see French in the seminar software (on the English desktop) and others prefer German, still on the English OSX. Now I can do something for them - great!

On OS X, the user’s preferred languages are stored in the AppleLanguages user default (Technical Q&A QA1391 has additional details). When asking for a localized string, the system goes down this list until it finds a localization. For example, here’s my current AppleLanguages value:

[joe@AirLappy.local ~] defaults read -g AppleLanguages ( en, fr, de, ...

This user default is set in the global domain, applying to all the user’s programs, by System Preferences. The nice thing about the user defaults system is that the application domain overrides the global domain, so you can specify the languages for a specific program. To make Safari use French, I would just do this:

[joe@AirLappy.local ~] defaults write com.apple.Safari AppleLanguages -array fr, en

Going down this route means that you don’t have to update every place you use a dynamic constant – at the expense of being an OS X only solution.

Hello Norman,

Im facing the same problem, i do need to make a multi language app and i tried to see your sample but it seems that i get an 404 , si if you can put it again or give an updated solution it will be great. I need to be able to choose the language from the main screen and then the whole app has to use that language. I did saw lingua and constants but im still discovering the options.

Thanks in advance.

The link should work now