Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(function(req, res, next) {
if (req.user && req.user.language) {
// Change moment language
moment.lang(req.user.language);
try {
// Change numeral language
numeral.language(req.user.language, require("../node_modules/numeral/languages/" + req.user.language + ".js"));
numeral.language(req.user.language);
} catch (error) {
// Just silently ignore this error...
}
}
// Set data to response locals, so those are accessible by any view
res.locals.currentUser = req.user;
res.locals.moment = moment;
res.locals.numeral = numeral;
res.locals.packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
res.locals.inspect = require("util").inspect;
next();
});
}
setLang(lang = "en", msgs = {}) {
let newmsgs = {};
if (typeof langs[lang] !== 'undefined') {
newmsgs = $.extend(true, this.messages, langs[lang]);
}
if (!_.isEmpty(msgs)) {
newmsgs = $.extend(true, newmsgs, msgs);
}
this.settings.language = lang;
try {
numeral.language(lang);
} catch (err) {
console.warn('unable to set numeral language to '+lang);
}
this.messages = newmsgs;
}
}
if (override) {
try {
var localenumeral = require('numeral');
//if for some reason our locale is English
if (localemap.numeral[override] === 'en') {
//set numeral's language
localenumeral.language('en');
return localenumeral;
} else {
//load the language
localenumeral.language(localemap.numeral[override], require('numeral/languages/' + localemap.numeral[override] + '.js'));
//set the language
localenumeral.language(localemap.numeral[override]);
return localenumeral;
}
} catch (error) {
cout("fn: lib , fn: numeral" + error.toString().replace("Error: ", " ")).error();
}
}
}
};
function loadNumeral(locale) {
if (locale === 'en') {
numeral.language('en');
} else {
numeral.language(locale, require(NUMERALPATH + locale));
numeral.language(locale);
}
debug(numeral.language(), 'fn: loadNumeral, Current numeral language');
debug(numeral(10000).format('$0,0.00'), 'fn: loadNumeral, Current numeral: I don\'t have');
}
function loadNumeral(locale) {
if (locale === 'en') {
numeral.language('en');
} else {
numeral.language(locale, require(NUMERALPATH + locale));
numeral.language(locale);
}
debug(numeral.language(), 'fn: loadNumeral, Current numeral language');
debug(numeral(10000).format('$0,0.00'), 'fn: loadNumeral, Current numeral: I don\'t have');
}
function loadNumeral(locale) {
if (locale === 'en') {
numeral.language('en');
} else {
numeral.language(locale, require(NUMERALPATH + locale));
numeral.language(locale);
}
debug(numeral.language(), 'fn: loadNumeral, Current numeral language');
debug(numeral(10000).format('$0,0.00'), 'fn: loadNumeral, Current numeral: I don\'t have');
}
import numeral from 'numeral';
const obj = require('numeral/languages/nl-nl');
numeral.language('nl-nl', obj);
numeral.language('nl-nl');
export default numeral;
'en': {
moment: 'en',
numeral: 'en',
},
};
const resources = {
dev: { translation: require('./locales/dev.json') },
de: { translation: require('./locales/de.json') },
};
numeral.language('de', require('numeral/languages/de'));
const I18N = extend(null, /** @lends I18N# */ {
language: null,
languageData: null,
timezone: null,
/**
* Creates a new I18N instance for the given language code.
*
* @constructs
* @param {string} [language='en'] Language code (ISO 639-1)