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 += '' + commentary + '
' + commentary + '
' + + '