From 07a6662be9f1a59bfe3ae42baa6589d74568c9ce Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 30 Mar 2016 13:04:35 +0200 Subject: Add codeq.tr.translate function for GUI strings not in DOM --- js/codeq/hint.js | 4 +--- js/codeq/profile.js | 5 ++--- js/codeq/translation.js | 12 ++++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/js/codeq/hint.js b/js/codeq/hint.js index b8cf03b..e77a3dc 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -38,8 +38,6 @@ along with this program. If not, see . */ hintCommonTr = commonDef.hint, planDef = problemDef.plan, templatePath = [problemDef.language, problemDef.group, problemDef.problem], - guiDict = codeq.tr.getDictionary('gui'), - btnMoreTranslations = guiDict['btn_more'] || {}, // get the default translations for the "more..." button clearHints = function () { var i; @@ -197,7 +195,7 @@ along with this program. If not, see . */ msg = content[lang][hintIndex]; if (typeof msg === 'string') { trContent[lang] = codeq.template.process(msg, templatePath, args); - trButton[lang] = btnMoreTranslations[lang] || 'More...'; + trButton[lang] = codeq.tr.translate('btn_more', lang) || 'More...'; } else { trContent[lang] = codeq.template.process(msg.message, templatePath, args); diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 8d26c85..5176fc0 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -50,11 +50,10 @@ along with this program. If not, see . */ data = data.stat; var columns = ['language', 'problem_group', 'problems_count', 'done', 'in_progress'], - items='', - tr_gui = codeq.tr.getDictionary('gui'); + items=''; $.each(columns, function( key, val ) { - items+=''+tr_gui[val][codeq.settings['gui_lang']]+''; + items+=''+codeq.tr.translate(val)+''; }); items+=''; diff --git a/js/codeq/translation.js b/js/codeq/translation.js index b453876..e648ae3 100644 --- a/js/codeq/translation.js +++ b/js/codeq/translation.js @@ -98,6 +98,14 @@ along with this program. If not, see . */ 'emptyDictionary': {}, // use this with registerDictionary when you don't want any translations + 'translate': function (key, lang) { + var dict = dicts['gui']; + lang = lang || codeq.settings['gui_lang']; + if (dict && dict[key] && dict[key][lang]) { + return dict[key][lang]; + } + }, + 'translateDom': function (jqTopElt) { var lang = codeq.settings['gui_lang']; jqTopElt.filter('[data-tkey]').each(function () { @@ -106,10 +114,6 @@ along with this program. If not, see . */ jqTopElt.find('[data-tkey]').each(function () { translateElement($(this),'tkey', lang); }); - }, - - 'getDictionary': function (name) { - return dicts[name]; } }; })(); -- cgit v1.2.1