Fix ngettext and variants with different interpolated variables in strings.

Review Request #11023 — Created May 15, 2020 and submitted

Information

babel-plugin-django-gettext
master

Reviewers

When using ngettext (and its variants), the generated code would be
wrong if both strings ended up using its own interpolated arguments. For
instance, this code:

N_(`This is ${var1}`,
   `This is ${var2}`,
   2)

... would end up generating the right strings, but the wrong arguments
to pass in. The way we were building up the merged list of variables was
wrong.

This change fixes this by introducing a new merging function for these
lists of variables, which goes through the lists and builds a merged,
deduplicated list of variables that can be passed in.

The unit test coverage has been expanded to include unique variables in
the ngettext-related tests that involve interpolation, and to test
both singular and plural variants in all tests.

Unit tests pass.

Verified this fixed a bug I encountered when testing /r/11022.

Summary ID
Fix ngettext and variants with different interpolated variables in strings.
When using `ngettext` (and its variants), the generated code would be wrong if both strings ended up using its own interpolated arguments. For instance, this code: ```javascript N_(`This is ${var1}`, `This is ${var2}`, 2) ``` ... would end up generating the right strings, but the wrong arguments to pass in. The way we were building up the merged list of variables was wrong. This change fixes this by introducing a new merging function for these lists of variables, which goes through the lists and builds a merged, deduplicated list of variables that can be passed in. The unit test coverage has been expanded to include unique variables in the `ngettext`-related tests that involve interpolation, and to test both singular and plural variants in all tests.
13871b84bcdc0186a08959f3857a84f05c1a0813
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...