Skip to content

Commit d31e18b

Browse files
committed
Filter values from nested results if interpolation is undefined.
1 parent ee99d12 commit d31e18b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

projects/ngx-translate/src/lib/translate.service.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,22 @@ describe("TranslateService", () =>
664664
expect(translate.instant("a.b")).toEqual(["X", "Y"]);
665665
});
666666

667+
it("ignores null values in nested results", () =>
668+
{
669+
const tr = {a: {aa: "test", bb: null}};
670+
translate.setTranslation("en", tr);
671+
translate.use("en");
672+
expect(translate.instant("a")).toEqual({aa: "test"});
673+
});
674+
675+
it("returns key when asking for null value directly", () =>
676+
{
677+
const tr = {a: {aa: "test", bb: null}};
678+
translate.setTranslation("en", tr);
679+
translate.use("en");
680+
expect(translate.instant("a.bb")).toEqual("a.bb");
681+
});
682+
667683
it("should interpolate in arrays", () =>
668684
{
669685
const tr = {a: {b: ["{{value}} 1", "{{value}} 2"]}};

projects/ngx-translate/src/lib/translate.service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ export class TranslateService {
430430
{
431431
const result: TranslationObject = {};
432432
for (const key in translations) {
433-
result[key] = this.runInterpolation(translations[key], interpolateParams);
433+
let res = this.runInterpolation(translations[key], interpolateParams);
434+
if(res !== undefined)
435+
{
436+
result[key] = res;
437+
}
434438
}
435439
return result;
436440
}

0 commit comments

Comments
 (0)