Fix sorting. Closes #16

This commit is contained in:
Kim Biesbjerg
2017-03-07 15:45:50 +01:00
parent d51674950c
commit f590b9bb9e

View File

@@ -77,15 +77,14 @@ export class TranslationCollection {
public sort(compareFn?: (a: string, b: string) => number): TranslationCollection { public sort(compareFn?: (a: string, b: string) => number): TranslationCollection {
if (!compareFn) { if (!compareFn) {
// if no compare functions is provided use a case insensitive sorting function // If no compare function is provided use a case insensitive sorting function
compareFn = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase()); compareFn = (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase());
} }
let values: TranslationType = {};
let collection = new TranslationCollection(); this.keys().sort(compareFn).forEach((key) => {
let sortedKeys = this.keys().sort(compareFn); values[key] = this.get(key);
sortedKeys.forEach((key) => {
collection = collection.add(key, this.get(key));
}); });
return collection;
return new TranslationCollection(values);
} }
} }