From edacb3e2ca7a5b1307ac572cb6af3d418286b047 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 16 Dec 2012 18:46:49 +0100 Subject: [PATCH] Update html10n.js --- src/static/js/html10n.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/static/js/html10n.js b/src/static/js/html10n.js index c36dcc9f7..a38f76d78 100644 --- a/src/static/js/html10n.js +++ b/src/static/js/html10n.js @@ -597,12 +597,14 @@ window.html10n = (function(window, document, undefined) { * @param langs An array of lang codes defining fallbacks */ html10n.localize = function(langs) { + var that = this // if only one string => create an array if ('string' == typeof langs) langs = [langs] this.build(langs, function(er, translations) { html10n.translations = translations html10n.translateElement(translations) + that.trigger('localized') }) } @@ -780,7 +782,8 @@ window.html10n = (function(window, document, undefined) { * @param langs Array - a list of langs sorted by priority (default langs should go last) */ html10n.build = function(langs, cb) { - var build = {} + var that = this + , build = {} asyncForEach(langs, function (lang, i, next) { html10n.loader.load(lang, next) @@ -790,9 +793,13 @@ window.html10n = (function(window, document, undefined) { for (var i=0, n=langs.length; i < n; i++) { // apply all strings of the current lang in the list // to our build object - for (var string in this.loader.langs[lang]) { + for (var string in this.loader.langs[i]) { build[string] = this.loader.langs[lang][string] } + + // the last applied lang will be exposed as the + // lang the page was translated to + that.language = langs[i] } cb(null, build) })