Built-in variables: language

The variable language stores in a multi-lingual, localized application the name of the currently selected language member. Please note, the variable is declared with the homonymous language data type.

Declaration

language language

Discussion

In your project you can define several language members for all language variants your application should be localized for. Then at the runtime, you select the desired language by simply assigning the name of the corresponding language member to the built-in variable language. Assuming, in your project you have defined language members called French, German and Default, then the following operation would switch to the language French:

language = French;

The modification of the language variable affects only the subsequent accesses to multi-lingual constants and bitmap resources. It has no effect on already evaluated expressions. In other words: the once obtained bitmap resource will not change its content when you afterwards switch the language. Assuming, your project contains a multi-lingual string constant Dialogs::YesCaption, then the both string variables text1 and text2 at the end of the following example will contain different language dependent values:

language = German;
var string text1 = Dialogs::YesCaption;

language = French;
var string text2 = Dialogs::YesCaption;

trace text1, text2; // "JA", "OUI"

You can also evaluate the variable language within expressions wherever an operand of data type language is allowed. For example, you can store the variable locally or use it in conditions. The following code demonstrates it on the example of how to toggle between the languages German and French:

var language tmp = language;

if ( tmp == German )
  tmp = French;

else if ( tmp == French )
  tmp = German;

language = tmp;

Please note, Chora provides powerful automatisms to allow existing objects to update themselves in response to the modification of the language variable. First, when changing the language, Chora automatically calls the ReInit() re-constructors of every currently existing object allowing the objects to explicitly handle the language alternation. You can implement these re-constructors accordingly to your needs.

Furthermore, if a GUI component is configured with the attribute MultiLingual = true, the Chora compiler generates additional code to automatically re-initialize all data members existing within the component. Changing the language causes thus their multi-lingual initialization expressions to be evaluated again for all currently existing instances of the affected GUI component.

In most cases it is thus not necessary to implement additional code to handle the language alternation. The above described automatism takes care of the appropriate update operations after your user has selected another language for the GUI.