Last Updated: February 25, 2016
· kazlan

Using i18next with Meteor

Just spent some time trying to figure out how to work i18n into a Meteor project and thought it was worth a share.

there's already a i18next module in atmosphere, so just

mrt add i18next-meteor

and the lib will be included.

check http://i18next.com/ to see how to write your json files and store them in
ex. /public/locales/en/translation.json

make sure you add the 'data-i18n="ns.key"' tag to the elements to be i18nized. Next we'll initialize the stuff (i'm using coffescript notation):

Meteor.startup -> 
  i18n.init {lng: 'es', load: 'unespecific', preload: 'en'},(t)->

then add the events to swap your locale. In my case I used two links (#i18n-es and #i18n-en):

  'click #i18n-en': (e)->
    i18n.setLng 'en', ->

  'click #i18n-es': (e) ->
    i18n.setLng 'es', ->

all set and done. Happy coding!

2 Responses
Add your response


Can you show us a sample template that is i18n enabled?

over 1 year ago ·

Check the tap:i18n package, the comprehensive internationalization solution for Meteor, which uses i18next as its internationalization engine.


over 1 year ago ·