FEATURE: Allow localization sessions

use: I18n.verbose_localization_session()
This commit is contained in:
Sam 2014-08-27 17:50:13 +10:00
parent 587f7f56c8
commit f48b78c0bb
2 changed files with 35 additions and 17 deletions

View File

@ -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();
}
}
};

View File

@ -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
}