From f48b78c0bbebd49c1f4606bfc565c2c08fffcd25 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Aug 2014 17:50:13 +1000 Subject: [PATCH] FEATURE: Allow localization sessions use: I18n.verbose_localization_session() --- .../initializers/verbose-localization.js.es6 | 18 +--------- app/assets/javascripts/locales/i18n.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/verbose-localization.js.es6 b/app/assets/javascripts/discourse/initializers/verbose-localization.js.es6 index 8f27beb4691..80e5a2fb90b 100644 --- a/app/assets/javascripts/discourse/initializers/verbose-localization.js.es6 +++ b/app/assets/javascripts/discourse/initializers/verbose-localization.js.es6 @@ -3,23 +3,7 @@ export default { initialize: function() { if(Discourse.SiteSettings.verbose_localization){ - var counter = 0; - var keys = {}; - var t = I18n.t; - - - I18n.t = I18n.translate = function(scope, value){ - var current = keys[scope]; - if(!current) { - current = keys[scope] = ++counter; - var message = "Translation #" + current + ": " + scope; - if (!_.isEmpty(value)) { - message += ", parameters: " + JSON.stringify(value); - } - window.console.log(message); - } - return t.apply(I18n, [scope, value]) + " (t" + current + ")"; - }; + I18n.enable_verbose_localization(); } } }; diff --git a/app/assets/javascripts/locales/i18n.js b/app/assets/javascripts/locales/i18n.js index 03cdfeb2076..29e572e388d 100644 --- a/app/assets/javascripts/locales/i18n.js +++ b/app/assets/javascripts/locales/i18n.js @@ -507,3 +507,37 @@ I18n.currentLocale = function() { I18n.t = I18n.translate; I18n.l = I18n.localize; I18n.p = I18n.pluralize; + +I18n.enable_verbose_localization = function(){ + var counter = 0; + var keys = {}; + var t = I18n.t; + + + I18n.t = I18n.translate = function(scope, value){ + var current = keys[scope]; + if(!current) { + current = keys[scope] = ++counter; + var message = "Translation #" + current + ": " + scope; + if (!_.isEmpty(value)) { + message += ", parameters: " + JSON.stringify(value); + } + window.console.log(message); + } + return t.apply(I18n, [scope, value]) + " (t" + current + ")"; + }; +}; + + +I18n.verbose_localization_session = function(){ + sessionStorage.setItem("verbose_localization", "true"); + I18n.enable_verbose_localization(); +} + +try { + if(sessionStorage && sessionStorage.getItem("verbose_localization")) { + I18n.enable_verbose_localization(); + } +} catch(e){ + // we don't care really, can happen if cookies disabled +}