Skip to content

Commit

Permalink
Filter values from nested results if interpolation is undefined.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeAndWeb committed Dec 18, 2024
1 parent ee99d12 commit d31e18b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions projects/ngx-translate/src/lib/translate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}};
Expand Down
6 changes: 5 additions & 1 deletion projects/ngx-translate/src/lib/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d31e18b

Please sign in to comment.