diff --git a/projects/ngx-translate/src/lib/translate.service.spec.ts b/projects/ngx-translate/src/lib/translate.service.spec.ts index 808e481..50e6c3e 100644 --- a/projects/ngx-translate/src/lib/translate.service.spec.ts +++ b/projects/ngx-translate/src/lib/translate.service.spec.ts @@ -664,6 +664,22 @@ describe("TranslateService", () => expect(translate.instant("a.b")).toEqual(["X", "Y"]); }); + it("ignores null values in nested results", () => + { + const tr = {a: {aa: "test", bb: null}}; + translate.setTranslation("en", tr); + translate.use("en"); + expect(translate.instant("a")).toEqual({aa: "test"}); + }); + + it("returns key when asking for null value directly", () => + { + const tr = {a: {aa: "test", bb: null}}; + translate.setTranslation("en", tr); + translate.use("en"); + expect(translate.instant("a.bb")).toEqual("a.bb"); + }); + it("should interpolate in arrays", () => { const tr = {a: {b: ["{{value}} 1", "{{value}} 2"]}}; diff --git a/projects/ngx-translate/src/lib/translate.service.ts b/projects/ngx-translate/src/lib/translate.service.ts index e08a276..4930fed 100644 --- a/projects/ngx-translate/src/lib/translate.service.ts +++ b/projects/ngx-translate/src/lib/translate.service.ts @@ -430,7 +430,11 @@ export class TranslateService { { const result: TranslationObject = {}; for (const key in translations) { - result[key] = this.runInterpolation(translations[key], interpolateParams); + let res = this.runInterpolation(translations[key], interpolateParams); + if(res !== undefined) + { + result[key] = res; + } } return result; }