guillaumepotier / gettext.js

gettext.js is a lightweight yet complete and accurate GNU gettext port for node and the browser.
http://guillaumepotier.github.io/gettext.js
150 stars 48 forks source link

don't pass the count as the first argument to strfmt #66

Closed nornagon closed 2 years ago

nornagon commented 2 years ago

This messes up the indices for strings which don't expect the number to be the first index.

e.g.

i18n.dcnpgettext(
  null,
  "requirement",
  "%1 (%2 charge)",
  "%1 (%2 charges)",
  tool.count,
  tool.name,
  tool.count
)

n should be used to determine the plural form, but not also take the first argument slot.

guillaumepotier commented 2 years ago

Hi @nornagon,

Thanks for this issue! This one is pretty tricky though...

I fear to understand now that I falsely assumed that the count discriminator would also be a good replacement for %1 in the strings.

You mean that:

i18n.ngettext('There is %1 apple', 'There are %1 apples', 1); should return (in EN_US) "There is %1 apple", while

i18n.ngettext('There is %1 apple', 'There are %1 apples', 1, 1); should return (in EN_US) "There is 1 apple"

If so, it would be a huge BC break for gettext.js :(

I'll double check the GNU implementation before considering this important change, and then update the test suite and the major version bump.

Best

nornagon commented 2 years ago

Yep, you've understood the situation as I do. I checked the GNU implementation too and found that gettext.js's behavior is different.