diff options
author | Caio Carrara <ccarrara@thoughtworks.com> | 2016-06-24 17:15:54 -0300 |
---|---|---|
committer | Caio Carrara <ccarrara@thoughtworks.com> | 2016-06-27 16:39:55 -0300 |
commit | 361796f0ff1eb0f450f768749d5c69f5c4f6b1e4 (patch) | |
tree | 01e1729ce21feccba9c08fd6e7d8452397d5521a /web-ui/app/js/views | |
parent | 6042a2b1b93d2f2a89c418971d7e12b5a79b3314 (diff) |
Updates the i18next to latest version
See: #727
Diffstat (limited to 'web-ui/app/js/views')
-rw-r--r-- | web-ui/app/js/views/i18n.js | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/web-ui/app/js/views/i18n.js b/web-ui/app/js/views/i18n.js index 6a39ee89..f843b845 100644 --- a/web-ui/app/js/views/i18n.js +++ b/web-ui/app/js/views/i18n.js @@ -14,15 +14,49 @@ * You should have received a copy of the GNU Affero General Public License * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. */ -define(['i18next'], function(i18n) { +define(['i18next', + 'i18nextXHRBackend', + 'i18nextBrowserLanguageDetector'], +function(i18n, i18n_backend, I18n_detector) { 'use strict'; - var self = i18n.t; + var detector = new I18n_detector(); + var detect = detector.detect.bind(detector); - self.init = function(path) { - i18n.init({detectLngQS: 'lang', fallbackLng: 'en_US', lowerCaseLng: true, getAsync: false, resGetPath: path + 'locales/__lng__/__ns__.json'}); - Handlebars.registerHelper('t', self.bind(self)); + detector.detect = function(detectionOrder) { + var result = detect(detectionOrder); + return result.replace('-', '_'); }; - return self; + function t(i18n_key) { + var result = i18n.t(i18n_key); + var safe_string = new Handlebars.SafeString(result); + return safe_string.string; + } + + function loaded(callback) { + i18n.on('loaded', function(loaded) { + callback(); + }); + } + + function init(path) { + i18n + .use(i18n_backend) + .use(detector) + .init({ + fallbackLng: 'en_US', + backend: { + loadPath: path + 'locales/{{lng}}/{{ns}}.json' + } + }); + // Handlebars.registerHelper('t', self.bind(self)); + Handlebars.registerHelper('t', t); + } + + return { + t: t, + init: init, + loaded: loaded + }; }); |