mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
rework localization
This commit is contained in:
parent
b1f6f8486a
commit
043f8b7889
82 changed files with 83316 additions and 96 deletions
|
@ -502,29 +502,6 @@ function ticks_to_human(str) {
|
|||
return time;
|
||||
};
|
||||
|
||||
(function (window) {
|
||||
|
||||
// Mimic Globalize api
|
||||
// https://github.com/jquery/globalize
|
||||
// Maybe later switch to it
|
||||
|
||||
window.Globalize = {
|
||||
translate: function (key) {
|
||||
|
||||
var val = window.localizationGlossary[key] || key;
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
|
||||
val = val.replace('{' + (i - 1) + '}', arguments[i]);
|
||||
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
})(window);
|
||||
|
||||
(function () {
|
||||
var supportTouch = $.support.touch,
|
||||
scrollEvent = "touchmove scroll",
|
||||
|
@ -595,7 +572,7 @@ function ticks_to_human(str) {
|
|||
})();
|
||||
|
||||
// This only exists because the polymer elements get distorted when using regular jquery show/hide
|
||||
$.fn.visible = function(visible) {
|
||||
$.fn.visible = function (visible) {
|
||||
|
||||
if (visible) {
|
||||
return this.removeClass('hide');
|
||||
|
|
109
dashboard-ui/scripts/globalize.js
Normal file
109
dashboard-ui/scripts/globalize.js
Normal file
|
@ -0,0 +1,109 @@
|
|||
(function () {
|
||||
|
||||
var dictionaries = {};
|
||||
|
||||
function getUrl(name, culture) {
|
||||
|
||||
return 'strings/' + name + '/' + culture + '.json';
|
||||
}
|
||||
function getDictionary(name, culture) {
|
||||
|
||||
return dictionaries[getUrl(name, culture)];
|
||||
}
|
||||
|
||||
function loadDictionary(name, culture) {
|
||||
|
||||
var deferred = DeferredBuilder.Deferred();
|
||||
|
||||
if (getDictionary(name, culture)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
|
||||
var url = getUrl(name, culture);
|
||||
|
||||
$.getJSON(url).done(function (dictionary) {
|
||||
dictionaries[url] = dictionary;
|
||||
deferred.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
var currentCulture = 'en-US';
|
||||
function setCulture(value) {
|
||||
|
||||
var promises = [];
|
||||
|
||||
currentCulture = value;
|
||||
|
||||
promises.push(loadDictionary('html', value));
|
||||
promises.push(loadDictionary('javascript', value));
|
||||
|
||||
return $.when(promises);
|
||||
}
|
||||
|
||||
function ensure() {
|
||||
|
||||
var culture = document.documentElement.getAttribute('data-culture');
|
||||
|
||||
if (!culture) {
|
||||
culture = 'en-US';
|
||||
}
|
||||
|
||||
return setCulture(culture);
|
||||
}
|
||||
|
||||
function translateDocument(html, dictionaryName) {
|
||||
|
||||
var glossary = getDictionary(dictionaryName, currentCulture) || {};
|
||||
|
||||
return translateHtml(html, glossary);
|
||||
}
|
||||
|
||||
function translateHtml(html, dictionary) {
|
||||
|
||||
var startIndex = html.indexOf('${');
|
||||
|
||||
if (startIndex == -1) {
|
||||
return html;
|
||||
}
|
||||
|
||||
startIndex += 2;
|
||||
var endIndex = html.indexOf('}', startIndex);
|
||||
|
||||
if (endIndex == -1) {
|
||||
return html;
|
||||
}
|
||||
|
||||
var key = html.substring(startIndex, endIndex);
|
||||
var val = dictionary[key] || key;
|
||||
|
||||
html = html.replace('${' + key + '}', val);
|
||||
|
||||
return translateHtml(html, dictionary);
|
||||
}
|
||||
|
||||
// Mimic Globalize api
|
||||
// https://github.com/jquery/globalize
|
||||
// Maybe later switch to it
|
||||
|
||||
window.Globalize = {
|
||||
translate: function (key) {
|
||||
|
||||
var glossary = getDictionary('javascript', currentCulture) || {};
|
||||
var val = glossary[key] || key;
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
|
||||
val = val.replace('{' + (i - 1) + '}', arguments[i]);
|
||||
|
||||
}
|
||||
|
||||
return val;
|
||||
},
|
||||
ensure: ensure,
|
||||
translateDocument: translateDocument
|
||||
};
|
||||
|
||||
})();
|
|
@ -12,8 +12,6 @@
|
|||
$('#selectThemeSong', page).val(appStorage.getItem('enableThemeSongs-' + user.Id) || '').selectmenu("refresh");
|
||||
$('#selectBackdrop', page).val(appStorage.getItem('enableBackdrops-' + user.Id) || '').selectmenu("refresh");
|
||||
|
||||
$('#selectEnableItemPreviews', page).val(AppSettings.enableItemPreviews().toString().toLowerCase()).selectmenu("refresh");
|
||||
|
||||
$('#chkEnableFullScreen', page).checked(AppSettings.enableFullScreen()).checkboxradio("refresh");
|
||||
|
||||
$('#chkSyncToExternalCard', page).checked(AppSettings.enableSyncToExternalStorage()).checkboxradio("refresh");
|
||||
|
@ -28,7 +26,6 @@
|
|||
user.Configuration.GroupMoviesIntoBoxSets = $('#chkGroupMoviesIntoCollections', page).checked();
|
||||
user.Configuration.IncludeTrailersInSuggestions = $('#chkDisplayTrailersWithinMovieSuggestions', page).checked();
|
||||
|
||||
AppSettings.enableItemPreviews($('#selectEnableItemPreviews', page).val() == 'true');
|
||||
AppSettings.enableFullScreen($('#chkEnableFullScreen', page).checked());
|
||||
|
||||
appStorage.setItem('enableThemeSongs-' + user.Id, $('#selectThemeSong', page).val());
|
||||
|
|
|
@ -160,7 +160,6 @@
|
|||
function loadForm(page, user, displayPreferences) {
|
||||
|
||||
$('#chkDisplayCollectionView', page).checked(user.Configuration.DisplayCollectionsView || false).checkboxradio("refresh");
|
||||
$('#chkDisplayFolderView', page).checked(user.Configuration.DisplayFoldersView || false).checkboxradio("refresh");
|
||||
|
||||
$('#chkHidePlayedFromLatest', page).checked(user.Configuration.HidePlayedInLatest || false).checkboxradio("refresh");
|
||||
|
||||
|
@ -195,7 +194,6 @@
|
|||
function saveUser(page, user, displayPreferences) {
|
||||
|
||||
user.Configuration.DisplayCollectionsView = $('#chkDisplayCollectionView', page).checked();
|
||||
user.Configuration.DisplayFoldersView = $('#chkDisplayFolderView', page).checked();
|
||||
|
||||
user.Configuration.HidePlayedInLatest = $('#chkHidePlayedFromLatest', page).checked();
|
||||
|
||||
|
|
|
@ -68,6 +68,13 @@ var Dashboard = {
|
|||
$.mobile.nojs = null;
|
||||
$.mobile.degradeInputsWithin = null;
|
||||
$.mobile.keepNative = ":jqmData(role='none'),.paper-input";
|
||||
|
||||
$.mobile.filterHtml = Dashboard.filterHtml;
|
||||
},
|
||||
|
||||
filterHtml: function (html) {
|
||||
|
||||
return Globalize.translateDocument(html, 'html');
|
||||
},
|
||||
|
||||
isConnectMode: function () {
|
||||
|
@ -1783,6 +1790,7 @@ var AppInfo = {};
|
|||
ConnectionManager.addApiClient(apiClient);
|
||||
Dashboard.importCss(apiClient.getUrl('Branding/Css'));
|
||||
window.ApiClient = apiClient;
|
||||
deferred.resolve();
|
||||
}
|
||||
return deferred.promise();
|
||||
}
|
||||
|
@ -2043,28 +2051,24 @@ var AppInfo = {};
|
|||
drawer.disableEdgeSwipe = true;
|
||||
}
|
||||
|
||||
if (Dashboard.isConnectMode()) {
|
||||
var deps = [];
|
||||
|
||||
if (AppInfo.isNativeApp && $.browser.android) {
|
||||
require(['cordova/android/logging']);
|
||||
}
|
||||
if (AppInfo.isNativeApp && $.browser.android) {
|
||||
deps.push('cordova/android/logging');
|
||||
}
|
||||
|
||||
require(['appstorage'], function () {
|
||||
deps.push('appstorage');
|
||||
|
||||
capabilities.DeviceProfile = MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width));
|
||||
createConnectionManager(capabilities).done(function () {
|
||||
$(function () {
|
||||
onDocumentReady();
|
||||
Dashboard.initPromiseDone = true;
|
||||
$.mobile.initializePage();
|
||||
deferred.resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
require([deps], function () {
|
||||
|
||||
} else {
|
||||
createConnectionManager(capabilities);
|
||||
capabilities.DeviceProfile = MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width));
|
||||
createConnectionManager(capabilities).done(function () { onConnectionManagerCreated(deferred); });
|
||||
});
|
||||
}
|
||||
|
||||
function onConnectionManagerCreated(deferred) {
|
||||
|
||||
Globalize.ensure().done(function () {
|
||||
$(function () {
|
||||
|
||||
onDocumentReady();
|
||||
|
@ -2072,7 +2076,7 @@ var AppInfo = {};
|
|||
$.mobile.initializePage();
|
||||
deferred.resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initCordovaWithDeviceId(deferred, deviceId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue