How to Dynamically Change Your Display Language
You can dynamically change your display language. You simply need to call setCurrentLanguage on the display. Views will reload automatically all the data files that you currently have loaded and display the new language. In order to do this, you have to provide the localized versions of these files and they must be available on your system.
Let's say you have created an application where all the messages are defined in a file named my_messages.dbm.
If display is your display, just load this file at the beginning of your application through a call to:
display->getDatabase()->read("my_messages.dbm", display);
If you have started your program in a French locale, Views will load the file located in locale/fr_FR.ISO-8859-1/my_messages.dbm.
Now, to change your display language, just call setCurrentLanguage with the new language you want. For example, if you want your display to be in Italian, call:
display->setCurrentLanguage(IlGetSymbol("it_IT"));
Views will automatically load the file located in:
locale/it_IT.ISO-8859-1/my_messages.dbm
It will also load all the other data files that are already open.
To go back to French, call setCurrentLanguage again as follows:
display->setCurrentLanguage(IlGetSymbol("fr_FR"));
Note
This can only be done if the encodings are compatible. |
The sample that you can find in samples/foundation/i18n/changelang is an illustration of this feature.