// example localization initialization
var loc = require('loc')({
// it gets the locale from the following strategies in this order.
// if the locale is not part of the `path`it looks it up in the `query` ect.
getLocaleFrom: ['path', 'query', 'subdomain', 'cookie'],
// if the locale was found in one of the strategies above, it stores it with this strategy.
// in this case in the `cookie`
storeLocaleTo: ['cookie'],
// the locale definitions (translations) are retrieved from `file`.
storage: 'file',
// the following locales are supported (optional).
// If this option is omitted, it accetps what ever is defined in the definitions.
locales: ['de', 'de-ch', 'en', 'en-GB', 'en-us'],
// locale definition director
directory: "./locales",
// locale definition file extension
extension: ".json",
// Exclude List for the path rewrite middleware used for the path strategy.
// problematic are static assets and url's that start with one to three letters in the path like:
// /p/, /js/ or /img/ and should therefore be excluded.
excludeList: [".css", ".js", '.ico', '/api/', '/img/', '/css/', '/js/']
});
// adds all middlewares as bundle
//loc.bind(app);
//or add them separately
// adds the loc middleware. adds the req.i18n object.
app.use(loc.loc());
// adds the locPathRewrite middleware used for the `path` strategy.
// it redirects the request to the url without the locale in the path. e.g. `/en-GB/about` to `/about`
app.use(loc.pathRewrite());
// adds the urlTranslation middleware
app.use(loc.urlTranslation());
// print out localeCache for debugging purposes
loc.writeLocaleCache();

{
"Hello": "Hello",
"Hello %s, how are you today?": "Hello %s, how are you today?",
"weekend": "weekend",
"Hello %s, how are you today? How was your %s.": "Hello %s, how are you today? How was your %s.",
"Hi": "Hi",
"Howdy": "Howdy",
"%s cat": {
"one": "%s cat",
"other": "%s cats"
},
"There is one monkey in the %%s": {
"one": "There is one monkey in the %%s",
"other": "There are %d monkeys in the %%s"
},
"tree": "tree"
}

that file can be edited or just uploaded to webtranslateit for any kind of collaborative translation workflow.

this gives you 1 cat and 3 cats. As with __(...) these could be nested:

var singular = i18n.__n('There is one monkey in the %%s', 'There are %d monkeys in the %%s', 1, 'tree');
var plural = i18n.__n('There is one monkey in the %%s', 'There are %d monkeys in the %%s', 3, 'tree');

putting There is one monkey in the tree or There are 3 monkeys in the tree.

Sets a locale to the specified string. If the locale is unknown, the locale defaults to the one specified by defaultLocale. For example if you have locales of 'en' and 'de', and a defaultLocale of 'en', then call .setLocale('ja') it will be equivalent to calling .setLocale('en').