dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32395
Java properties files in Javascript clients
Hi, the following function can be used to parse Java properties files (e.g.
for i18n) on the key=value format in a Javascript client. So far it handles
- unicoded characters on the format \uXXXX
- untrimmed keys and values
- values with quotation marks
- any number of line breaks
- lines that are not key=value such as date/timestamps
Please feel free to improve it.
parseProperties = function(responseText) {
var i18n = {}, rows;
if (typeof responseText !== 'string') {
return i18n;
}
rows = responseText.split(/\n/);
for (var i = 0, a; i < rows.length; i++) {
if (!!(typeof rows[i] === 'string' && rows[i].length &&
rows[i].indexOf('=') !== -1)) {
a = rows[i].split('=');
i18n[a[0].trim()] = eval('"' + a[1].trim().replace(/"/g, '\'')
+ '"');
}
}
return i18n;
};
Follow ups