Skip to content

Commit

Permalink
FEATURE: Allow localization sessions
Browse files Browse the repository at this point in the history
use: I18n.verbose_localization_session()
  • Loading branch information
SamSaffron committed Aug 27, 2014
1 parent 587f7f5 commit f48b78c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};
34 changes: 34 additions & 0 deletions app/assets/javascripts/locales/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f48b78c

Please sign in to comment.