FIX: Enabling verbose localization for session didn't work
This commit is contained in:
parent
179ecee11e
commit
3fde4c9db7
|
@ -4,31 +4,21 @@ export default {
|
|||
name: 'localization',
|
||||
after: 'inject-objects',
|
||||
|
||||
enableVerboseLocalization() {
|
||||
let counter = 0;
|
||||
let keys = {};
|
||||
let t = I18n.t;
|
||||
|
||||
I18n.noFallbacks = true;
|
||||
isVerboseLocalizationEnabled(container) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
if (siteSettings.verbose_localization) return true;
|
||||
|
||||
I18n.t = I18n.translate = function(scope, value){
|
||||
let current = keys[scope];
|
||||
if (!current) {
|
||||
current = keys[scope] = ++counter;
|
||||
let message = "Translation #" + current + ": " + scope;
|
||||
if (!_.isEmpty(value)) {
|
||||
message += ", parameters: " + JSON.stringify(value);
|
||||
}
|
||||
Em.Logger.info(message);
|
||||
}
|
||||
return t.apply(I18n, [scope, value]) + " (#" + current + ")";
|
||||
};
|
||||
try {
|
||||
return sessionStorage && sessionStorage.getItem("verbose_localization");
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
if (siteSettings.verbose_localization) {
|
||||
this.enableVerboseLocalization();
|
||||
if (this.isVerboseLocalizationEnabled(container)) {
|
||||
I18n.enableVerboseLocalization();
|
||||
}
|
||||
|
||||
// Merge any overrides into our object
|
||||
|
|
|
@ -292,5 +292,33 @@ I18n.currentLocale = function() {
|
|||
return I18n.locale || I18n.defaultLocale;
|
||||
};
|
||||
|
||||
I18n.enableVerboseLocalization = function() {
|
||||
var counter = 0;
|
||||
var keys = {};
|
||||
var t = I18n.t;
|
||||
|
||||
I18n.noFallbacks = true;
|
||||
|
||||
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);
|
||||
}
|
||||
Em.Logger.info(message);
|
||||
}
|
||||
return t.apply(I18n, [scope, value]) + " (#" + current + ")";
|
||||
};
|
||||
};
|
||||
|
||||
I18n.enableVerboseLocalizationSession = function() {
|
||||
sessionStorage.setItem("verbose_localization", "true");
|
||||
I18n.enableVerboseLocalization();
|
||||
|
||||
return 'Verbose localization is enabled. Close the browser tab to turn it off. Reload the page to see the translation keys.';
|
||||
};
|
||||
|
||||
// shortcuts
|
||||
I18n.t = I18n.translate;
|
||||
|
|
Loading…
Reference in New Issue