diff --git a/node_modules/i18n-2/i18n.js b/node_modules/i18n-2/i18n.js index dda2fab..38574f4 100644 --- a/node_modules/i18n-2/i18n.js +++ b/node_modules/i18n-2/i18n.js @@ -15,6 +15,7 @@ var vsprintf = require("sprintf-js").vsprintf, debugWarn = require('debug')('i18n-2:warn'), debugError = require('debug')('i18n-2:err'); +var translates = {}; function dotNotation (obj, is, value) { if (obj.hasOwnProperty(is)) { @@ -54,16 +55,21 @@ var i18n = module.exports = function (opt) { }); } - // implicitly read all locales - // if it's an array of locale names, read in the data - if (opt.locales && opt.locales.forEach) { - this.locales = {}; + if (translates && Object.keys(translates).length !== 0) { + this.locales = translates; + this.defaultLocale = opt.defaultLocale || opt.locales[0]; + } else { + // implicitly read all locales + // if it's an array of locale names, read in the data + if (opt.locales && opt.locales.forEach) { + this.locales = {}; - opt.locales.forEach(function (locale) { - self.readFile(locale); - }); + opt.locales.forEach(function (locale) { + self.readFile(locale); + }); - this.defaultLocale = opt.defaultLocale || opt.locales[0]; + this.defaultLocale = opt.defaultLocale || opt.locales[0]; + } } // Set the locale to the default locale @@ -456,6 +462,15 @@ i18n.prototype = { return path.normalize(this.directory + '/' + locale + this.extension); }, + appendLocale: function (locale, data) { + this.locales[locale] = {...this.locales[locale], ...data}; + translates[locale] = this.locales[locale]; + }, + + getLocales: function () { + return this.locales + }, + initLocale: function (locale, data) { if (!this.locales[locale]) { this.locales[locale] = data;