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;
};
_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to