Localization

I have just finished “localizing” an application. The part that involves using dynamic constants is fine. But because these cannot be used for all things, I needed to create a solution for window titles, MsgBox messages, etc. using if-then-else statements. These respond to a preferences property within the application that I created. Thus to make that application completely functional in the other language (Spanish), two things need to happen: 1) change the system’s Language setting to Spanish AND 2) select Spanish in the preferences window within the application. Without #2 MsgBox messages, window titles, SaveAsDialog prompts remain in English while field prompts, button captions, etc. are in Spanish.

My question has to do with learning if there is a way within Xojo to detect the system’s Language setting so I can use that automatically within the application. This is to avoid directing the user to set the preference so the application will work completely in Spanish. I’m sure this is possible, but I just can’t figure out how to do it. Any help on this? Thank you.

Create a computed property, mCurrentLanguage, and set values in it for the languages you support
Then just check that value

Why you can’t use dynamic constants for window titles?
You can set using #costantName
For the other cases most of then can be setted via constant
ie: msgbox myMsgboxCostant

if you have to write parameters: define your constant with placeholders and replace them with the “live” value that you need
ie:
constant myPrompt eng ->Pick the folder where you want to save “@datafile_name@”
constant myPromy esp ->Elija la carpeta donde desea guardar “@datafile_name@” //Forgive me I don’t know spanish
mySaveDialog.PromptText= myPrompt.ReplaceAll("@datafile_name@",theFolderItem.name)

Oh and for most things I would not use MsgBox except as a way to show debug messages

I had no difficilty localizing everything using dynamic constants, including window titles, prompts and such. Why do you think you need anything else for this?

Thank you all for your replies. What I am hoping to learn is how to automatically detect the Language setting being used by the computer’s OS. I tried to find it in the Windows registry with no luck. There are some things that I can’t (or don’t know how to) do with dynamic constants. An example is that I need to read in a different RTF file for my system help depending on the language. So far I can only do this with an if-then-else statement in the window.open event. This works fine, but it depends on the user going to preferences and setting the language, while the dynamic constants are set automatically by “reading” the OS. Maybe this is where my understanding is lacking.

As I said before all of the constants I have created for window labels and such are working fine. But which language is used for each constant is determined by the system (Windows) setting in the Region/Language area. Norman suggested a property to store the selected language. I have done that. But the problem is that I have to set it manually in a preferences window. I would like that information to be “read” from the OS automatically.

I do appreciate all your help. I did some work with VisualBasic years ago, but have since worked mostly with FileMaker Pro. So it is taking me a while getting up to speed with Xojo. But I am really enjoying the experience. Again thanks to you all.

Actually I suggested a computed property that you read so you can tell what language your program is running in :stuck_out_tongue:

Create one called “CurrentLanguage”
Put in one value for each language you support
Say you support English Dutch & Russian
Then you would put in three entries
Any platform Language = English value = English
Any platform Language = Ducth value = Dutch
Any platform Language = Russian value = Russian
Now when you run your program you READ CurrentLanguage & voile it will tell you which of those supported languages is in use

I would go with Norman’s suggestion, it’s possible to actually ask the computer what language their OS is in, but if stay within the Xojo framework (by using Dynamic Constants) it’ll save you a lot of hassle with the different OSes.

Antionio’s response is a great way for encapsulating replaceable data (such as filenames) within the constants too.

If you haven’t done so already, look at replacing MsgBox with the MessageDialog, this will enable you to localize the button captions too. You could even wrap the code into a single function so you can call it as simply as MsgBox.

The biggest issue I ran into when trying to localize, was spacing of controls. Often the interface looks great in English (coz hey I designed it in English) and then realize that I didn’t give all these controls enough spacing for other languages.

Another good addition (?) is to add in the Preferences a Language entry, so your user will be able to change the application display language.
You can put the language list in a PopupMenu and save that in your Preferences application. Then at application launch time, when you read the preferences, you set the CurrentLanguage to that value (Norman suggestion).

Just a 0.000001¢

[quote=49956:@Sam Rowlands]
The biggest issue I ran into when trying to localize, was spacing of controls. Often the interface looks great in English (coz hey I designed it in English) and then realize that I didn’t give all these controls enough spacing for other languages.[/quote]
Hence why we’re working on a way to deal with that :stuck_out_tongue:

[quote=49967:@Emile Schwarz]Another good addition (?) is to add in the Preferences a Language entry, so your user will be able to change the application display language.
You can put the language list in a PopupMenu and save that in your Preferences application. Then at application launch time, when you read the preferences, you set the CurrentLanguage to that value (Norman suggestion).
[/quote]
Thats not actually what I suggested
What I did suggest won’t make it so the computer runs in one language & your application runs in a different one UNLESS your application does NOT support the primary language the computer is running in
It’s just a way for you to know what language your app is running in using the built in dynamic constant system

Do you mean “dynamic constant”? I’m not sure how a computed property helps here.

yes :stuck_out_tongue:

I am feeling kinda dumb now because I am still stuck on this. Again, you have all been great and provided some great ideas. I absolutely understand everything that has been suggested. I already had created an app property for language. But the problem that I STILL have is that the property does not control the constants.

In the window where we define constants we click the small (+) button that gives us a new line to set Platform, Language, and Value. I click the language and choose the desired language (in this case Spanish). From what I understand that “connects” my constant to configure itself based on the language that is set in the OS under the Regional settings. So if my PC is set to English, the constants display in English, etc.

