2
0
Fork 0

Localize the UI

This commit is contained in:
Alex Kotov 2023-03-26 06:24:00 +04:00
parent 6a134a4f42
commit ddb4a8fece
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 54 additions and 4 deletions

View File

@ -1,4 +1,39 @@
window.leqsikoni = {
translations: {
en: {
Meanings: 'Meanings',
Commentary: 'Commentary',
Inflections: 'Inflections',
'Usage examples': 'Usage examples',
},
ru: {
Meanings: 'Значения',
Commentary: 'Комментарий',
Inflections: 'Формы слова',
'Usage examples': 'Примеры употребления',
},
},
translate: function(key, options) {
key = String(key)
if (!options || typeof(options) !== 'object') {
options = {}
}
var no_translation = '[no translation for key: ' + key + ']'
var locale = String($('#locale').val())
var translations = window.leqsikoni.translations[locale]
if (typeof(translations) === 'undefined') return no_translation
var translation = String(translations[key])
if (typeof(translation) === 'undefined') return no_translation
// TODO: apply options
return translation
},
maybe_text: function(obj) {
if (obj) {
return String(obj).trim() || null
@ -58,17 +93,32 @@ window.leqsikoni = {
html += '<p>' + part_of_speech + '</p>'
}
if (translations) {
html += '<div><h2>Значения</h2><div>' + translations + '</div></div>'
html +=
'<div>' +
'<h2>' + window.leqsikoni.translate('Meanings') + '</h2>' +
'<div>' + translations + '</div>' +
'</div>'
}
if (commentary) {
html += '<div><h2>Комментарий</h2><p>' + commentary + '</p></div>'
html +=
'<div>' +
'<h2>' + window.leqsikoni.translate('Commentary') + '</h2>' +
'<p>' + commentary + '</p>' +
'</div>'
}
if (inflections) {
html += '<div><h2>Inflections</h2><div>' + inflections + '</div></div>'
html +=
'<div>' +
'<h2>' + window.leqsikoni.translate('Inflections') + '</h2>' +
'<div>' + inflections + '</div>' +
'</div>'
}
if (examples) {
html +=
'<div><h2>Примеры употребления</h2><div>' + examples + '</div></div>'
'<div>' +
'<h2>' + window.leqsikoni.translate('Usage examples') + '</h2>' +
'<div>' + examples + '</div>' +
'</div>'
}
return html