var o = {lang: l[0], flag: l[1], url: url, langName: l[3], countryName: l[4]};
- $this.multilang[$this.multilang.length] = o;
+ // $this.multilang[$this.multilang.length] = o;
+ $this.multilang[l[0]] = o; // Indexed by language code to allow easier lookups later
});
},
getActiveFlag: function () {
}
}
},
+
+ getCurrentLanguageName: function () {
+ return this.getLanguageName(this.getActiveLang());
+ },
+
+ // Format the language name according to the settings
+ getLanguageName: function (languageCode) {
+
+ var details = this.multilang[languageCode],
+ name = '';
+
+ if (details === undefined) {
+ return name;
+ }
+
+ switch(this.fluidbook.datas.multilangDisplay) {
+ case 'lang':
+ name = details.langName;
+ break;
+ case 'lang_country':
+ name = details.langName + ' (' + details.countryName + ')';
+ break;
+ case 'country_lang':
+ name = details.countryName + ' (' + details.langName + ')';
+ break;
+ }
+
+ return name;
+ },
+
updateTranslations: function () {
var $this = this;
$("#q").attr('placeholder', this.__('search'));
view += '<div class="content">';
view += '<ul class="chapters localesList">';
var $this = this;
- $.each(this.fluidbook.l10n.multilang, function (k, v) {
+
+ Object.keys(this.fluidbook.l10n.multilang).forEach(function (langCode) {
+ var v = this.fluidbook.l10n.multilang[langCode];
var url = v.url;
if (url.substr(0, 3) == '../' && !$this.fluidbook.datas.standalone) {
url = '../' + url;
__('Langue') . ' (' . __('Pays') . ')' => 'lang_country',
__('Pays') . ' (' . __('Langue') . ')' => 'country_lang'));*/
- var name = '';
- if ($this.fluidbook.datas.multilangDisplay == 'lang') {
- name = v.langName;
- } else if ($this.fluidbook.datas.multilangDisplay == 'lang_country') {
- name = v.langName + ' (' + v.countryName + ')';
- } else if ($this.fluidbook.datas.multilangDisplay == 'country_lang') {
- name = v.countryName + ' (' + v.langName + ')';
- }
+ var name = $this.fluidbook.l10n.getLanguageName(langCode);
var c = '';
if ($this.fluidbook.datas.phonegap) {
}
}
- // Only the Menu should have titles
- if (navType == 'menu') {
+ // Only the Menu should have titles + the locales icon in the horizontal menu
+ if (navType == 'menu' || id == 'locales') {
if (title != undefined && title != '') {
- res += ' ' + this.fluidbook.l10n.__(title);
+ res += ' <span class="menu-item-title">' + this.fluidbook.l10n.__(title) + '</span>';
}
}
}
- var all = "index,chapters,search,friend,print,bookmark,archives,basket,fullscreen,sound,3d,help".split(",");
- var hide = array_diff(all, this.fluidbook.datas.navOrder);
- var loop = [].concat(this.fluidbook.datas.navOrder).concat(hide);
+ // All possible icons and default ordering
+ var all = "index,chapters,search,friend,print,bookmark,archives,basket,fullscreen,sound,3d,help,lang".split(",");
+ // var hide = array_diff(all, this.fluidbook.datas.navOrder); // Array of icons that aren't in the navOrder list and should be hidden
+ // var loop = [].concat(this.fluidbook.datas.navOrder).concat(hide);
+ var loop = this.fluidbook.datas.navOrder;
+ var localeIconIndex;
+
+ // If the locales icon is included, it should always be placed last in the list for formatting reasons
+ if ((localeIconIndex = loop.indexOf('lang')) !== -1) {
+ loop.push(loop.splice(localeIconIndex, 1)[0]); // Push to end of array
+ }
for (var e in loop) {
var icon = loop[e];
- var visible = hide.indexOf(icon) == -1;
+ //var visible = hide.indexOf(icon) == -1;
var link;
if (icon == 'home' && !skipHome) {
link = this.addLink(navType, 'interface-print', '#', 'print', 'print', 'print');
} else if (icon == 'lang' && this.fluidbook.l10n.multilangEnabled) {
- link = this.addMultilangLink(navType);
+ // Note: the "!" at the beginning of the title/help parameters means that we don't want these strings translated
+ link = this.addLink(navType, 'interface-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
} else if (icon == 'archives') {
if (this.fluidbook.datas.archivesLink != '') {
}
- if (!visible) {
- $(link).addClass('hidden');
- }
+ // if (!visible) {
+ // $(link).addClass('hidden');
+ // }
}
},
- addMultilangLink: function (navType) {
- var $nav = this.getNavFromType(navType),
- id = 'locales',
- elementID = navType + '_' + id;
-
- if ($nav.find('#' + elementID).length > 0) {
- return;
- }
-
- var label = this.fluidbook.l10n.__('Select language');
- var url = '#/locales';
- var flagHolder = '<span class="locale-flag"></span>';
- var link;
- if (navType == 'horizontalNav') {
- link = '<a id="'+ elementID +'" data-tooltip="' + label + '" href="'+ url +'">'+ flagHolder +'</a>';
- } else {
- link = '<a id="'+ elementID +'" href="'+ url +'">'+ flagHolder +' '+ label +'</a>';
- }
-
- var flag = this.fluidbook.l10n.getActiveFlag();
- if (flag === false) {
- return;
- }
-
- // Add to menu and set flag
- $nav.find('ul').append('<li>' + link + '</li>');
- $nav.find(".locale-flag").css('background-image', 'url("images/flags/' + flag + '.png")');
-
- return link;
- },
-
getMenuCloseButton: function () {
var $this = this,
buttonID = 'menuClose';
},
setInterface: function () {
+ // Ensure we don't add interface elements more than once
+ if (this._inited['interface'] == true) {
+ return;
+ }
+ this._inited['interface'] = true;
+
var res = this.getLink('interface-previous', '#', 'previous', '', '', '', false);
res += this.getLink('interface-next', '#', 'next', '', '', '', false);
$('#interface').append(res);