core icon indicating copy to clipboard operation
core copied to clipboard

Translation interpolated twice, with and without [translateParams]

Open ghost opened this issue 7 years ago • 3 comments

I'm submitting a ...

[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 With directive's translations <any translate="SOME_KEY" [translateParams]="someModel"></any> and with custom interpolation, TranslateMessageFormat for instance, the value interpolation is called twice: firstly without parameters (translate directive) and secondly with parameters (translateParams directive).

The problem is relative to the first call, without parameters. It fails every time a translation contains a param. The inherent cause comes from lambda functions generated by the custom interpolation compiler that do not support null or empty params...

Expected/desired behavior ... But, I think (but not sure) a better behavior should be restricting translation to only one call (with params) instead of two (one without then one with params).

Reproduction of the problem

  1. use an interpolation compiler that generate lamba functions expecting interpolation params (without handling null or missing params)

  2. translate using directives translate and translateParams

  3. it should throw an exception

What is the expected behavior? I should translate 😀

What is the motivation / use case for changing the behavior? Three obvious solutions are possible : (i) make the external compiler compliant with missing interpolation params, (ii) try-catch interpolation on run-time or (iii) call only once the interpolation (with params).

I'm not in favor of (i) and (ii) solutions mainly to avoid side effects with "regular" exceptions (i.e. the developer doesn't provide the right object as parameter, ...).

Please tell us about your environment:

  • ngx-translate version: 9.1.1

  • ngx-translate-messageformat-compiler version: 3.0.0 (but not so important here)

  • Angular version: 5.2.6

  • Browser: all

ghost avatar Feb 27 '18 14:02 ghost

Seems to be similar to #806

CodeAndWeb avatar Mar 27 '18 16:03 CodeAndWeb

True, excepts that, here, it's not about the TranslateMessageFormat limitness, but it's about the first call made by the translate directive with partial data.

ghost avatar Mar 27 '18 16:03 ghost

May be related to https://github.com/lephyrus/ngx-translate-messageformat-compiler/issues/35

dmitry-dedukhin avatar Jul 26 '19 05:07 dmitry-dedukhin