JS applications i18n and AMD (require.js)

883 views Asked by At

Context: single page web applications written in JavaScript and AMD modules (like require.js)

What is the better way to implement i18n with AMD modules?

Lets say:

translation.js returns some i18n function

require([..modules files., 'translation.js' ], function(.modules.. , t ){
   here in the code/view templates I use t('give_me_text') function
})

Is such approach ok?

1

There are 1 answers

1
jamuhl On BEST ANSWER

it's ok but if your doing a singlepage app you might consider using a template engine and use some helper there to translate the templates during parsing.

you might have a look at http://i18next.com i18n for javascript (has amd version) and the template section