question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support proper i18n pluralization

See original GitHub issue

We should use __n for numeric messages to support unlimited, language-specific messages.

More: https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kauffjcommented, Jun 12, 2020

@seanyesmunt please read/follow this thread

0reactions
marko-lorentzcommented, Jun 13, 2020

I will try to answer the questions raised by @kauffj:

  • yes - using an ICU-based translation model means that you also need to add a dedicated “English translation” as the plural forms vanish from the code
    • Transifex proposes to upload the developer strings as language “en” to the system and have (developers or) translators create a translation for language “en_US” which will then be used by the production system (see explanation here)
    • the translators are able to view both (the “en” and the “en_US” strings) to derive the correct translation by switching the Transifex translation view to “show a second source language”
    • the strings that will remain in the source code should be the those with the most abstract plural like “I have %n% cars” in order to show the intention of the author (this form is called other in the ICU model)
  • the content of the translation file will look different, similar to this simple example:
{
  "You have %count% files": "{count, plural, one {You have {count} file.} other {You have {count} files.}}"
}
  • the translators will ideally not be in touch with this special format as Transifex should ask them to enter the one form and the other form separately if the target language requires these 2 forms (this will need a try I think - never trust the docu of a tool) (the Transifex docu also doesn’t mention how the zero form is supported and it would really be a mess if it is not, as you need “You don’t have a car.” instead of “You have 0 cars.”)
  • in the source code, representation is depending on the library you use and how you wrap it; raw example for “Format JS/Intl MessageFormat” lib without wrapper:
const enNumPhotos = new IntlMessageFormat(
    `
    {count, plural, one {You have {count} file.} other {You have {count} files.}}
    `,
    'en-US'
  );
  return enNumPhotos.format({count: 1000});

I’m not a JS developer at all (I usually do Java backend stuff) but I’m sure this can be wrapped with a generic vararg function or fancy other stuff. Whether it is __n(...) or whatever might be a decision to make after reading through the docu of the lib - as depending on lib, there might be some more to discover, like e.g. nested replacements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plurals - i18next documentation
How to find the correct plural suffix? ... You can use this small utility to get the correct plural suffixes. ... Or try...
Read more >
Pluralization | Vue I18n
You don't need to explicitly give the number for pluralization. The number can be accessed within locale messages via pre-defined named ...
Read more >
Let's Talk About Internationalization of Plurals - Nelio Software
Remember that i18n is a two-step process: (a) select the appropriate sentence and (b) replace all placeholders with the actual values. If a ......
Read more >
Java internationalization (i18n) with proper plurals
No, I don't know ICU and gettext, I only read that they have better support for plural forms. I also wonder how they...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The I18n gem provides a Pluralization backend that can be used to enable locale-specific rules. Include it to the Simple backend, then add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found