Skip to content

Commit

Permalink
feat(TranslateService): support merging non-valid JSON object notations
Browse files Browse the repository at this point in the history
Fixes #764
  • Loading branch information
hanyu-natsu authored and ocombe committed Jan 15, 2018
1 parent 45f1f6e commit 6f7296f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export function isObject(item: any): boolean {
}

export function mergeDeep(target: any, source: any): any {
target = JSON.parse(JSON.stringify(target));
source = JSON.parse(JSON.stringify(source));
let output = Object.assign({}, target);
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach((key: any) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/translate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ describe('TranslateService', () => {
});
});

it("should merge non-valid JSON translations if option shouldMerge is true", () => {
translations = {};
translate.setTranslation('en', { "TEST": { "sub1": () => "value1" } }, true);
translate.setTranslation('en', { "TEST": { "sub2": () => "value2" } }, true);
translate.use('en');

translate.get('TEST.sub1').subscribe((res: string) => {
expect(res).toEqual('value1');
});
translate.get('TEST.sub2').subscribe((res: string) => {
expect(res).toEqual('value2');
});
});

it("shouldn't call the current loader if you set the translation yourself", (done: Function) => {
translations = {};
translate.setTranslation('en', {"TEST": "This is a test"});
Expand Down

0 comments on commit 6f7296f

Please sign in to comment.