Skip to content

Commit

Permalink
Merge pull request #78 from euforic/TIMOB-16149
Browse files Browse the repository at this point in the history
[TIMOB-16149] properly decode xml entities in i18n strings.xml
  • Loading branch information
Michael Xia committed Feb 15, 2014
2 parents 3360055 + 513d65e commit caa08c3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/fserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@ FServer.start = function(opts) {
var langs = fs.readdirSync(LOCALE_DIR);
var langData = {};


function decodeEntity(str) {
var names = {
'nbsp': 160,
'lt': 60,
'gt': 62,
'amp': 38,
'cent': 162,
'pound': 163,
'yen': 164,
'euro': 8364,
'copy': 169,
'reg:': 174
};

return ('' + str).replace(/&#?([\w\d]+);?/g, function(s, entity) {
entity = (isNaN(entity)) ? names[entity] : entity;
return String.fromCharCode(encodeURI(entity).replace('%'));
});
};

function next(i) {
if (!langs[i]) {
response.write('module.exports = ' + JSON.stringify(langData) + ';');
Expand All @@ -223,7 +244,7 @@ FServer.start = function(opts) {

parser.on('tag', function (e) {
if(e.name !== 'string') { return; }
tags[e.attr.name] = this._text;
tags[e.attr.name] = decodeEntity(this._text);
});

fs.createReadStream(join(LOCALE_DIR, langs[i], 'strings.xml'))
Expand Down

0 comments on commit caa08c3

Please sign in to comment.