'en'; // Or use req.headers['Accept-Language'] // Or use the user's account settings. // Or use multiple strategies. req.messages = require(path.resolve(__dirname, 'locales', lang + '.json')) next(); });
http://localhost:8080/bag?items=1 <!doctype html> <p>There is 1 item in your bag</p> http://localhost:8080/bag?items=2&lang=es <!doctype html> <p>Hay 2 itemas en su bolso</p>
• Japanese sentences involving imported words can be very long • German words get very long and finding good wrapping gets tricky • Arabic and 8 other currently used scripts start on the right and go left.
English is spoken in the UK. But we spell colour differently and we write our dates inside out in the US. Same language, different specifics. You can call the language with the local details a "locale".
from an external source, you may have more or less to the language tag than you expect. Use the bcp47 module to parse them. Use bcp47-serialize to get them as a string again. Canonicalize into a locale you support early on.
whenever possible -- it’s far easier to get right. "en-US" // Better {lang: 'en', region: 'US'} // You will make mistakes Especially once you add i-navajo and zh-CN-hanz.