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

Support language-specific pluralization #7991

Merged
merged 1 commit into from
Sep 15, 2020
Merged

Conversation

quincylvania
Copy link
Collaborator

Closes #597.

This is essentially a reimplementation of #4964 (shout-out to @1ec5!), but for the current codebase.

We can also use the built-in Intl.PluralRules function instead of an external dependency, since it's now supported in all major browsers. iD will attempt to fallback gracefully on legacy browsers.

@quincylvania quincylvania added the localization Adapting iD across languages, regions, and cultures label Sep 14, 2020
Copy link
Collaborator

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like iD uses Ruby-style YAML, so Transifex should recognize the one and other subkeys as plural rules. 👍

for (let k in replacements) {
const token = `{${k}}`;
const regex = new RegExp(token, 'g');
result = result.replace(regex, replacements[k]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good place to apply some number formatting both for grouping characters (really big changesets!) and non-European numerals (for languages like Arabic and Hindi).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is why I left strings like {n} result for {search} instead of 1 result for {search}. I think I'll add formatting separately though.

@quincylvania
Copy link
Collaborator Author

Looks like iD uses Ruby-style YAML, so Transifex should recognize the one and other subkeys as plural rules. 👍

@1ec5 Yep, I made the changes with that documentation in mind. I'll debug if Transifex doesn't pick it up for some reason.

@quincylvania quincylvania added this to the 2.19.0 milestone Sep 15, 2020
@quincylvania quincylvania merged commit ced7404 into develop Sep 15, 2020
@quincylvania quincylvania deleted the translatable-plurals branch September 15, 2020 14:33
@quincylvania
Copy link
Collaborator Author

Looks like Transifex is reacting as expected!

Screen Shot 2020-09-15 at 11 08 12 AM

@quincylvania
Copy link
Collaborator Author

@1ec5 Do you know if we need to enable plural forms for strings like this that are based on an amount but don't include the amount?

      too_bendy:
        single: This can't be straightened because it bends too much.
        multiple: These can't be straightened because they bend too much.

@maro-21
Copy link

maro-21 commented Sep 15, 2020

Do you know if we need to enable plural forms for strings like this that are based on an amount but don't include the amount?

      too_bendy:
        single: This can't be straightened because it bends too much.
        multiple: These can't be straightened because they bend too much.

It's not necessary when there is no numeral.

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.

Better i18n plural support
3 participants