Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluralize localizable strings #4964

Closed
wants to merge 1 commit into from
Closed

Pluralize localizable strings #4964

wants to merge 1 commit into from

Conversation

1ec5
Copy link
Collaborator

@1ec5 1ec5 commented Apr 4, 2018

UI strings that include counts now use the appropriate plural form in English and (once translations are updated) in other languages. When looking up a translation and one of the tokens is numeric, look one level deeper in the translation file for the CLDR plural form corresponding to the numeric token.

singular plural

In order to support this feature for all the languages that iD supports, with all their varying pluralization rules, this change introduces dependencies on:

  • cldr-core, which supplies plural rules for a number of languages (part of cldr-data)
  • CLDRPluralRuleParser, which parses a plural rule, determining whether it matches the given number (used by MediaWiki)

This works locally using npm start, but I’d like someone to double-check that I’m including these dependencies correctly. (All we need is a single JSON file from cldr-core, not the entire package.)

Keying off numbers in token replacements means any number formatting that occurs before calling t() will defeat the pluralization logic therein. Unlike the unit formatting that occurs in t()’s callers (as of #4672), number formatting needs to happen inside t().

More to come:

  • Depend on cldr-core and CLDRPluralRuleParser
  • Look up pluralized translations in t()
  • Pluralize some strings in core.yaml
  • Move number formatting into t()
  • Combine manually pluralized strings like restriction.controls.via_up_to_one/restriction.controls.via_up_to_two
  • Break up validations.many_deletions into strings with one pluralized word each
  • Mention plural format in contributing documentation
  • Update changelog

Fixes #597.

@1ec5 1ec5 added the localization Adapting iD across languages, regions, and cultures label Apr 4, 2018
@1ec5 1ec5 self-assigned this Apr 4, 2018
@1ec5 1ec5 requested a review from bhousel April 4, 2018 10:32
@1ec5 1ec5 mentioned this pull request Apr 4, 2018
@bhousel
Copy link
Member

bhousel commented Apr 25, 2018

This works locally using npm start, but I’d like someone to double-check that I’m including these dependencies correctly. (All we need is a single JSON file from cldr-core, not the entire package.)

Looks great! Rollup will include only the single JSON file 👍

Keying off numbers in token replacements means any number formatting that occurs before calling t() will defeat the pluralization logic therein. Unlike the unit formatting that occurs in t()’s callers (as of #4672), number formatting needs to happen inside t().

Ok, that makes sense. I don't know how often in the code we pass stringified numbers to t() but it is probably not too much work to change these.

@1ec5 1ec5 force-pushed the 1ec5-plural-597 branch from 01ddebe to dbf93ba Compare April 27, 2018 05:31
Introduced dependencies on cldr-core and CLDRPluralRuleParser, which supply the plural rules and plural rule parsing, respectively. When looking up a translation and one of the tokens is numeric, look one level deeper in the translation file for plural forms.

Fixes #597.
@1ec5 1ec5 force-pushed the 1ec5-plural-597 branch from dbf93ba to 26efb6e Compare April 27, 2018 05:33
@magol
Copy link

magol commented Jul 24, 2018

Any work on this PR?

@1ec5
Copy link
Collaborator Author

1ec5 commented Aug 3, 2018

Sorry, I don’t know when I’ll get a chance to get back to this PR, but it’s certainly something I’d like to get in eventually. (At some point, browser support for Intl.PluralRules would improve enough that we could radically simplify this PR.)

@quincylvania
Copy link
Collaborator

To be clear, this was closed automatically when I renamed the master branch, but it was two years old.

I'd like to spend some time soon to get pluralization right as we work on expanding iD's global usability (see #7713).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
localization Adapting iD across languages, regions, and cultures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants