packages/cafeteria/docs/localize/resource_conv.js
function (singular) {
    var self = this;
    this.singluer = singular;
    this.requireDefaultFile = false;
    // [CDP customize]
    this.folderName = '..\\..\\app\\res\\locales';
    // [CDP customize]
    this.formatLine = function (key, value) {
        var v2 = '' + value;
        return '  "' + key + '": "' + v2.replace(/"/g, '\\"') + '",\n';
    };
    this.formatLastLine = function (key, value) {
        var v2 = '' + value;
        return '  "' + key + '": "' + v2.replace(/"/g, '\\"') + '"\n';
    };
    this.formatComment = function (comment) {
        return '';
    };
    this.formatEmptyLine = function () { return ''; };
    this.formatHeader = function (localeKey) {
        return self.singluer ? '{\n' : '';
    };
    this.formatFooter = function (localeKey) {
        // [CDP customize]
        return self.singluer ? '\n}' : '\n';
        // [CDP customize]
    };
    this.getFilePath = function (folderPath, localeKey) {
        return folderPath + '\\messages.' + localeKey + '.json';
    };
    this.normalizeLines = function (lines) {
        // format: json-singluer, noop.
        if (self.singluer) {
            return lines;
        }

        // ensure JSON object
        (function () {
            if (typeof JSON !== 'object') {
                var fileStream = fso.openTextFile('.\\json2.js');
                var fileData = fileStream.readAll();
                fileStream.Close();
                /*jshint evil: true */
                eval(fileData);
                /*jshint evil: false */
            }
        }());

        var flatJsonObj = (function () {
            var flatSrc = '{\n';
            for (var i = 0, n = lines.length; i < n; i++) {
                var line = lines[i];
                if (i === n - 1) {  // last line
                    line = line.split(',')[0];
                }
                flatSrc += line;
            }
            flatSrc += '\n}';
            return JSON.parse(flatSrc);
        }());

        var jsonText = (function (flat) {
            var normalize = {};
            for (var key in flat) {
                var value = flat[key];
                var keys = key.split(".");
                var temp = normalize;
                for (var i = 0, n = keys.length; i < n; i++) {
                    if (!temp[keys[i]]) {
                        if (i < n - 1) {
                            temp[keys[i]] = {};
                        } else {
                            temp[keys[i]] = value;
                        }
                    }
                    temp = temp[keys[i]];
                }
            }
            return JSON.stringify(normalize, null, 4);
        }(flatJsonObj));

        return jsonText.split('\r\n');
    };
}
function (singular) {
    var self = this;
    this.singluer = singular;
    this.requireDefaultFile = false;
    // [CDP customize]
    this.folderName = '..\\..\\app\\res\\locales';
    // [CDP customize]
    this.formatLine = function (key, value) {
        var v2 = '' + value;
        return '  "' + key + '": "' + v2.replace(/"/g, '\\"') + '",\n';
    };
    this.formatLastLine = function (key, value) {
        var v2 = '' + value;
        return '  "' + key + '": "' + v2.replace(/"/g, '\\"') + '"\n';
    };
    this.formatComment = function (comment) {
        return '';
    };
    this.formatEmptyLine = function () { return ''; };
    this.formatHeader = function (localeKey) {
        return self.singluer ? '{\n' : '';
    };
    this.formatFooter = function (localeKey) {
        // [CDP customize]
        return self.singluer ? '\n}' : '\n';
        // [CDP customize]
    };
    this.getFilePath = function (folderPath, localeKey) {
        return folderPath + '\\messages.' + localeKey + '.json';
    };
    this.normalizeLines = function (lines) {
        // format: json-singluer, noop.
        if (self.singluer) {
            return lines;
        }

        // ensure JSON object
        (function () {
            if (typeof JSON !== 'object') {
                var fileStream = fso.openTextFile('.\\json2.js');
                var fileData = fileStream.readAll();
                fileStream.Close();
                /*jshint evil: true */
                eval(fileData);
                /*jshint evil: false */
            }
        }());

        var flatJsonObj = (function () {
            var flatSrc = '{\n';
            for (var i = 0, n = lines.length; i < n; i++) {
                var line = lines[i];
                if (i === n - 1) {  // last line
                    line = line.split(',')[0];
                }
                flatSrc += line;
            }
            flatSrc += '\n}';
            return JSON.parse(flatSrc);
        }());

        var jsonText = (function (flat) {
            var normalize = {};
            for (var key in flat) {
                var value = flat[key];
                var keys = key.split(".");
                var temp = normalize;
                for (var i = 0, n = keys.length; i < n; i++) {
                    if (!temp[keys[i]]) {
                        if (i < n - 1) {
                            temp[keys[i]] = {};
                        } else {
                            temp[keys[i]] = value;
                        }
                    }
                    temp = temp[keys[i]];
                }
            }
            return JSON.stringify(normalize, null, 4);
        }(flatJsonObj));

        return jsonText.split('\r\n');
    };
}
function ( singular ) { var self = this ; this . singluer = singular ; this . requireDefaultFile = false ; // [CDP customize] this . folderName = '..\\..\\app\\res\\locales' ; // [CDP customize] this . formatLine = function ( key , value ) { var v2 = '' + value ; return '  "' + key + '": "' + v2 . replace ( / " / g , '\\"' ) + '",\n' ; } ; this . formatLastLine = function ( key , value ) { var v2 = '' + value ; return '  "' + key + '": "' + v2 . replace ( / " / g , '\\"' ) + '"\n' ; } ; this . formatComment = function ( comment ) { return '' ; } ; this . formatEmptyLine = function ( ) { return '' ; } ; this . formatHeader = function ( localeKey ) { return self . singluer ? '{\n' : '' ; } ; this . formatFooter = function ( localeKey ) { // [CDP customize] return self . singluer ? '\n}' : '\n' ; // [CDP customize] } ; this . getFilePath = function ( folderPath , localeKey ) { return folderPath + '\\messages.' + localeKey + '.json' ; } ; this . normalizeLines = function ( lines ) { // format: json-singluer, noop. if ( self . singluer ) { return lines ; } // ensure JSON object ( function ( ) { if ( typeof JSON !== 'object' ) { var fileStream = fso . openTextFile ( '.\\json2.js' ) ; var fileData = fileStream . readAll ( ) ; fileStream . Close ( ) ; /*jshint evil: true */ eval ( fileData ) ; /*jshint evil: false */ } } ( ) ) ; var flatJsonObj = ( function ( ) { var flatSrc = '{\n' ; for ( var i = 0 , n = lines . length ; i < n ; i ++ ) { var line = lines [ i ] ; if ( i === n - 1 ) { // last line line = line . split ( ',' ) [ 0 ] ; } flatSrc += line ; } flatSrc += '\n}' ; return JSON . parse ( flatSrc ) ; } ( ) ) ; var jsonText = ( function ( flat ) { var normalize = { } ; for ( var key in flat ) { var value = flat [ key ] ; var keys = key . split ( "." ) ; var temp = normalize ; for ( var i = 0 , n = keys . length ; i < n ; i ++ ) { if ( ! temp [ keys [ i ] ] ) { if ( i < n - 1 ) { temp [ keys [ i ] ] = { } ; } else { temp [ keys [ i ] ] = value ; } } temp = temp [ keys [ i ] ] ; } } return JSON . stringify ( normalize , null , 4 ) ; } ( flatJsonObj ) ) ; return jsonText . split ( '\r\n' ) ; } ; }
JSON file formatter
JSON file formatter