mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-04 09:39:23 +00:00
minimal translations
This commit is contained in:
parent
687ed0978a
commit
cb36881edd
1 changed files with 21 additions and 2 deletions
|
|
@ -82,7 +82,25 @@ var getManifestFiles = function(page){
|
|||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Translations
|
||||
|
||||
var translations = {};
|
||||
|
||||
fs.readdirSync(path.join(__dirname, "/../locales")).forEach(function(file) {
|
||||
translations[file] = require(path.join(__dirname, "/../locales/", file, 'app.json'))
|
||||
});
|
||||
|
||||
var getTranslatedString = function(locale, string){
|
||||
if(!locale || !string) throw new Error("Missing locale and/or string argument.");
|
||||
if(!translations[locale]) throw new Error("Missing locale '" + locale + "'");
|
||||
|
||||
// TODO support nested dot-separated strings
|
||||
if(translations[locale][string]) return translations[locale][string];
|
||||
if(translations['en'][string]) return translations['en'][string];
|
||||
return 'String not found!';
|
||||
}
|
||||
|
||||
module.exports.locals = function(req, res, next) {
|
||||
res.locals.habitrpg = res.locals.habitrpg || {}
|
||||
|
|
@ -93,7 +111,8 @@ module.exports.locals = function(req, res, next) {
|
|||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
|
||||
getManifestFiles: getManifestFiles,
|
||||
getBuildUrl: getBuildUrl
|
||||
getBuildUrl: getBuildUrl,
|
||||
getTranslatedString: getTranslatedString
|
||||
});
|
||||
next()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue