mcms node localization module
npm install mcms-node-localizationmcms-node-localization
======================
localization module for mcms-node
/lang
/en
messages.json
/es
messages.json
`
Every file in those folders will be parsed and assigned to an object like so : messages.myTranslationVariable
The first part is always the filename and the second your variable.
Usage
check the examples folder for usage scenarios
Initialize like so :
`
var Lang = require('mcms-node-localization');
var locales = ['en','de']; //assuming you have 2 languages
var t = new Lang({
directory : __dirname + '/locales',
locales : locales
});
`
then add the translations
`
t.add();
`
$3
`
console.log(t.get('messages.weekend',{name : 'Michael',surname : 'Bobos'}));
`
$3
`
console.log(t.get('messages.tree','bob','john'));
`
$3
`
console.log(t.choice('messages.cat',2,{name : 'Michael',surname : 'bobos'}));//using named parameters
console.log(t.choice('messages.cat',1,'is enough'));//using arguments
`
$3
`
t.add({
directory : __dirname + '/additionalLocales',
locales : locales
},function(err,translations){
console.log(t.get('msg.Hello',{name : 'Michael',surname : 'bobos'}));
});
`
API
$3
where options :
`
{
directory : __dirname + '/additionalLocales',
locales : locales
}
`
$3
Where optionalArgument could be an object with named parameters or actual parameters. We are making use of sprintf so
if you go for the parameters option make sure they are of the right type.
$3
Count is a number that will output the singular or plural option of the translation variable.
Where optionalArgument could be an object with named parameters or actual parameters. We are making use of sprintf so
if you go for the parameters option make sure they are of the right type.
$3
Inject an object to an existing translation. You can either inject the full blown object like so :
`
var newTranslation = {
en : {
focus : 'Daniel san EN'
},
de : {
focus : 'Daniel san DE'
}
};
t.inject('tester',newTranslation);
`
or just a single variable like so :
`
var newTranslation2 = {
en : 'bob EN',
de : 'bob DE'
};
t.inject('tester.name',newTranslation2);
``