@biesbjerg/ng2-translate-extract
Advanced tools
Comparing version 0.3.5 to 0.4.0
@@ -16,2 +16,3 @@ "use strict"; | ||
replace: ['r', 'Replace the contents of output file if it exists (Merges by default)', 'boolean', false], | ||
sort: ['s', 'Sort translations in the output file in alphabetical order', 'boolean', false], | ||
clean: ['c', 'Remove obsolete strings when merging', 'boolean', false] | ||
@@ -33,2 +34,6 @@ }); | ||
}); | ||
var compiler = new json_compiler_1.JsonCompiler(); | ||
if (options.format === 'pot') { | ||
compiler = new po_compiler_1.PoCompiler(); | ||
} | ||
var parsers = [ | ||
@@ -50,6 +55,2 @@ new pipe_parser_1.PipeParser(), | ||
var collection = extracted; | ||
var compiler = new json_compiler_1.JsonCompiler(); | ||
if (options.format === 'pot') { | ||
compiler = new po_compiler_1.PoCompiler(); | ||
} | ||
if (!options.replace && fs.existsSync(outputPath)) { | ||
@@ -70,2 +71,5 @@ var existing = compiler.parse(fs.readFileSync(outputPath, 'utf-8')); | ||
} | ||
if (options.sort) { | ||
collection = collection.sort(); | ||
} | ||
fs.writeFileSync(outputPath, compiler.compile(collection)); | ||
@@ -72,0 +76,0 @@ cli.ok("* Saved to '" + outputPath + "'"); |
@@ -19,2 +19,3 @@ export interface TranslationType { | ||
isEmpty(): boolean; | ||
sort(compareFn?: (a: string, b: string) => number): TranslationCollection; | ||
} |
@@ -65,2 +65,14 @@ "use strict"; | ||
}; | ||
TranslationCollection.prototype.sort = function (compareFn) { | ||
var _this = this; | ||
if (!compareFn) { | ||
compareFn = function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }; | ||
} | ||
var collection = new TranslationCollection(); | ||
var sortedKeys = this.keys().sort(compareFn); | ||
sortedKeys.forEach(function (key) { | ||
collection = collection.add(key, _this.get(key)); | ||
}); | ||
return collection; | ||
}; | ||
return TranslationCollection; | ||
@@ -67,0 +79,0 @@ }()); |
{ | ||
"name": "@biesbjerg/ng2-translate-extract", | ||
"version": "0.3.5", | ||
"version": "0.4.0", | ||
"description": "Extract strings from projects using ng2-translate", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -28,8 +28,10 @@ # ng2-translate-extract | ||
-o, --output [DIR] Directory path you would like to save extracted | ||
strings (Default is current directory) | ||
strings (Default is current directory/template.json) | ||
-f, --format [VALUE] Output format. VALUE must be either [json|pot] (Default is json) | ||
-r, --replace BOOLEAN Replace the contents of output file if it exists | ||
(Merges by default) | ||
-s, --sort BOOLEAN Sort translations in the output file in alphabetical | ||
order | ||
-c, --clean BOOLEAN Remove obsolete strings when merging | ||
-h, --help Display help and usage details | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
38464
493
37