summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-30 13:04:35 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-30 13:09:29 +0200
commit07a6662be9f1a59bfe3ae42baa6589d74568c9ce (patch)
tree80b2def41adcd06e360e475d712d37196cd5f45f
parent5b03ea193c1927305fc99b93307b6c74bde0d84d (diff)
Add codeq.tr.translate function for GUI strings not in DOM
-rw-r--r--js/codeq/hint.js4
-rw-r--r--js/codeq/profile.js5
-rw-r--r--js/codeq/translation.js12
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 <http://www.gnu.org/licenses/>. */
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 <http://www.gnu.org/licenses/>. */
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 <http://www.gnu.org/licenses/>. */
data = data.stat;
var columns = ['language', 'problem_group', 'problems_count', 'done', 'in_progress'],
- items='<thead><tr>',
- tr_gui = codeq.tr.getDictionary('gui');
+ items='<thead><tr>';
$.each(columns, function( key, val ) {
- items+='<th data-tkey="'+ val + '">'+tr_gui[val][codeq.settings['gui_lang']]+'</th>';
+ items+='<th data-tkey="'+val+'">'+codeq.tr.translate(val)+'</th>';
});
items+='</tr></thead>';
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 <http://www.gnu.org/licenses/>. */
'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 <http://www.gnu.org/licenses/>. */
jqTopElt.find('[data-tkey]').each(function () {
translateElement($(this),'tkey', lang);
});
- },
-
- 'getDictionary': function (name) {
- return dicts[name];
}
};
})();