Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multilanguage express app

Tags:

I wonder what would be the best way to implement multiple versions / languages of the same content in the same layout in express.

Should I just do this?

app.get("/", function(req, res) {     res.render(language + "/index"); }); 

Or is there a smarter / better way?

like image 764
buschtoens Avatar asked Jun 02 '12 23:06

buschtoens


People also ask

How do I get multilanguage app?

Multilanguage support is easy done for android. Create a new values directory for the language with the suffix of the language code. For german: values-de or french: values-fr than copy your string. xml into that and translate each entry.

What is a multilanguage application?

Mobile apps that target an international audience through multilingual apps not only drive conversion rates but create a long-lasting relationship with the end-users. Multilingual apps are likable and shareable that helps improve brand visibility twofold. The more users, the more successful the app will be.


2 Answers

I would suggest to keep only one template, as if you use one template per language it will get out of hand very quickly, let alone duplicate much content (and the small amount of "logic" you would put in a template too). Many applications use a tool called gettext to do the internationalization thing. There is a node.js library for it at https://github.com/DanielBaulig/node-gettext

Alternatively there is also i18n-node. It appears to have a bit more integration with express js.

like image 154
ziad-saab Avatar answered Oct 06 '22 01:10

ziad-saab


The i18n-node is the simplest and greatest module that you should use. You can use directly in Javascript code or with Jade/Handlebar templates with express js.

Why should you use i18n?

  • Auto detection of locale from the browser by header, cookie or query parameter depending on your setup.
  • It comes with examples as well.
  • It automatically generates a en.json by default inside ./locales/. This acts as a master file for you to start building new translations.
  • Supports Singular and plural forms
  • Support for parameters: __('Hello %s', 'Marcus') returns Hallo Marcus
like image 42
ankitjaininfo Avatar answered Oct 06 '22 00:10

ankitjaininfo