My dilemma continues to be how do I do one of two things:

  1. “Read” the OS language setting from within Xojo so my language property will set itself accordingly, or
  2. Make that Language dropdown list synchronize with my language property.

To state it another way–yes, I can set dynamic constants all day long–but they “obey” the language set in the OS and NOT my language property. I am trying to do what Sam Rowlands suggested–"…stay within the Xojo framework (by using dynamic constants)" But how do I make those dynamic constants “connect to” or “read” my language property and NOT the OS?

I feel like I am tiring you all out with this. But as you can see we still have not connected with regard to what my problem/question is. Take care.

You don’t. Dynamic constants are tied to the OS settings. I’d recommend presenting your list of things you haven’t been able to get working and let the folks here try to help. According to Michael, it should all work.

[quote=50086:@Randall Sandberg] I already had created an app property for language. But the problem that I STILL have is that the property does not control the constants.
[/quote]
Don’t - you want a DYNAMIC CONSTANT called CurrentLanguage that the Runtime will already manage for you
Then you can simply READ the value from this & it will tell you what language your application IS running in

Say you support 3 language - English French & Spanish
So you crate a dynamic constant on the App class called CurrentLanguage
Set the 3 values in it to
ANY PLATFORM, English, value = English
ANY PLATFORM, French, value = French
ANY PLATFORM, Spanish, value = Spanish

On OS X Say your user has their language list set to
German
Dutch
Russian
English
and so on

WHen they run you application and you read the value of CurrentLanguage it will say …. English because that is the FIRST LOCALIZATION that is in their preferred language list that has a match in your application
And every other place you have set values for dynamic constants like this will pick the English version

You literally don’t have to do anything

There are few places you can’t do anything about are Msgbox - which I would not use in a shipping app.
But virtually everything else should just work if you set up dynamic constants for the strings you want to show.
Thats all we do in the IDE and the only time we have mixed up languages are when / if we miss localizing one.

You have all been great, and I thank you very much. I think Tim Hare gave me the definitive answer I was looking for–that there is no way to “read” the OS language setting. This has caused me to abandon the idea of localizing my app. I get the part about dynamic constants perfectly, and what I have implemented works fine. But as I have said before, my hope was to “read” the OS language setting and use it to set a SystemLanguage property I created. This would have allowed me to set msg parameters for MsgBox (or even MessageDialog) locally using if-then-else statements. The same was true for HelpTags, which I had also hoped to make dynamic, but at this “local” level such as in the Open event for windows, etc.

And yes, I see that I can do it all with the dynamic constants. But that task becomes frankly overwhelming if I must create dynamic constants to set HelpTags, MessageDialog msg parameters, etc. Last night I read in BKenney Briefs that their clients from Latin America all request to have their software created in English anyway. So it is probably not worth all the effort. I have considered the possibility that it would probably be easier to create a Spanish language version of the app than it would be to create (and keep track) of so many dynamic constants. Truthfully I’m just too lazy, and all the fretting over the localization stuff was distracting and causing me to lose focus on the main function of the app.

It has been a learning experience, which was actually a good part of what I hoped for. Maybe someday Xojo will have a way to detect the OS language setting. In the meantime I thank you all again for your ideas and suggestions. I hope everyone has a wonderful holiday season.

Randall,
Xojo should have a section in their manual about localization. Have you read that?

Also, I think you’re doing more than what’s necessary: You seem to be trying to let your own code handle the localization, i.e. switch the language as needed, from your code. That’s overkill. All OSs (Windows, OS X, even Linux) have nowadays an automatic mechanism that does this for you: The user chooses which language he prefers, and then the OS chooses the right language from your app automatically. All you have to do for this is to include all languages, via dynamic constants, and Xojo + the OS do the rest for you.

I also recommend reading my article on this topic, which also includes instructions for how to turn all your controls, window titles etc. automagically into dynamic constants with my program Arbed (that feature is not free, though):

http://www.tempel.org/RB/Localization

No built in way - correct

[quote=50163:@Randall Sandberg]This has caused me to abandon the idea of localizing my app. I get the part about dynamic constants perfectly, and what I have implemented works fine. But as I have said before, my hope was to “read” the OS language setting and use it to set a SystemLanguage property I created. This would have allowed me to set msg parameters for MsgBox (or even MessageDialog) locally using if-then-else statements. The same was true for HelpTags, which I had also hoped to make dynamic, but at this “local” level such as in the Open event for windows, etc.
[/quote]
If you use dynamic constants for all this you don’t require ANY if then statements - you don’t have to write ANY code to “do localization” UNLESS you want to do something the OS does not support (like on OS X providing a way to change the language your app runs in when it’s running)

[quote=50163:@Randall Sandberg]
It has been a learning experience, which was actually a good part of what I hoped for. Maybe someday Xojo will have a way to detect the OS language setting. [/quote]
There’s no point in Xojo making it so you can read the OS language since there’s nothing you can do with it beyond “Oh hey look the app is running in spanish”. You can’t switch it at run time to make your app run in english when the preferred language is spanish - at least not nearly as simply as just using dynamic constants.

Its one reason why the IDE doesn’t have a way to switch the language at run time

I whipped up a small sample of how to use dynamic constants to do this if you’re interested - I’m not sure we include any in the examples

The Eddie’s Electronics examples in the Sample App folder are both localized using dynamic constants for a variety of languages.