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

Better i18n plural support #597

Closed
jfirebaugh opened this issue Feb 1, 2013 · 8 comments · Fixed by #7991
Closed

Better i18n plural support #597

jfirebaugh opened this issue Feb 1, 2013 · 8 comments · Fixed by #7991
Assignees
Labels
localization Adapting iD across languages, regions, and cultures
Milestone

Comments

@jfirebaugh
Copy link
Member

Multiselect produces translations like "Deleted {n} objects", which we're currently translating without real plural form support.

@jfirebaugh
Copy link
Member Author

Doesn't seem to be critical.

@althio
Copy link
Contributor

althio commented Jan 29, 2018

I would like to see this re-assessed, and maybe flagged "help wanted" from someone fluent in internationalization stuff.

@bhousel
Copy link
Member

bhousel commented Jan 29, 2018

Sure @althio we can reopen and ask for help. I agree that it's not critical, but if somebody wants to work on it, I'd accept a PR for it.

In some places we support pluralization just by having multiple translation strings:

iD/data/core.yaml

Lines 80 to 103 in c8e89b7

delete:
title: Delete
description:
single: Delete this feature permanently.
multiple: Delete these features permanently.
annotation:
point: Deleted a point.
vertex: Deleted a node from a way.
line: Deleted a line.
area: Deleted an area.
relation: Deleted a relation.
multiple: "Deleted {n} features."
too_large:
single: This feature can't be deleted because not enough of it is currently visible.
multiple: These features can't be deleted because not enough of them are currently visible.
incomplete_relation:
single: This feature can't be deleted because it hasn't been fully downloaded.
multiple: These features can't be deleted because they haven't been fully downloaded.
part_of_relation:
single: This feature can't be deleted because it is part of a larger relation. You must remove it from the relation first.
multiple: These features can't be deleted because they are part of larger relations. You must remove them from the relations first.
connected_to_hidden:
single: This feature can't be deleted because it is connected to a hidden feature.
multiple: These features can't be deleted because some are connected to hidden features.

@bhousel bhousel reopened this Jan 29, 2018
@bhousel bhousel added localization Adapting iD across languages, regions, and cultures help wanted For intermediate contributors, requires investigation or knowledge of iD code labels Jan 29, 2018
@bhousel bhousel changed the title need i18n plural support Better i18n plural support Jan 29, 2018
@althio
Copy link
Contributor

althio commented Jan 29, 2018

Thanks @bhousel

In some places we support pluralization just by having multiple translation strings:

There are shortcomings with this simple approach and maybe a systematic approach would be better (but more complex).
From what I read, plural rules are different depending on languages and lots of work and thoughts already on the subject.
https://stackoverflow.com/questions/14326653/java-internationalization-i18n-with-proper-plurals#14327683
http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html

@bhousel
Copy link
Member

bhousel commented Jan 29, 2018

There are shortcomings with this simple approach and maybe a systematic approach would be better (but more complex).

Thats fine, but I'd strongly prefer "simple" over "perfect".. If we need to redo all of our translations and the code to produce them to get to "perfect", lets not do that.

@1ec5
Copy link
Collaborator

1ec5 commented Feb 2, 2018

Some of the supported languages pluralize according to more complex rules that couldn’t be accommodated by adding a few extra strings for translation. For example, some languages have a different plural form for numbers ending in 1. I think it would be a reasonable goal to support each of iD’s languages as a first-class citizen, but doing so by adding strings would unnecessarily increase the workload for all translators. For example, a Spanish translator shouldn’t have to translate redundant strings because Russian has a dual form.

The good news is that Transifex supports alternatives to the YAML format that explicitly handle pluralization. (I’m familiar with .stringsdict from iOS development, but there are others.) We could supplement the existing YAML file with another file containing a few override strings for which pluralization matters. For languages like Chinese that have no plural forms, there would only be one set of strings to translate. Back here in this repository, iD could depend on one of several libraries that support the CLDR plural format.

@1ec5
Copy link
Collaborator

1ec5 commented Apr 4, 2018

The good news is that Transifex supports alternatives to the YAML format that explicitly handle pluralization.

Turns out Transifex supports plurals in YAML as well, as subkeys of what would normally be a single string. To enable Transifex pluralization for a particular message, we need to turn something like:

changes: "{count} Changes"

into:

    changes:
      one: "1 Change"
      other: "%{count} Changes"

That’ll cause Transifex to display a tabbed interface for this message. Some languages will see a different set of tabs than the one and other defined in the YAML file; it all depends on the language’s definition in CLDR.

To use the pluralized translations, we’d need a library such as the Plural module of globalize.js – there are several alternatives – to determine which rule (one, few, many, etc.) to use for count, then modify t() to look one level deeper:

var rep = translations[loc];

Someday we’ll be able to use Intl.PluralRules, but that API is very new.

It’s unclear to me how or whether this Rails-style YAML format supports pluralizing multiple placeholders within a single message, as gettext and stringsdict can. This is the only message that currently contains multiple pluralized words:

many_deletions: "You're deleting {n} features: {p} nodes, {l} lines, {a} areas, {r} relations. Are you sure you want to do this? This will delete them from the map that everyone else sees on openstreetmap.org."

I think we could break it up into multiple messages as a workaround.

@1ec5 1ec5 self-assigned this Apr 4, 2018
@1ec5 1ec5 removed the help wanted For intermediate contributors, requires investigation or knowledge of iD code label Apr 4, 2018
1ec5 added a commit that referenced this issue Apr 4, 2018
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 mentioned this issue Apr 4, 2018
8 tasks
@1ec5
Copy link
Collaborator

1ec5 commented Apr 4, 2018

#4964 implements this enhancement.

1ec5 added a commit that referenced this issue Apr 27, 2018
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 added a commit that referenced this issue Apr 27, 2018
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.
@quincylvania quincylvania added this to the 2.19.0 milestone Sep 14, 2020
@quincylvania quincylvania assigned quincylvania and unassigned 1ec5 Sep 14, 2020
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 a pull request may close this issue.

5 participants