mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Unminify using 1.5.323
Repo with tag: https://github.com/MediaBrowser/emby-webcomponents/tree/1.5.323
This commit is contained in:
parent
4678528d00
commit
de6ac33ec1
289 changed files with 78483 additions and 54701 deletions
312
src/bower_components/emby-webcomponents/globalize.js
vendored
312
src/bower_components/emby-webcomponents/globalize.js
vendored
|
@ -1,127 +1,287 @@
|
|||
define(["connectionManager", "userSettings", "events"], function(connectionManager, userSettings, events) {
|
||||
"use strict";
|
||||
define(['connectionManager', 'userSettings', 'events'], function (connectionManager, userSettings, events) {
|
||||
'use strict';
|
||||
|
||||
var allTranslations = {};
|
||||
var currentCulture;
|
||||
var currentDateTimeCulture;
|
||||
|
||||
function getCurrentLocale() {
|
||||
return currentCulture
|
||||
|
||||
return currentCulture;
|
||||
}
|
||||
|
||||
function getCurrentDateTimeLocale() {
|
||||
return currentDateTimeCulture
|
||||
return currentDateTimeCulture;
|
||||
}
|
||||
|
||||
function getDefaultLanguage() {
|
||||
var culture = document.documentElement.getAttribute("data-culture");
|
||||
return culture || (navigator.language ? navigator.language : navigator.userLanguage ? navigator.userLanguage : navigator.languages && navigator.languages.length ? navigator.languages[0] : "en-us")
|
||||
|
||||
var culture = document.documentElement.getAttribute('data-culture');
|
||||
|
||||
if (culture) {
|
||||
return culture;
|
||||
}
|
||||
|
||||
if (navigator.language) {
|
||||
return navigator.language;
|
||||
}
|
||||
if (navigator.userLanguage) {
|
||||
return navigator.userLanguage;
|
||||
}
|
||||
if (navigator.languages && navigator.languages.length) {
|
||||
return navigator.languages[0];
|
||||
}
|
||||
|
||||
return 'en-us';
|
||||
}
|
||||
|
||||
function updateCurrentCulture() {
|
||||
|
||||
var culture;
|
||||
try {
|
||||
culture = userSettings.language()
|
||||
} catch (err) {}
|
||||
culture = culture || getDefaultLanguage(), currentCulture = normalizeLocaleName(culture);
|
||||
culture = userSettings.language();
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
culture = culture || getDefaultLanguage();
|
||||
|
||||
currentCulture = normalizeLocaleName(culture);
|
||||
|
||||
var dateTimeCulture;
|
||||
try {
|
||||
dateTimeCulture = userSettings.dateTimeLocale()
|
||||
} catch (err) {}
|
||||
currentDateTimeCulture = dateTimeCulture ? normalizeLocaleName(dateTimeCulture) : currentCulture, ensureTranslations(currentCulture)
|
||||
dateTimeCulture = userSettings.dateTimeLocale();
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
if (dateTimeCulture) {
|
||||
currentDateTimeCulture = normalizeLocaleName(dateTimeCulture);
|
||||
}
|
||||
else {
|
||||
currentDateTimeCulture = currentCulture;
|
||||
}
|
||||
|
||||
ensureTranslations(currentCulture);
|
||||
}
|
||||
|
||||
function ensureTranslations(culture) {
|
||||
for (var i in allTranslations) ensureTranslation(allTranslations[i], culture)
|
||||
}
|
||||
|
||||
function ensureTranslation(translationInfo, culture) {
|
||||
return translationInfo.dictionaries[culture] ? Promise.resolve() : loadTranslation(translationInfo.translations, culture).then(function(dictionary) {
|
||||
translationInfo.dictionaries[culture] = dictionary
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeLocaleName(culture) {
|
||||
culture = culture.replace("_", "-");
|
||||
var parts = culture.split("-");
|
||||
2 === parts.length && parts[0].toLowerCase() === parts[1].toLowerCase() && (culture = parts[0].toLowerCase());
|
||||
var lower = culture.toLowerCase();
|
||||
return "ca-es" === lower ? "ca" : "sv-se" === lower ? "sv" : lower
|
||||
}
|
||||
|
||||
function getDictionary(module) {
|
||||
module || (module = defaultModule());
|
||||
var translations = allTranslations[module];
|
||||
return translations ? translations.dictionaries[getCurrentLocale()] : {}
|
||||
}
|
||||
|
||||
function register(options) {
|
||||
allTranslations[options.name] = {
|
||||
translations: options.strings || options.translations,
|
||||
dictionaries: {}
|
||||
for (var i in allTranslations) {
|
||||
ensureTranslation(allTranslations[i], culture);
|
||||
}
|
||||
}
|
||||
|
||||
function loadStrings(options) {
|
||||
var locale = getCurrentLocale();
|
||||
return "string" == typeof options ? ensureTranslation(allTranslations[options], locale) : (register(options), ensureTranslation(allTranslations[options.name], locale))
|
||||
function ensureTranslation(translationInfo, culture) {
|
||||
|
||||
if (translationInfo.dictionaries[culture]) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return loadTranslation(translationInfo.translations, culture).then(function (dictionary) {
|
||||
|
||||
translationInfo.dictionaries[culture] = dictionary;
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeLocaleName(culture) {
|
||||
|
||||
culture = culture.replace('_', '-');
|
||||
|
||||
// If it's de-DE, convert to just de
|
||||
var parts = culture.split('-');
|
||||
if (parts.length === 2) {
|
||||
if (parts[0].toLowerCase() === parts[1].toLowerCase()) {
|
||||
culture = parts[0].toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
var lower = culture.toLowerCase();
|
||||
|
||||
if (lower === 'ca-es') {
|
||||
return 'ca';
|
||||
}
|
||||
|
||||
// normalize Swedish
|
||||
if (lower === 'sv-se') {
|
||||
return 'sv';
|
||||
}
|
||||
|
||||
return lower;
|
||||
}
|
||||
|
||||
function getDictionary(module) {
|
||||
|
||||
if (!module) {
|
||||
module = defaultModule();
|
||||
}
|
||||
|
||||
var translations = allTranslations[module];
|
||||
|
||||
if (!translations) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return translations.dictionaries[getCurrentLocale()];
|
||||
}
|
||||
|
||||
function register(options) {
|
||||
|
||||
allTranslations[options.name] = {
|
||||
translations: options.strings || options.translations,
|
||||
dictionaries: {}
|
||||
};
|
||||
}
|
||||
|
||||
function loadStrings(options) {
|
||||
|
||||
var locale = getCurrentLocale();
|
||||
|
||||
if (typeof options === 'string') {
|
||||
return ensureTranslation(allTranslations[options], locale);
|
||||
} else {
|
||||
register(options);
|
||||
return ensureTranslation(allTranslations[options.name], locale);
|
||||
}
|
||||
}
|
||||
|
||||
var cacheParam = new Date().getTime();
|
||||
function loadTranslation(translations, lang) {
|
||||
|
||||
lang = normalizeLocaleName(lang);
|
||||
var filtered = translations.filter(function(t) {
|
||||
return normalizeLocaleName(t.lang) === lang
|
||||
|
||||
var filtered = translations.filter(function (t) {
|
||||
return normalizeLocaleName(t.lang) === lang;
|
||||
});
|
||||
return filtered.length || (filtered = translations.filter(function(t) {
|
||||
return "en-us" === normalizeLocaleName(t.lang)
|
||||
})), new Promise(function(resolve, reject) {
|
||||
if (!filtered.length) return void resolve();
|
||||
|
||||
if (!filtered.length) {
|
||||
filtered = translations.filter(function (t) {
|
||||
return normalizeLocaleName(t.lang) === 'en-us';
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (!filtered.length) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var url = filtered[0].path;
|
||||
url += -1 === url.indexOf("?") ? "?" : "&", url += "v=" + cacheParam;
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.open("GET", url, !0), xhr.onload = function(e) {
|
||||
resolve(this.status < 400 ? JSON.parse(this.response) : {})
|
||||
}, xhr.onerror = function() {
|
||||
resolve({})
|
||||
}, xhr.send()
|
||||
})
|
||||
|
||||
url += url.indexOf('?') === -1 ? '?' : '&';
|
||||
url += 'v=' + cacheParam;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onload = function (e) {
|
||||
if (this.status < 400) {
|
||||
resolve(JSON.parse(this.response));
|
||||
} else {
|
||||
resolve({});
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
resolve({});
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
function translateKey(key) {
|
||||
var module, parts = key.split("#");
|
||||
return parts.length > 1 && (module = parts[0], key = parts[1]), translateKeyFromModule(key, module)
|
||||
|
||||
var parts = key.split('#');
|
||||
var module;
|
||||
|
||||
if (parts.length > 1) {
|
||||
module = parts[0];
|
||||
key = parts[1];
|
||||
}
|
||||
|
||||
return translateKeyFromModule(key, module);
|
||||
}
|
||||
|
||||
function translateKeyFromModule(key, module) {
|
||||
|
||||
var dictionary = getDictionary(module);
|
||||
return dictionary ? dictionary[key] || key : key
|
||||
|
||||
if (!dictionary) {
|
||||
return key;
|
||||
}
|
||||
|
||||
return dictionary[key] || key;
|
||||
}
|
||||
|
||||
function replaceAll(str, find, replace) {
|
||||
return str.split(find).join(replace)
|
||||
|
||||
return str.split(find).join(replace);
|
||||
}
|
||||
|
||||
function translate(key) {
|
||||
for (var val = translateKey(key), i = 1; i < arguments.length; i++) val = replaceAll(val, "{" + (i - 1) + "}", arguments[i]);
|
||||
return val
|
||||
|
||||
var val = translateKey(key);
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
|
||||
val = replaceAll(val, '{' + (i - 1) + '}', arguments[i]);
|
||||
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
function translateHtml(html, module) {
|
||||
if (module || (module = defaultModule()), !module) throw new Error("module cannot be null or empty");
|
||||
var startIndex = html.indexOf("${");
|
||||
if (-1 === startIndex) return html;
|
||||
|
||||
if (!module) {
|
||||
module = defaultModule();
|
||||
}
|
||||
|
||||
if (!module) {
|
||||
throw new Error('module cannot be null or empty');
|
||||
}
|
||||
|
||||
var startIndex = html.indexOf('${');
|
||||
|
||||
if (startIndex === -1) {
|
||||
return html;
|
||||
}
|
||||
|
||||
startIndex += 2;
|
||||
var endIndex = html.indexOf("}", startIndex);
|
||||
if (-1 === endIndex) return html;
|
||||
var key = html.substring(startIndex, endIndex),
|
||||
val = translateKeyFromModule(key, module);
|
||||
return html = html.replace("${" + key + "}", val), translateHtml(html, module)
|
||||
var endIndex = html.indexOf('}', startIndex);
|
||||
|
||||
if (endIndex === -1) {
|
||||
return html;
|
||||
}
|
||||
|
||||
var key = html.substring(startIndex, endIndex);
|
||||
var val = translateKeyFromModule(key, module);
|
||||
|
||||
html = html.replace('${' + key + '}', val);
|
||||
return translateHtml(html, module);
|
||||
}
|
||||
|
||||
var _defaultModule;
|
||||
function defaultModule(val) {
|
||||
return val && (_defaultModule = val), _defaultModule
|
||||
|
||||
if (val) {
|
||||
|
||||
_defaultModule = val;
|
||||
}
|
||||
|
||||
return _defaultModule;
|
||||
}
|
||||
var currentCulture, currentDateTimeCulture, _defaultModule, allTranslations = {},
|
||||
cacheParam = (new Date).getTime();
|
||||
return updateCurrentCulture(), events.on(connectionManager, "localusersignedin", updateCurrentCulture), events.on(userSettings, "change", function(e, name) {
|
||||
"language" !== name && "datetimelocale" !== name || updateCurrentCulture()
|
||||
}), {
|
||||
|
||||
updateCurrentCulture();
|
||||
|
||||
events.on(connectionManager, 'localusersignedin', updateCurrentCulture);
|
||||
events.on(userSettings, 'change', function (e, name) {
|
||||
if (name === 'language' || name === 'datetimelocale') {
|
||||
updateCurrentCulture();
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getString: translate,
|
||||
translate: translate,
|
||||
translateDocument: translateHtml,
|
||||
|
@ -131,5 +291,5 @@ define(["connectionManager", "userSettings", "events"], function(connectionManag
|
|||
getCurrentLocale: getCurrentLocale,
|
||||
getCurrentDateTimeLocale: getCurrentDateTimeLocale,
|
||||
register: register
|
||||
}
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue