Update html10n.js

pull/1297/head
Marcel Klehr 2012-12-16 18:46:49 +01:00
parent 53521c8732
commit edacb3e2ca
1 changed files with 9 additions and 2 deletions

View File

@ -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)
})