From e2f78a958509a38c1381f582e6e187428a0ee3f2 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 22 Mar 2016 11:19:33 +0200 Subject: [PATCH] closes #4432 --- public/src/app.js | 5 ++++- public/src/modules/translator.js | 13 +++++++------ src/controllers/helpers.js | 6 +++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 65276bc798..2d37b53a41 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -326,7 +326,10 @@ app.cacheBuster = null; return; } require(['translator'], function(translator) { - title = config.titleLayout.replace(/{/g, '{').replace(/}/g, '}').replace('{pageTitle}', title).replace('{browserTitle}', config.browserTitle); + title = config.titleLayout.replace(/{/g, '{').replace(/}/g, '}') + .replace('{pageTitle}', function() { return title; }) + .replace('{browserTitle}', function() { return config.browserTitle; }); + translator.translate(title, function(translated) { titleObj.titles[0] = translated; app.alternatingTitle(''); diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index 5892f6dde8..b208a0af48 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -213,13 +213,14 @@ function insertLanguage(text, key, value, variables) { if (value) { - var variable; - for (var i = 1, ii = variables.length; i < ii; i++) { - variable = S(variables[i]).chompRight(']]').collapseWhitespace().decodeHTMLEntities().escapeHTML().s; - value = value.replace('%' + i, variable); - } + variables.forEach(function(variable, index) { + if (index > 0) { + variable = S(variable).chompRight(']]').collapseWhitespace().decodeHTMLEntities().escapeHTML().s; + value = value.replace('%' + index, function() { return variable; }); + } + }); - text = text.replace(key, value); + text = text.replace(key, function() { return value; }); } else { var string = key.split(':'); text = text.replace(key, string[string.length-1].replace(regexes.replace, '')); diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 3962e2036b..058a1849b1 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -105,7 +105,11 @@ helpers.buildTitle = function(pageTitle) { var browserTitle = validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB'); pageTitle = pageTitle || ''; - var title = titleLayout.replace('{pageTitle}', pageTitle).replace('{browserTitle}', browserTitle); + var title = titleLayout.replace('{pageTitle}', function() { + return pageTitle; + }).replace('{browserTitle}', function() { + return browserTitle; + }); return title; };