Add CLI option to enable alphabetical sorting of extracted keys
This commit is contained in:
committed by
Kim Biesbjerg
parent
94e6416c76
commit
c18b7dc9c7
@@ -75,4 +75,17 @@ export class TranslationCollection {
|
||||
return Object.keys(this.values).length === 0;
|
||||
}
|
||||
|
||||
public sort(compareFn?: (a: string, b: string) => number): TranslationCollection {
|
||||
if (!compareFn) {
|
||||
// if no compare functions is provided use a case insensitive sorting function
|
||||
compareFn = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
}
|
||||
|
||||
let collection = new TranslationCollection();
|
||||
let sortedKeys = this.keys().sort(compareFn);
|
||||
sortedKeys.forEach((key) => {
|
||||
collection = collection.add(key, this.get(key));
|
||||
});
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user