mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-27 09:09:42 +00:00
Locale loader now ignores non-directories
Locales must be stored in directories and the code previously crashed if there were any unexpected files in the locale folder. Now the code simply ignores all non-directories.
This commit is contained in:
parent
49772bb571
commit
84e1223809
1 changed files with 6 additions and 4 deletions
10
src/i18n.js
10
src/i18n.js
|
|
@ -5,19 +5,21 @@ var fs = require('fs'),
|
||||||
shared = require('habitrpg-shared'),
|
shared = require('habitrpg-shared'),
|
||||||
translations = {};
|
translations = {};
|
||||||
|
|
||||||
|
var localePath = path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")
|
||||||
|
|
||||||
var loadTranslations = function(locale){
|
var loadTranslations = function(locale){
|
||||||
var files = fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale));
|
var files = fs.readdirSync(path.join(localePath, locale));
|
||||||
translations[locale] = {};
|
translations[locale] = {};
|
||||||
_.each(files, function(file){
|
_.each(files, function(file){
|
||||||
_.merge(translations[locale], require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, file)));
|
_.merge(translations[locale], require(path.join(localePath, locale, file)));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// First fetch english so we can merge with missing strings in other languages
|
// First fetch english so we can merge with missing strings in other languages
|
||||||
loadTranslations('en');
|
loadTranslations('en');
|
||||||
|
|
||||||
fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")).forEach(function(file) {
|
fs.readdirSync(localePath).forEach(function(file) {
|
||||||
if(file === 'en' || file === 'README.md' || file.indexOf('.') === 0) return;
|
if(file === 'en' || fs.statSync(path.join(localePath, file)).isDirectory() === false) return;
|
||||||
loadTranslations(file);
|
loadTranslations(file);
|
||||||
// Merge missing strings from english
|
// Merge missing strings from english
|
||||||
_.defaults(translations[file], translations.en);
|
_.defaults(translations[file], translations.en);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue