mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-23 06:07:07 +00:00
Merge pull request #3527 from OverloadUT/locale.ignore.system.files
Translation loader now ignores non-directories
This commit is contained in:
commit
b2ef756443
1 changed files with 7 additions and 4 deletions
11
src/i18n.js
11
src/i18n.js
|
|
@ -5,19 +5,22 @@ var fs = require('fs'),
|
|||
shared = require('habitrpg-shared'),
|
||||
translations = {};
|
||||
|
||||
var localePath = path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")
|
||||
|
||||
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] = {};
|
||||
_.each(files, function(file){
|
||||
_.merge(translations[locale], require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, file)));
|
||||
if(path.extname(file) !== '.json') return;
|
||||
_.merge(translations[locale], require(path.join(localePath, locale, file)));
|
||||
});
|
||||
};
|
||||
|
||||
// First fetch english so we can merge with missing strings in other languages
|
||||
loadTranslations('en');
|
||||
|
||||
fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")).forEach(function(file) {
|
||||
if(file === 'en' || file === 'README.md') return;
|
||||
fs.readdirSync(localePath).forEach(function(file) {
|
||||
if(file === 'en' || fs.statSync(path.join(localePath, file)).isDirectory() === false) return;
|
||||
loadTranslations(file);
|
||||
// Merge missing strings from english
|
||||
_.defaults(translations[file], translations.en);
|
||||
|
|
|
|||
Loading…
Reference in a new issue