We are about to start building our web app in Node.js and I would like to be ready for i18n so I'm looking for your experience with building Node.js apps where the text is translatable.
Preferably I'd like to use a tool like Pootle via Git or other if you have any recommendations.
There are a number of i18n modules you can use in your application, but you can create your own if you want.
For example create a folder /languages and inside it create en.js, fr.js etc
it.js
module.exports = {
"name": "nome",
"age": "eta",
.. etc
}
The important thing is to set a default language and make a language select bar somewhere in your site. When the user chooses another language (and not English) in your app you do something like this:
app.get('/lang/:ln', function (req, res, next) {
// remember the user's chosen language
req.session.language = req.params.ln;
});
Then you can have a language helper function like so:
translate = function (language, text) {
// language array contains all the languages
return language_array[language].text;
}
// example: translate(req.session.language, "age")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With