Skip to content

Commit

Permalink
#677 Fixed localization controller to be backward compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Sep 2, 2015
1 parent 3c21ae0 commit 58e9839
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 26 additions & 2 deletions include/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,36 @@ module.exports = function LocalizationModule(pb) {
* @param {String} locale
* @return {Object}
*/
Localization.getLocalizationPackage = function(locale) {//TODO fix this
Localization.getLocalizationPackage = function(locale, options) {
if (!pb.validation.isNonEmptyStr(locale, true)) {
return null;
}

return Localization.storage[locale.toLowerCase()] || null;
var ls = new Localization(locale);
var package = {};
var keys = Object.keys(Localization.keys);
keys.forEach(function(key) {
var result = ls.g(key, {}, options);

var parts = key.split(Localization.KEY_SEP);
if (parts.length === 1) {
package[key] = result;
return;
}

var block = package;
for (var i = 0; i < parts.length; i++) {
if (i == parts.length - 1) {
block[parts[i]] = result;
break;
}
else if (util.isNullOrUndefined(block[parts[i]])) {
block[parts[i]] = {};
}
block = block[parts[i]];
}
});
return package;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ module.exports = function LocalizationApiControllerModule(pb) {
*/
LocalizationApiController.prototype.getAsScript = function(cb) {
var locale = this.query.locale || this.ls.language;
var plugin = this.query.plugin;

var package = pb.Localization.getLocalizationPackage(locale, { plugin: plugin });
var content = {
content: 'var loc = ' + JSON.stringify(pb.Localization.storage[locale]) + ';',
content: 'var loc = ' + JSON.stringify(package) + ';',
content_type: 'text/javascript'
};
cb(content);
Expand Down

0 comments on commit 58e9839

Please sign in to comment.