mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migration of Globalize to ES6 module
This commit is contained in:
parent
a9246f8f39
commit
76a037b7c2
34 changed files with 92 additions and 89 deletions
|
@ -164,6 +164,7 @@
|
||||||
"src/plugins/backdropScreensaver/plugin.js",
|
"src/plugins/backdropScreensaver/plugin.js",
|
||||||
"src/components/filterdialog/filterdialog.js",
|
"src/components/filterdialog/filterdialog.js",
|
||||||
"src/components/fetchhelper.js",
|
"src/components/fetchhelper.js",
|
||||||
|
"src/scripts/globalize.js",
|
||||||
"src/scripts/keyboardNavigation.js",
|
"src/scripts/keyboardNavigation.js",
|
||||||
"src/scripts/settings/appSettings.js",
|
"src/scripts/settings/appSettings.js",
|
||||||
"src/scripts/settings/userSettings.js",
|
"src/scripts/settings/userSettings.js",
|
||||||
|
|
|
@ -67,7 +67,7 @@ import 'formDialogStyle';
|
||||||
});
|
});
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
let html = '';
|
let html = '';
|
||||||
html += globalize.translateDocument(template);
|
html += globalize.translateHtml(template);
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
populateHours(dlg);
|
populateHours(dlg);
|
||||||
loadSchedule(dlg, options.schedule);
|
loadSchedule(dlg, options.schedule);
|
||||||
|
|
|
@ -465,7 +465,7 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro
|
||||||
|
|
||||||
function loadContent(ctx, route, html, request) {
|
function loadContent(ctx, route, html, request) {
|
||||||
|
|
||||||
html = globalize.translateDocument(html, route.dictionary);
|
html = globalize.translateHtml(html, route.dictionary);
|
||||||
request.view = html;
|
request.view = html;
|
||||||
|
|
||||||
viewManager.loadView(request);
|
viewManager.loadView(request);
|
||||||
|
|
|
@ -274,7 +274,7 @@ define(['require', 'browser', 'layoutManager', 'appSettings', 'pluginManager', '
|
||||||
|
|
||||||
function embed(options, self) {
|
function embed(options, self) {
|
||||||
require(['text!./displaySettings.template.html'], function (template) {
|
require(['text!./displaySettings.template.html'], function (template) {
|
||||||
options.element.innerHTML = globalize.translateDocument(template, 'core');
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
||||||
if (options.enableSaveButton) {
|
if (options.enableSaveButton) {
|
||||||
options.element.querySelector('.btnSave').classList.remove('hide');
|
options.element.querySelector('.btnSave').classList.remove('hide');
|
||||||
|
|
|
@ -412,7 +412,7 @@ import 'css!./style.css';
|
||||||
dlg.classList.add('background-theme-a');
|
dlg.classList.add('background-theme-a');
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
dlg.classList.add('filterDialog');
|
dlg.classList.add('filterDialog');
|
||||||
dlg.innerHTML = globalize.translateDocument(template);
|
dlg.innerHTML = globalize.translateHtml(template);
|
||||||
setVisibility(dlg, this.options);
|
setVisibility(dlg, this.options);
|
||||||
dialogHelper.open(dlg);
|
dialogHelper.open(dlg);
|
||||||
dlg.addEventListener('close', resolve);
|
dlg.addEventListener('close', resolve);
|
||||||
|
|
|
@ -286,7 +286,7 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'apphost',
|
||||||
|
|
||||||
html += template;
|
html += template;
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(html, 'core');
|
dlg.innerHTML = globalize.translateHtml(html, 'core');
|
||||||
|
|
||||||
var settingElements = dlg.querySelectorAll('.viewSetting');
|
var settingElements = dlg.querySelectorAll('.viewSetting');
|
||||||
for (var i = 0, length = settingElements.length; i < length; i++) {
|
for (var i = 0, length = settingElements.length; i < length; i++) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ define(['dialogHelper', 'globalize', 'userSettings', 'layoutManager', 'connectio
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -1151,7 +1151,7 @@ define(['require', 'inputManager', 'browser', 'globalize', 'connectionManager',
|
||||||
|
|
||||||
context.classList.add('tvguide');
|
context.classList.add('tvguide');
|
||||||
|
|
||||||
context.innerHTML = globalize.translateDocument(template, 'core');
|
context.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
programGrid = context.querySelector('.programGrid');
|
programGrid = context.querySelector('.programGrid');
|
||||||
var timeslotHeaders = context.querySelector('.timeslotHeaders');
|
var timeslotHeaders = context.querySelector('.timeslotHeaders');
|
||||||
|
|
|
@ -472,7 +472,7 @@ define(['require', 'apphost', 'layoutManager', 'focusManager', 'globalize', 'loa
|
||||||
template = template.replace('{section' + i + 'label}', globalize.translate('LabelHomeScreenSectionValue', i));
|
template = template.replace('{section' + i + 'label}', globalize.translate('LabelHomeScreenSectionValue', i));
|
||||||
}
|
}
|
||||||
|
|
||||||
options.element.innerHTML = globalize.translateDocument(template, 'core');
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
options.element.querySelector('.viewOrderList').addEventListener('click', onSectionOrderListClick);
|
options.element.querySelector('.viewOrderList').addEventListener('click', onSectionOrderListClick);
|
||||||
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
||||||
|
|
|
@ -339,7 +339,7 @@ define(['dom', 'loading', 'apphost', 'dialogHelper', 'connectionManager', 'image
|
||||||
|
|
||||||
var dlg = dialogHelper.createDialog(dialogOptions);
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(template, 'core');
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
if (layoutManager.tv) {
|
if (layoutManager.tv) {
|
||||||
scrollHelper.centerFocus.on(dlg, false);
|
scrollHelper.centerFocus.on(dlg, false);
|
||||||
|
|
|
@ -92,7 +92,7 @@ define(['globalize', 'dom', 'dialogHelper', 'emby-checkbox', 'emby-select', 'emb
|
||||||
scrollY: false
|
scrollY: false
|
||||||
});
|
});
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
dlg.innerHTML = globalize.translateDocument(template);
|
dlg.innerHTML = globalize.translateHtml(template);
|
||||||
dlg.addEventListener('close', function () {
|
dlg.addEventListener('close', function () {
|
||||||
saveValues(dlg, options);
|
saveValues(dlg, options);
|
||||||
});
|
});
|
||||||
|
|
|
@ -161,7 +161,7 @@ import 'css!./style';
|
||||||
|
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(template, 'core');
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
if (layoutManager.tv) {
|
if (layoutManager.tv) {
|
||||||
scrollHelper.centerFocus.on(dlg, false);
|
scrollHelper.centerFocus.on(dlg, false);
|
||||||
|
|
|
@ -464,7 +464,7 @@ define(['dialogHelper', 'connectionManager', 'loading', 'dom', 'layoutManager',
|
||||||
|
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(template, 'core');
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
if (layoutManager.tv) {
|
if (layoutManager.tv) {
|
||||||
scrollHelper.centerFocus.on(dlg, false);
|
scrollHelper.centerFocus.on(dlg, false);
|
||||||
|
|
|
@ -150,7 +150,7 @@ import 'flexStyles';
|
||||||
const dlg = dialogHelper.createDialog(dialogOptions);
|
const dlg = dialogHelper.createDialog(dialogOptions);
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
let html = '';
|
let html = '';
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
if (layoutManager.tv) {
|
if (layoutManager.tv) {
|
||||||
dlg.querySelector('.formDialogContent');
|
dlg.querySelector('.formDialogContent');
|
||||||
|
|
|
@ -382,7 +382,7 @@ import 'cardStyle';
|
||||||
dlg.classList.add('recordingDialog');
|
dlg.classList.add('recordingDialog');
|
||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ import 'cardStyle';
|
||||||
dlg.classList.add('recordingDialog');
|
dlg.classList.add('recordingDialog');
|
||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -359,7 +359,7 @@ define(['globalize', 'dom', 'emby-checkbox', 'emby-select', 'emby-input'], funct
|
||||||
xhr.open('GET', 'components/libraryoptionseditor/libraryoptionseditor.template.html', true);
|
xhr.open('GET', 'components/libraryoptionseditor/libraryoptionseditor.template.html', true);
|
||||||
xhr.onload = function(e) {
|
xhr.onload = function(e) {
|
||||||
var template = this.response;
|
var template = this.response;
|
||||||
parent.innerHTML = globalize.translateDocument(template);
|
parent.innerHTML = globalize.translateHtml(template);
|
||||||
populateRefreshInterval(parent.querySelector('#selectAutoRefreshInterval'));
|
populateRefreshInterval(parent.querySelector('#selectAutoRefreshInterval'));
|
||||||
var promises = [populateLanguages(parent), populateCountries(parent.querySelector('#selectCountry'))];
|
var promises = [populateLanguages(parent), populateCountries(parent.querySelector('#selectCountry'))];
|
||||||
Promise.all(promises).then(function() {
|
Promise.all(promises).then(function() {
|
||||||
|
|
|
@ -211,7 +211,7 @@ export class showEditor {
|
||||||
dlg.classList.add('background-theme-a');
|
dlg.classList.add('background-theme-a');
|
||||||
dlg.classList.add('dlg-librarycreator');
|
dlg.classList.add('dlg-librarycreator');
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
dlg.innerHTML = globalize.translateDocument(template);
|
dlg.innerHTML = globalize.translateHtml(template);
|
||||||
initEditor(dlg, options.collectionTypeOptions);
|
initEditor(dlg, options.collectionTypeOptions);
|
||||||
dlg.addEventListener('close', onDialogClosed);
|
dlg.addEventListener('close', onDialogClosed);
|
||||||
dialogHelper.open(dlg);
|
dialogHelper.open(dlg);
|
||||||
|
|
|
@ -226,7 +226,7 @@ export class showEditor {
|
||||||
dlg.classList.add('ui-body-a');
|
dlg.classList.add('ui-body-a');
|
||||||
dlg.classList.add('background-theme-a');
|
dlg.classList.add('background-theme-a');
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
dlg.innerHTML = globalize.translateDocument(template);
|
dlg.innerHTML = globalize.translateHtml(template);
|
||||||
dlg.querySelector('.formDialogHeaderTitle').innerHTML = options.library.Name;
|
dlg.querySelector('.formDialogHeaderTitle').innerHTML = options.library.Name;
|
||||||
initEditor(dlg, options);
|
initEditor(dlg, options);
|
||||||
dlg.addEventListener('close', onDialogClosed);
|
dlg.addEventListener('close', onDialogClosed);
|
||||||
|
|
|
@ -1045,7 +1045,7 @@ define(['itemHelper', 'dom', 'layoutManager', 'dialogHelper', 'datetime', 'loadi
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
@ -1085,7 +1085,7 @@ define(['itemHelper', 'dom', 'layoutManager', 'dialogHelper', 'datetime', 'loadi
|
||||||
|
|
||||||
require(['text!./metadataEditor.template.html'], function (template) {
|
require(['text!./metadataEditor.template.html'], function (template) {
|
||||||
|
|
||||||
elem.innerHTML = globalize.translateDocument(template, 'core');
|
elem.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
elem.querySelector('.formDialogFooter').classList.remove('formDialogFooter');
|
elem.querySelector('.formDialogFooter').classList.remove('formDialogFooter');
|
||||||
elem.querySelector('.btnHeaderSave').classList.remove('hide');
|
elem.querySelector('.btnHeaderSave').classList.remove('hide');
|
||||||
|
|
|
@ -31,7 +31,7 @@ define(['dialogHelper', 'layoutManager', 'globalize', 'require', 'paper-icon-but
|
||||||
var html = '';
|
var html = '';
|
||||||
var submitted = false;
|
var submitted = false;
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ define(['require', 'browser', 'appSettings', 'apphost', 'focusManager', 'quality
|
||||||
|
|
||||||
require(['text!./playbackSettings.template.html'], function (template) {
|
require(['text!./playbackSettings.template.html'], function (template) {
|
||||||
|
|
||||||
options.element.innerHTML = globalize.translateDocument(template, 'core');
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ define(['globalize', 'connectionManager', 'serverNotifications', 'require', 'loa
|
||||||
require(['text!./recordingfields.template.html'], function (template) {
|
require(['text!./recordingfields.template.html'], function (template) {
|
||||||
var options = self.options;
|
var options = self.options;
|
||||||
var context = options.parent;
|
var context = options.parent;
|
||||||
context.innerHTML = globalize.translateDocument(template, 'core');
|
context.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
context.querySelector('.singleRecordingButton').addEventListener('click', onRecordChange.bind(self));
|
context.querySelector('.singleRecordingButton').addEventListener('click', onRecordChange.bind(self));
|
||||||
context.querySelector('.seriesRecordingButton').addEventListener('click', onRecordSeriesChange.bind(self));
|
context.querySelector('.seriesRecordingButton').addEventListener('click', onRecordSeriesChange.bind(self));
|
||||||
|
|
|
@ -168,7 +168,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
|
||||||
var dlg = options.context;
|
var dlg = options.context;
|
||||||
|
|
||||||
dlg.classList.add('hide');
|
dlg.classList.add('hide');
|
||||||
dlg.innerHTML = globalize.translateDocument(template, 'core');
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.querySelector('.formDialogHeader').classList.add('hide');
|
dlg.querySelector('.formDialogHeader').classList.add('hide');
|
||||||
dlg.querySelector('.formDialogFooter').classList.add('hide');
|
dlg.querySelector('.formDialogFooter').classList.add('hide');
|
||||||
|
@ -221,7 +221,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
|
||||||
|
|
||||||
var html = '';
|
var html = '';
|
||||||
|
|
||||||
html += globalize.translateDocument(template, 'core');
|
html += globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.innerHTML = html;
|
dlg.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
||||||
|
|
||||||
require(['text!./searchfields.template.html'], function (template) {
|
require(['text!./searchfields.template.html'], function (template) {
|
||||||
|
|
||||||
var html = globalize.translateDocument(template, 'core');
|
var html = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
if (browser.tizen || browser.orsay) {
|
if (browser.tizen || browser.orsay) {
|
||||||
html = html.replace('<input ', '<input readonly ');
|
html = html.replace('<input ', '<input readonly ');
|
||||||
|
|
|
@ -601,7 +601,7 @@ define(['layoutManager', 'globalize', 'require', 'events', 'connectionManager',
|
||||||
template = replaceAll(template, 'itemsContainer scrollSlider', 'itemsContainer scrollSlider vertical-wrap');
|
template = replaceAll(template, 'itemsContainer scrollSlider', 'itemsContainer scrollSlider vertical-wrap');
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = globalize.translateDocument(template, 'core');
|
var html = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
elem.innerHTML = html;
|
elem.innerHTML = html;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'layoutMana
|
||||||
|
|
||||||
html += template;
|
html += template;
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(html, 'core');
|
dlg.innerHTML = globalize.translateHtml(html, 'core');
|
||||||
|
|
||||||
fillSortBy(dlg, options.sortOptions);
|
fillSortBy(dlg, options.sortOptions);
|
||||||
initEditor(dlg, options.settings);
|
initEditor(dlg, options.settings);
|
||||||
|
|
|
@ -448,7 +448,7 @@ define(['dialogHelper', 'require', 'layoutManager', 'globalize', 'userSettings',
|
||||||
dlg.classList.add('formDialog');
|
dlg.classList.add('formDialog');
|
||||||
dlg.classList.add('subtitleEditorDialog');
|
dlg.classList.add('subtitleEditorDialog');
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(template, 'core');
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
dlg.querySelector('.originalSubtitleFileLabel').innerHTML = globalize.translate('File');
|
dlg.querySelector('.originalSubtitleFileLabel').innerHTML = globalize.translate('File');
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ function embed(options, self) {
|
||||||
require(['text!./subtitlesettings.template.html'], function (template) {
|
require(['text!./subtitlesettings.template.html'], function (template) {
|
||||||
|
|
||||||
options.element.classList.add('subtitlesettings');
|
options.element.classList.add('subtitlesettings');
|
||||||
options.element.innerHTML = globalize.translateDocument(template, 'core');
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
||||||
|
|
||||||
options.element.querySelector('form').addEventListener('submit', self.onSubmit.bind(self));
|
options.element.querySelector('form').addEventListener('submit', self.onSubmit.bind(self));
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'conne
|
||||||
|
|
||||||
html += template;
|
html += template;
|
||||||
|
|
||||||
dlg.innerHTML = globalize.translateDocument(html, 'core');
|
dlg.innerHTML = globalize.translateHtml(html, 'core');
|
||||||
|
|
||||||
var settingElements = dlg.querySelectorAll('.viewSetting');
|
var settingElements = dlg.querySelectorAll('.viewSetting');
|
||||||
for (var i = 0, length = settingElements.length; i < length; i++) {
|
for (var i = 0, length = settingElements.length; i < length; i++) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ define(['events', 'loading', 'globalize'], function (events, loading, globalize)
|
||||||
|
|
||||||
function loadTemplate(page, type, providerId) {
|
function loadTemplate(page, type, providerId) {
|
||||||
require(['text!./components/tvproviders/' + type + '.template.html'], function (html) {
|
require(['text!./components/tvproviders/' + type + '.template.html'], function (html) {
|
||||||
page.querySelector('.providerTemplate').innerHTML = globalize.translateDocument(html);
|
page.querySelector('.providerTemplate').innerHTML = globalize.translateHtml(html);
|
||||||
init(page, type, providerId);
|
init(page, type, providerId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
define(['userSettings', 'events'], function (userSettings, events) {
|
import * as userSettings from 'userSettings';
|
||||||
'use strict';
|
import events from 'events';
|
||||||
var fallbackCulture = 'en-us';
|
|
||||||
|
|
||||||
var allTranslations = {};
|
/* eslint-disable indent */
|
||||||
var currentCulture;
|
|
||||||
var currentDateTimeCulture;
|
|
||||||
|
|
||||||
function getCurrentLocale() {
|
const fallbackCulture = 'en-us';
|
||||||
|
|
||||||
|
const allTranslations = {};
|
||||||
|
let currentCulture;
|
||||||
|
let currentDateTimeCulture;
|
||||||
|
|
||||||
|
export function getCurrentLocale() {
|
||||||
return currentCulture;
|
return currentCulture;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentDateTimeLocale() {
|
export function getCurrentDateTimeLocale() {
|
||||||
return currentDateTimeCulture;
|
return currentDateTimeCulture;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultLanguage() {
|
function getDefaultLanguage() {
|
||||||
var culture = document.documentElement.getAttribute('data-culture');
|
const culture = document.documentElement.getAttribute('data-culture');
|
||||||
if (culture) {
|
if (culture) {
|
||||||
return culture;
|
return culture;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +36,8 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
return fallbackCulture;
|
return fallbackCulture;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCurrentCulture() {
|
export function updateCurrentCulture() {
|
||||||
var culture;
|
let culture;
|
||||||
try {
|
try {
|
||||||
culture = userSettings.language();
|
culture = userSettings.language();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -44,7 +47,7 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
|
|
||||||
currentCulture = normalizeLocaleName(culture);
|
currentCulture = normalizeLocaleName(culture);
|
||||||
|
|
||||||
var dateTimeCulture;
|
let dateTimeCulture;
|
||||||
try {
|
try {
|
||||||
dateTimeCulture = userSettings.dateTimeLocale();
|
dateTimeCulture = userSettings.dateTimeLocale();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -60,11 +63,11 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureTranslations(culture) {
|
function ensureTranslations(culture) {
|
||||||
for (var i in allTranslations) {
|
for (let i in allTranslations) {
|
||||||
ensureTranslation(allTranslations[i], culture);
|
ensureTranslation(allTranslations[i], culture);
|
||||||
}
|
}
|
||||||
if (culture !== fallbackCulture) {
|
if (culture !== fallbackCulture) {
|
||||||
for (var i in allTranslations) {
|
for (let i in allTranslations) {
|
||||||
ensureTranslation(allTranslations[i], fallbackCulture);
|
ensureTranslation(allTranslations[i], fallbackCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,14 +88,14 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
culture = culture.replace('_', '-');
|
culture = culture.replace('_', '-');
|
||||||
|
|
||||||
// convert de-DE to de
|
// convert de-DE to de
|
||||||
var parts = culture.split('-');
|
const parts = culture.split('-');
|
||||||
if (parts.length === 2) {
|
if (parts.length === 2) {
|
||||||
if (parts[0].toLowerCase() === parts[1].toLowerCase()) {
|
if (parts[0].toLowerCase() === parts[1].toLowerCase()) {
|
||||||
culture = parts[0].toLowerCase();
|
culture = parts[0].toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lower = culture.toLowerCase();
|
const lower = culture.toLowerCase();
|
||||||
if (lower === 'ca-es') {
|
if (lower === 'ca-es') {
|
||||||
return 'ca';
|
return 'ca';
|
||||||
}
|
}
|
||||||
|
@ -110,7 +113,7 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
module = defaultModule();
|
module = defaultModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
var translations = allTranslations[module];
|
const translations = allTranslations[module];
|
||||||
if (!translations) {
|
if (!translations) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -118,17 +121,17 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
return translations.dictionaries[locale];
|
return translations.dictionaries[locale];
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(options) {
|
export function register(options) {
|
||||||
allTranslations[options.name] = {
|
allTranslations[options.name] = {
|
||||||
translations: options.strings || options.translations,
|
translations: options.strings || options.translations,
|
||||||
dictionaries: {}
|
dictionaries: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadStrings(options) {
|
export function loadStrings(options) {
|
||||||
var locale = getCurrentLocale();
|
const locale = getCurrentLocale();
|
||||||
var promises = [];
|
const promises = [];
|
||||||
var optionsName;
|
let optionsName;
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
optionsName = options;
|
optionsName = options;
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,10 +143,10 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheParam = new Date().getTime();
|
const cacheParam = new Date().getTime();
|
||||||
function loadTranslation(translations, lang) {
|
function loadTranslation(translations, lang) {
|
||||||
lang = normalizeLocaleName(lang);
|
lang = normalizeLocaleName(lang);
|
||||||
var filtered = translations.filter(function (t) {
|
let filtered = translations.filter(function (t) {
|
||||||
return normalizeLocaleName(t.lang) === lang;
|
return normalizeLocaleName(t.lang) === lang;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -159,12 +162,12 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = filtered[0].path;
|
let url = filtered[0].path;
|
||||||
|
|
||||||
url += url.indexOf('?') === -1 ? '?' : '&';
|
url += url.indexOf('?') === -1 ? '?' : '&';
|
||||||
url += 'v=' + cacheParam;
|
url += 'v=' + cacheParam;
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
|
|
||||||
xhr.onload = function (e) {
|
xhr.onload = function (e) {
|
||||||
|
@ -183,8 +186,8 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateKey(key) {
|
function translateKey(key) {
|
||||||
var parts = key.split('#');
|
const parts = key.split('#');
|
||||||
var module;
|
let module;
|
||||||
|
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
module = parts[0];
|
module = parts[0];
|
||||||
|
@ -195,7 +198,7 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateKeyFromModule(key, module) {
|
function translateKeyFromModule(key, module) {
|
||||||
var dictionary = getDictionary(module, getCurrentLocale());
|
let dictionary = getDictionary(module, getCurrentLocale());
|
||||||
if (!dictionary || !dictionary[key]) {
|
if (!dictionary || !dictionary[key]) {
|
||||||
dictionary = getDictionary(module, fallbackCulture);
|
dictionary = getDictionary(module, fallbackCulture);
|
||||||
}
|
}
|
||||||
|
@ -209,15 +212,15 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
return str.split(find).join(replace);
|
return str.split(find).join(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
function translate(key) {
|
export function translate(key) {
|
||||||
var val = translateKey(key);
|
let val = translateKey(key);
|
||||||
for (var i = 1; i < arguments.length; i++) {
|
for (let i = 1; i < arguments.length; i++) {
|
||||||
val = replaceAll(val, '{' + (i - 1) + '}', arguments[i]);
|
val = replaceAll(val, '{' + (i - 1) + '}', arguments[i]);
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateHtml(html, module) {
|
export function translateHtml(html, module) {
|
||||||
if (!module) {
|
if (!module) {
|
||||||
module = defaultModule();
|
module = defaultModule();
|
||||||
}
|
}
|
||||||
|
@ -225,26 +228,26 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
throw new Error('module cannot be null or empty');
|
throw new Error('module cannot be null or empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
var startIndex = html.indexOf('${');
|
let startIndex = html.indexOf('${');
|
||||||
if (startIndex === -1) {
|
if (startIndex === -1) {
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
startIndex += 2;
|
startIndex += 2;
|
||||||
var endIndex = html.indexOf('}', startIndex);
|
const endIndex = html.indexOf('}', startIndex);
|
||||||
if (endIndex === -1) {
|
if (endIndex === -1) {
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = html.substring(startIndex, endIndex);
|
const key = html.substring(startIndex, endIndex);
|
||||||
var val = translateKeyFromModule(key, module);
|
const val = translateKeyFromModule(key, module);
|
||||||
|
|
||||||
html = html.replace('${' + key + '}', val);
|
html = html.replace('${' + key + '}', val);
|
||||||
return translateHtml(html, module);
|
return translateHtml(html, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
var _defaultModule;
|
let _defaultModule;
|
||||||
function defaultModule(val) {
|
export function defaultModule(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
_defaultModule = val;
|
_defaultModule = val;
|
||||||
}
|
}
|
||||||
|
@ -259,16 +262,15 @@ define(['userSettings', 'events'], function (userSettings, events) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
export default {
|
||||||
getString: translate,
|
translate,
|
||||||
translate: translate,
|
translateHtml,
|
||||||
translateDocument: translateHtml,
|
loadStrings,
|
||||||
translateHtml: translateHtml,
|
defaultModule,
|
||||||
loadStrings: loadStrings,
|
getCurrentLocale,
|
||||||
defaultModule: defaultModule,
|
getCurrentDateTimeLocale,
|
||||||
getCurrentLocale: getCurrentLocale,
|
register,
|
||||||
getCurrentDateTimeLocale: getCurrentDateTimeLocale,
|
updateCurrentCulture
|
||||||
register: register,
|
};
|
||||||
updateCurrentCulture: updateCurrentCulture
|
|
||||||
};
|
/* eslint-enable indent */
|
||||||
});
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ var AppInfo = {};
|
||||||
require(['globalize', 'browser'], function (globalize, browser) {
|
require(['globalize', 'browser'], function (globalize, browser) {
|
||||||
window.Globalize = globalize;
|
window.Globalize = globalize;
|
||||||
loadCoreDictionary(globalize).then(function () {
|
loadCoreDictionary(globalize).then(function () {
|
||||||
onGlobalizeInit(browser);
|
onGlobalizeInit(browser, globalize);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
require(['keyboardnavigation'], function(keyboardnavigation) {
|
require(['keyboardnavigation'], function(keyboardnavigation) {
|
||||||
|
@ -455,14 +455,14 @@ var AppInfo = {};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGlobalizeInit(browser) {
|
function onGlobalizeInit(browser, globalize) {
|
||||||
if ('android' === self.appMode) {
|
if ('android' === self.appMode) {
|
||||||
if (-1 !== self.location.href.toString().toLowerCase().indexOf('start=backgroundsync')) {
|
if (-1 !== self.location.href.toString().toLowerCase().indexOf('start=backgroundsync')) {
|
||||||
return onAppReady(browser);
|
return onAppReady(browser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.title = Globalize.translateDocument(document.title, 'core');
|
document.title = globalize.translateHtml(document.title, 'core');
|
||||||
|
|
||||||
if (browser.tv && !browser.android) {
|
if (browser.tv && !browser.android) {
|
||||||
console.debug('using system fonts with explicit sizes');
|
console.debug('using system fonts with explicit sizes');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue