summaryrefslogtreecommitdiff
path: root/src/static/js/html10n.js
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2012-12-19 16:29:38 +0100
committerMarcel Klehr <mklehr@gmx.net>2012-12-23 18:16:41 +0100
commit64b176f4defe24456603030457709818c6ad61c6 (patch)
treefceb4a8d7a6698c99085a27c9bc4e64d580856e2 /src/static/js/html10n.js
parent67c893aacaca26d835505c911ec465e35cf88d0d (diff)
downloadetherpad-lite-64b176f4defe24456603030457709818c6ad61c6.zip
Fix html10n (finally)
Diffstat (limited to 'src/static/js/html10n.js')
-rw-r--r--src/static/js/html10n.js42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/static/js/html10n.js b/src/static/js/html10n.js
index 3c2e2072..8029b8d6 100644
--- a/src/static/js/html10n.js
+++ b/src/static/js/html10n.js
@@ -79,10 +79,10 @@ window.html10n = (function(window, document, undefined) {
for (var i=0, n=this.resources.length; i < n; i++) {
this.fetch(this.resources[i], lang, function(e) {
reqs++;
- if(e) setTimeout(function(){ throw e }, 0)
+ if(e) return setTimeout(function(){ throw e }, 0)
if (reqs < n) return;// Call back once all reqs are completed
- cb()
+ cb && cb()
})
}
}
@@ -108,7 +108,7 @@ window.html10n = (function(window, document, undefined) {
var data = JSON.parse(xhr.responseText)
that.cache[href] = data
// Pass on the contents for parsing
- this.parse(lang, data, cb)
+ that.parse(lang, data, cb)
} else {
cb(new Error('Failed to load '+href))
}
@@ -619,18 +619,18 @@ window.html10n = (function(window, document, undefined) {
var children = element? getTranslatableChildren(element) : document.childNodes;
for (var i=0, n=children.length; i < n; i++) {
- translateNode(translations, children[i])
+ this.translateNode(translations, children[i])
}
// translate element itself if necessary
- translateNode(translations, element)
+ this.translateNode(translations, element)
}
- function asyncForEach(list, iterator, cb) {
+ function asyncForEach(list, iterator, cb) {
var i = 0
, n = list.length
iterator(list[i], i, function each(err) {
- consoleLog(err)
+ if(err) consoleLog(err)
i++
if (i < n) return iterator(list[i],i, each);
cb()
@@ -656,10 +656,10 @@ window.html10n = (function(window, document, undefined) {
if(!translations[id]) return consoleWarn('Could not find string '+id)
// apply args
- str = substArguments(translations[id], args)
+ var str = substArguments(translations[id], args)
// apply macros
- return substMacros(translations, id, str, args)
+ return substMacros(id, str, args)
// replace {{arguments}} with their values or the
// associated translation string (based on its key)
@@ -759,7 +759,7 @@ window.html10n = (function(window, document, undefined) {
if (node.children.length === 0) {
node[prop] = str.str
} else {
- var children = element.childNodes,
+ var children = node.childNodes,
found = false
for (var i=0, n=children.length; i < n; i++) {
if (children[i].nodeType === 3 && /\S/.test(children[i].textContent)) {
@@ -772,7 +772,7 @@ window.html10n = (function(window, document, undefined) {
}
}
if (!found) {
- consoleWarn('Unexpected error: could not translate element content')
+ consoleWarn('Unexpected error: could not translate element content for key '+str.id, node)
}
}
}
@@ -786,20 +786,26 @@ window.html10n = (function(window, document, undefined) {
, build = {}
asyncForEach(langs, function (lang, i, next) {
- html10n.loader.load(lang, next)
+ if(!lang) return next();
+ that.loader.load(lang, next)
}, function() {
-
+ var lang
langs.reverse()
+
+ // loop through priority array...
for (var i=0, n=langs.length; i < n; i++) {
- // apply all strings of the current lang in the list
+ lang = langs[i]
+ if(!lang) continue;
+
+ // ... and apply all strings of the current lang in the list
// to our build object
- for (var string in this.loader.langs[i]) {
- build[string] = this.loader.langs[lang][string]
+ for (var string in that.loader.langs[lang]) {
+ build[string] = that.loader.langs[lang][string]
}
// the last applied lang will be exposed as the
// lang the page was translated to
- that.language = langs[i]
+ that.language = langs[lang]
}
cb(null, build)
})
@@ -840,7 +846,7 @@ window.html10n = (function(window, document, undefined) {
// gettext-like shortcut
if (window._ === undefined)
- var _ = html10n.get;
+ window._ = html10n.get;
return html10n
})(window, document) \ No newline at end of file