Meteor Internationalization with tap:i18n

In this post I want to share a simple way to internationalize Meteor applications with tap:i18n.

First at all, include tap:i18n package :

meteor add tap:i18n

Now, create a new directory to keep your language files and tap:i18n configuration.

This is the i18n.js file content:

[code language=”javascript”]

Meteor.startup(function () {

Session.set(“showLoadingIndicator”, true);

var userLanguage = window.navigator.userLanguage   window.navigator.language;

var language = ‘en-US’;

if(userLanguage.toLowerCase()==”pt-br”){

language = ‘pt-BR’;

}

TAPi18n.setLanguage(language)

.done(function () {

Session.set(“showLoadingIndicator”, false);

})

.fail(function (error_message) {

console.log(error_message);

});

});

[/code]

 

An important thing is about this lines is that window.navigator.userLanguage return a lowercase string like ‘en-us’ but tap:i18n expects this format ‘en-US’, so it’s necessary to do this validation. Example

The next step are the messages files, tap:i18n expects JSon format files

[code language=”javascript”]

{

“key”: “value”

}

[/code]

Examples:

en-US.i18n.json

pt-BR.i18n.json

Finally the usage is pretty simple.

With Spacebars :  

[code language=”html”]

[/code]

With JS : TAPi18n.__(“key”)

[code language=”javascript”]

throw new Meteor.Error(‘insufficient-privileges’,TAPi18n.__(“insufficientPrivileges”));

[/code]

Allan de Queiroz

Allan de Queiroz
London based software engineer

XServer forward from Linux text mode for Headless purposes.

Hello, this post is about XServer forward from Linux text mode, **not ssh forward, anything related to VNC** or things like that.Recently...… Continue reading