diff --git a/resources/static/shared/gettext.js b/resources/static/shared/gettext.js index dab6ac4f144e3c6ef9643f6d7bc6d8856aca35fe..2b24477c5a468f3f8ac97ebcabb135da4f3c94d1 100644 --- a/resources/static/shared/gettext.js +++ b/resources/static/shared/gettext.js @@ -1,30 +1,44 @@ +/*globals json_locale_data: true */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -function Gettext(params) { - return { - gettext: function (msgid) { - if (json_locale_data && json_locale_data["client"]) { - var dict = json_locale_data["client"]; - if (dict[msgid] && dict[msgid].length >= 2 && - dict[msgid][1].trim() != "") { - return dict[msgid][1]; - } - } - return msgid; - }, - // See lib/i18n.js format docs - format: function (fmt, obj, named) { - if (! fmt) return ""; - if (! fmt.replace) { - return fmt; +(function() { + "use strict"; + + function Gettext(params) { + return { + gettext: function (msgid) { + if (json_locale_data && json_locale_data["client"]) { + var dict = json_locale_data["client"]; + if (dict[msgid] && dict[msgid].length >= 2 && + dict[msgid][1].trim() != "") { + return dict[msgid][1]; + } } - if (named) { - return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); - } else { - return fmt.replace(/%s/g, function(match){return String(obj.shift())}); + return msgid; + }, + // See lib/i18n.js format docs + format: function (fmt, obj, named) { + if (! fmt) return ""; + if (! fmt.replace) { + return fmt; + } + if (named) { + return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); + } else { + return fmt.replace(/%s/g, function(match){return String(obj.shift())}); + } } - } - }; -}; \ No newline at end of file + }; + }; + + var params = { + "domain" : "client", + "locale_data" : json_locale_data + }; + var gt = new Gettext(params); + window.gettext = gt.gettext.bind(gt); + window.format = gt.format.bind(gt); + +}()); diff --git a/resources/static/shared/renderer.js b/resources/static/shared/renderer.js index 62b2421675a8fe682c16255a0adb9d27898bc14a..8cbfb216a5c541d1ac62782efc3564abea3df593 100644 --- a/resources/static/shared/renderer.js +++ b/resources/static/shared/renderer.js @@ -26,14 +26,6 @@ BrowserID.Renderer = (function() { url: "/dialog/views/" + templateName + ".ejs" }; } - // TODO(aok) Do caching like EJS below - var params = { - "domain" : "client", - "locale_data" : json_locale_data - }; - var gt = new Gettext(params); - window.gettext = gt.gettext.bind(gt); - window.format = gt.format.bind(gt); var template = templateCache[templateName]; if(!template) {