3.17 Internationalization

RapaGUI easily allows you to add internationalization (i18n) support to your applications because it seamlessly integrates with Hollywood's catalog system. Thus, all you have to do to support multiple languages in your application is create a catalog containing all language-dependent texts used by your program and open it at startup, for example using the @CATALOG preprocessor command, e.g.

 
@CATALOG "MyApp.catalog"

You can then address individual catalog entries by using either the MOAI.I18N attribute or the @i18n: directive. All attributes that accept a string argument also accept the MOAI.I18N attribute which allows you to specify a catalog string index that should be used if a catalog for the user's system language is available. The string index can either be an absolute numeric value or a Hollywood constant. For example, to create a multi-lingual button you could do the following:

 
<button i18n="0">Click me</button>

With such XML code, the text "Click me" will only be used if the user's system language is English or RapaGUI can't find a catalog for the current system language. Otherwise, RapaGUI will use the string at index 0 in the catalog file instead of the default text "Click me".

For for locale-dependent strings that are passed in tag attributes you have to use the @i18n: directive. Just append this suffix to the string, followed by a numeric value or a Hollywood constant and Hollywood will use the specified catalog string instead if there's a catalog for the user's system language available. For example:

 
<window title="My application@i18n:1">...</window>

In that example, RapaGUI will use the window title "My application" only if the user's system language is English or if RapaGUI can't find a catalog for the current system language. Otherwise, RapaGUI will use the string at index 1 in the catalog file instead of the title "My application".

As already pointed out, you can also use Hollywood constants instead of hard-coded numeric values. Using Hollywood constants might be more convenient to maintain your XML because it allows you to easily add and remove entries. Using Hollywood constants, the XML from above looks like this:

 
<button i18n="#CAT_BUTTON">Click me</button>
<window title="My application@i18n:#CAT_TITLE">...</window>

Note that all these internationalization features only apply to the XML. All changes that are made at runtime need to be handled manually, so you need to use Hollywood's GetCatalogString() function to obtain the correct catalog string when making locale-dependent changes to the GUI at runtime, e.g. by calling functions like moai.Set().


Show TOC