Localizing a Gadget

Gadgets containing text can be localized. Localizing a gadget means adapting its text to the language used in the final application. This property allows you to create multilingual applications whose current language can be changed dynamically very easily.

Views lets you create message databases as files where you can store all the text that will be displayed in your final application with its translation to as many languages as you want. The message database file have a .dbm extension. See “IlvMessageDatabase” in the chapter “Internationalization” of the Views Foundation User’s Manual.

To have the text of a gadget change dynamically depending on the language used in the final application, you must provide a reference to the message database where the text is stored instead of hard-coding it.

Let’s suppose that you have created the following message database:

Message: &MenuPrinterSetup

en_US: Printer Setup

fr_Fr: Configuration imprimante

You can assign a gadget label the string defined by &MenuPrinterSetup like this:

gadget->setLabel("&MenuPrinterSetup");

Calling the getLabel member function will return the string &MenuPrinterSetup and invoking the getMessage member function will provide the translation to the current language (for example, “Printer Setup” for English and “Configuration imprimante” for French).