« Back to the index

Internationalization of texts and messages

The I18n library allow to manage standarized messages in any needed language.
The system is simple: One unique id, many languages for the same id. The system takes the right message for the right language.


Let's translate our messages to french:
function test1() { // At the beginning of our application, we can setup some messages WA.i18n.setEntry('message1', 'Enter the application'); WA.i18n.setEntry('message2', 'Exit the application'); // Somewhere int the application, we overload the french entries. // There may be more messages than the already defined. var fr = { 'message1': 'Entrer dans le programme', 'message2': 'Sortir du programme', 'message3': 'Se d├ęplacer dans le programme' } // The order is not important. If we call loadMessage, they WILL always be the main ones to use WA.i18n.loadMessages(fr); // Maybe later in the application we define new messages. Even if we define them in english, they will be returned as french if they were loaded by loadMessages WA.i18n.setEntry('message3', 'Move in the application'); WA.i18n.setEntry('message4', 'Fatal error in the application'); // In some point of our application, we use the language entries WA.get('#test1').text('Message1 in a button: <b>' + WA.i18n.getMessage('message1') + '</b>\n'); WA.get('#test1').append('Message2 in another button: <b>' + WA.i18n.getMessage('message2') + '</b>\n'); WA.get('#test1').append('Message3 in a help: <b>' + WA.i18n.getMessage('message3') + '</b>\n'); // Note the message4 has not been loaded in our french language so it takes the default english entry WA.get('#test1').append('Note that message4 was not loaded by the "french array" so the english entry will be used:\n'); WA.get('#test1').append('Message4 in an alert: <b>' + WA.i18n.getMessage('message4') + '</b>\n'); // Note the message5 has not been loaded at all so it takes the id itself WA.get('#test1').append('Note that message5 was not created by either french array or english entries, so the ID will be used:\n'); WA.get('#test1').append('Message5 in a box: <b>' + WA.i18n.getMessage('message5') + '</b>\n'); }
Show the result

« Back to the index