From ddb4a8fece83d619900dfb550d550cf58069829e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 26 Mar 2023 06:24:00 +0400 Subject: [PATCH] Localize the UI --- bundle.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/bundle.js b/bundle.js index b3ecdef..c3c3490 100644 --- a/bundle.js +++ b/bundle.js @@ -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 += '

' + part_of_speech + '

' } if (translations) { - html += '

Значения

' + translations + '
' + html += + '
' + + '

' + window.leqsikoni.translate('Meanings') + '

' + + '
' + translations + '
' + + '
' } if (commentary) { - html += '

Комментарий

' + commentary + '

' + html += + '
' + + '

' + window.leqsikoni.translate('Commentary') + '

' + + '

' + commentary + '

' + + '
' } if (inflections) { - html += '

Inflections

' + inflections + '
' + html += + '
' + + '

' + window.leqsikoni.translate('Inflections') + '

' + + '
' + inflections + '
' + + '
' } if (examples) { html += - '

Примеры употребления

' + examples + '
' + '
' + + '

' + window.leqsikoni.translate('Usage examples') + '

' + + '
' + examples + '
' + + '
' } return html