this.multilang = [];
this.multilangEnabled = false;
this.fluidbook = fluidbook;
-
- this.load(lang);
+ this.init(lang);
this.initMultilang();
+ this.load();
}
FluidbookL10N.prototype = {
- load: function (lang) {
- if (lang == undefined || lang == null || lang == '') {
+ init: function (lang) {
+ if (lang === undefined || lang === null || lang === '') {
lang = 'default';
}
this.lang = lang;
+ },
+ load: function () {
this.dir = this.getLanguageDirection(this.getActiveLang());
this.ltr = (this.dir == 'ltr');
this.rtl = !this.ltr;
$("html").removeClass('rtl').addClass('ltr');
}
- if (lang == 'default') {
+ if (this.lang === 'default') {
this.translations = this.fluidbook.datas.l10n[this.fluidbook.datas.defaultLang];
- $.extend(this.translations, this.fluidbook.datas.l10n[lang]);
+ $.extend(this.translations, this.fluidbook.datas.l10n[this.lang]);
} else {
- this.translations = this.fluidbook.datas.l10n[lang];
+ this.translations = this.fluidbook.datas.l10n[this.lang];
}
this.updateTranslations();
},
getActiveLang: function () {
- if (this.lang != 'default') {
- return this.lang;
+ var res = this.lang;
+ if (this.lang === 'default') {
+ res = this.fluidbook.datas.defaultLang;
}
- return this.fluidbook.datas.defaultLang;
+
+ // Append country when lang is present more than one time in the list
+ if (this._langsCount[res] > 1) {
+ res += '_' + this.fluidbook.datas.country;
+ }
+ return res;
},
initMultilang: function () {
var forceLocales;
var ml = this.fluidbook.datas.multilang.replace(/\r/g, "\n").replace(/\n+/g, "\n");
var e = ml.split("\n");
+ this._langsCount = {};
+ var versions = [];
$.each(e, function (k, v) {
if (v == '') {
return;
var o = {lang: l[0], flag: l[1], url: url, langName: l[3], countryName: l[4]};
- // $this.multilang[$this.multilang.length] = o;
- var languageID = l[0] + '_' + l[1];
- $this.multilang[languageID] = o; // Indexed by language code + flag to allow easier lookups later and allow multiple variations of the same language
- });
- },
- getActiveFlag: function () {
- var active = this.getActiveLang();
- var res = [];
- for (var i = 0; i < this.multilang.length; i++) {
- var l = this.multilang[i];
- if (l.lang == active) {
- res.push(l);
+ if ($this._langsCount[o.lang] === undefined) {
+ $this._langsCount[o.lang] = 0;
}
- }
+ $this._langsCount[o.lang]++;
+ versions.push(o);
+ });
- if (res.length == 1) {
- return res[0].flag;
- } else if (res.length == 0) {
- return false;
- } else {
- if (this.fluidbook.datas.country != '') {
- for (var i in res) {
- if (res[i].flag == this.fluidbook.datas.country) {
- return res[i].flag;
- }
- }
- return res[0].flag;
+
+ $.each(versions, function (k, version) {
+ // $this.multilang[$this.multilang.length] = o;
+ var languageId = version.lang;
+ if ($this._langsCount[version.lang] > 1) {
+ languageId += '_' + version.flag;
}
- }
+ version.id = languageId;
+ $this.multilang[languageId] = version; // Indexed by language code + flag to allow easier lookups later and allow multiple variations of the same language
+ });
+
},
getCurrentLanguageName: function () {
// Determine if a language is LTR or RTL based on its code
getLanguageDirection: function (languageCode) {
+ var e = languageCode.split('_');
+ languageCode = e[0];
+
// Arabic and Hebrew are the only RTL languages defined for now.
// ToDo: update this with a full list of RTL languages
return (languageCode == 'ar' || languageCode == 'he') ? 'rtl' : 'ltr'
if (str.substr(0, 1) == '!') {
return str.substr(1);
}
-
+
if (this.translations[str] == undefined || this.translations[str] == null || this.translations[str] == '') {
if (markupIfNonAvailable == undefined || !markupIfNonAvailable) {
return str;
}
} else if (icon == 'lang' && this.fluidbook.l10n.multilangEnabled) {
// Note: the "!" at the beginning of the title/help parameters means that we don't want these strings translated
- //link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
- // Todo: remove this temporary link and re-instate original link above when ticket #2173 is done so we can display proper language name
- link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!Select Language', '!Select Language'); // Label says "Select Language" until we can have the country code recorded for the Fluidbook
+ link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
} else if (icon == 'archives') {
if (this.fluidbook.datas.archivesLink != '') {
link = this.addLink(navType, 'nav-archives', this.fluidbook.datas.archivesLink, 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);