Skip to content

Translation errors when parser returns null #970

@aleksandar-kandzhichki

Description

@aleksandar-kandzhichki

I'm submitting a ... (check one with "x")


[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior
When we provide custom TranslateParser, the translation get function errors if our parser returns null.

image

I have traced this down to this line of code:

return typeof res !== "undefined" ? res : key;

Here, if we get null, since typeof null == "object" we return res - which is null, and then in

if (typeof res.subscribe === "function") {

we get null.subscribe which produces the error
So maybe it could be compared with null too

Expected/desired behavior
Probably the translator should treat it same as undefined - return the key

Reproduction of the problem
create translation with some key and value null e.g.
{
"mytranslation": null
}
and use parser that simply returns the value of "mytranslation"

What is the motivation / use case for changing the behavior?
better quality

Please tell us about your environment:

  • @ngx-translate/core: "^10.0.2",
  • @angular/core: "^6.0.3",
  • browser: all
  • language: typescript es6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions