Skip to content

Commit

Permalink
Pluralize localizable strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1ec5 committed Apr 27, 2018
1 parent 22cedfb commit 26efb6e
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 44 deletions.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ to iD, only display them in the interface through the `t()` function.
Then, add the new string to `data/core.yaml`. The translation system, Transifex,
will automatically detect the change.

If you need to insert something into the string programmatically, insert a
`{token}` into the string in the YAML file. If the token is a number that can
affect how surrounding words are pluralized, define the singular and plural
forms separately like this:

```yaml
changes:
one: "1 Change"
other: "{count} Changes"
```
If you are updating an existing string, update it in `data/core/yaml` and run
`npm run build` to generate the `en.json` file automatically, then commit both
modified files.
Expand Down
48 changes: 36 additions & 12 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ en:
line: Deleted a line.
area: Deleted an area.
relation: Deleted a relation.
multiple: "Deleted {n} features."
multiple:
one: "Deleted a feature."
other: "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.
Expand Down Expand Up @@ -129,7 +131,9 @@ en:
title: Merge
description: Merge these features.
key: C
annotation: "Merged {n} features."
annotation:
one: "Merged a feature."
other: "Merged {n} features."
not_eligible: These features can't be merged.
not_adjacent: These features can't be merged because their endpoints aren't connected.
restriction: "These features can't be merged because it would damage a \"{relation}\" relation."
Expand Down Expand Up @@ -221,7 +225,9 @@ en:
annotation:
line: Split a line.
area: Split an area boundary.
multiple: "Split {n} lines/area boundaries."
multiple:
one: "Split a line/area boundary."
other: "Split {n} lines/area boundaries."
not_eligible: Lines can't be split at their beginning or end.
multiple_ways: There are too many lines here to split.
connected_to_hidden: This can't be split because it is connected to a hidden feature.
Expand Down Expand Up @@ -281,8 +287,12 @@ en:
report_a_bug: Report a bug
help_translate: Help translate
feature_info:
hidden_warning: "{count} hidden features"
hidden_details: "These features are currently hidden: {details}"
hidden_warning:
one: "1 hidden feature"
other: "{count} hidden features"
hidden_details:
one: "This feature is currently hidden: {details}"
other: "These features are currently hidden: {details}"
status:
error: Unable to connect to API.
offline: The API is offline. Please try editing later.
Expand All @@ -295,7 +305,9 @@ en:
request_review: "I would like someone to review my edits."
save: Upload
cancel: Cancel
changes: "{count} Changes"
changes:
one: "1 Change"
other: "{count} Changes"
download_changes: Download osmChange file
warnings: Warnings
modified: Modified
Expand All @@ -307,7 +319,9 @@ en:
google_warning_link: https://www.openstreetmap.org/copyright
contributors:
list: "Edits by {users}"
truncated_list: "Edits by {users} and {count} others"
truncated_list:
one: "Edits by {users} and someone else"
other: "Edits by {users} and {count} others"
info_panels:
key: I
background:
Expand All @@ -327,7 +341,9 @@ en:
history:
key: H
title: History
selected: "{n} selected"
selected:
one: "1 selected"
other: "{n} selected"
no_history: "No History (New Feature)"
version: Version
last_edit: Last Edit
Expand All @@ -342,7 +358,9 @@ en:
measurement:
key: M
title: Measurement
selected: "{n} selected"
selected:
one: "1 selected"
other: "{n} selected"
geometry: Geometry
closed_line: closed line
closed_area: closed area
Expand Down Expand Up @@ -381,7 +399,9 @@ en:
new_relation: New relation...
role: Role
choose: Select feature type
results: "{n} results for {search}"
results:
one: "1 result for {search}"
other: "{n} results for {search}"
reference: View on OpenStreetMap Wiki
back_tooltip: Change feature
remove: Remove
Expand Down Expand Up @@ -578,7 +598,9 @@ en:
untagged_relation_tooltip: "Select a feature type that describes what this relation is."
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."
tag_suggests_area: "The tag {tag} suggests line should be area, but it is not an area"
deprecated_tags: "Deprecated tags: {tags}"
deprecated_tags:
one: "Deprecated tag: {tags}"
other: "Deprecated tags: {tags}"
zoom:
in: Zoom in
out: Zoom out
Expand Down Expand Up @@ -920,7 +942,9 @@ en:
words: "This walkthrough will introduce some new words and concepts. When we introduce a new word, we'll use *italics*."
mouse: "You can use any input device to edit the map, but this walkthrough assumes you have a mouse with left and right buttons. **If you want to attach a mouse, do so now, then click OK.**"
leftclick: "When this tutorial asks you to click or double-click, we mean with the left button. On a trackpad it might be a single-click or single-finger tap. **Left-click {num} times.**"
rightclick: "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click {num} times.**"
rightclick:
one: "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click once.**"
other: "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click {num} times.**"
chapters: "So far, so good! You can use the buttons below to skip chapters at any time or to restart a chapter if you get stuck. Let's begin! **Click '{next}' to continue.**"
navigation:
title: "Navigation"
Expand Down
1 change: 1 addition & 0 deletions data/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { wikipedia as dataWikipedia } from 'wmf-sitematrix';
export { default as dataSuggestions } from 'name-suggestion-index/name-suggestions.json';
export { default as plurals } from 'cldr-core/supplemental/plurals.json';

export { dataAddressFormats } from './address-formats.json';
export { dataDeprecated } from './deprecated.json';
Expand Down
89 changes: 57 additions & 32 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@
"line": "Deleted a line.",
"area": "Deleted an area.",
"relation": "Deleted a relation.",
"multiple": "Deleted {n} features."
"multiple": {
"one": "Deleted a feature.",
"other": "Deleted {n} features."
}
},
"too_large": {
"single": "This feature can't be deleted because not enough of it is currently visible.",
Expand Down Expand Up @@ -167,7 +170,10 @@
"title": "Merge",
"description": "Merge these features.",
"key": "C",
"annotation": "Merged {n} features.",
"annotation": {
"one": "Merged a feature.",
"other": "Merged {n} features."
},
"not_eligible": "These features can't be merged.",
"not_adjacent": "These features can't be merged because their endpoints aren't connected.",
"restriction": "These features can't be merged because it would damage a \"{relation}\" relation.",
Expand Down Expand Up @@ -286,7 +292,10 @@
"annotation": {
"line": "Split a line.",
"area": "Split an area boundary.",
"multiple": "Split {n} lines/area boundaries."
"multiple": {
"one": "Split a line/area boundary.",
"other": "Split {n} lines/area boundaries."
}
},
"not_eligible": "Lines can't be split at their beginning or end.",
"multiple_ways": "There are too many lines here to split.",
Expand Down Expand Up @@ -358,8 +367,14 @@
"report_a_bug": "Report a bug",
"help_translate": "Help translate",
"feature_info": {
"hidden_warning": "{count} hidden features",
"hidden_details": "These features are currently hidden: {details}"
"hidden_warning": {
"one": "1 hidden feature",
"other": "{count} hidden features"
},
"hidden_details": {
"one": "This feature is currently hidden: {details}",
"other": "These features are currently hidden: {details}"
}
},
"status": {
"error": "Unable to connect to API.",
Expand All @@ -374,7 +389,10 @@
"request_review": "I would like someone to review my edits.",
"save": "Upload",
"cancel": "Cancel",
"changes": "{count} Changes",
"changes": {
"one": "1 Change",
"other": "{count} Changes"
},
"download_changes": "Download osmChange file",
"warnings": "Warnings",
"modified": "Modified",
Expand All @@ -387,7 +405,10 @@
},
"contributors": {
"list": "Edits by {users}",
"truncated_list": "Edits by {users} and {count} others"
"truncated_list": {
"one": "Edits by {users} and someone else",
"other": "Edits by {users} and {count} others"
}
},
"info_panels": {
"key": "I",
Expand All @@ -409,7 +430,10 @@
"history": {
"key": "H",
"title": "History",
"selected": "{n} selected",
"selected": {
"one": "1 selected",
"other": "{n} selected"
},
"no_history": "No History (New Feature)",
"version": "Version",
"last_edit": "Last Edit",
Expand All @@ -426,7 +450,10 @@
"measurement": {
"key": "M",
"title": "Measurement",
"selected": "{n} selected",
"selected": {
"one": "1 selected",
"other": "{n} selected"
},
"geometry": "Geometry",
"closed_line": "closed line",
"closed_area": "closed area",
Expand Down Expand Up @@ -470,7 +497,10 @@
"new_relation": "New relation...",
"role": "Role",
"choose": "Select feature type",
"results": "{n} results for {search}",
"results": {
"one": "1 result for {search}",
"other": "{n} results for {search}"
},
"reference": "View on OpenStreetMap Wiki",
"back_tooltip": "Change feature",
"remove": "Remove",
Expand Down Expand Up @@ -701,7 +731,10 @@
"untagged_relation_tooltip": "Select a feature type that describes what this relation is.",
"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.",
"tag_suggests_area": "The tag {tag} suggests line should be area, but it is not an area",
"deprecated_tags": "Deprecated tags: {tags}"
"deprecated_tags": {
"one": "Deprecated tag: {tags}",
"other": "Deprecated tags: {tags}"
}
},
"zoom": {
"in": "Zoom in",
Expand Down Expand Up @@ -1071,7 +1104,10 @@
"words": "This walkthrough will introduce some new words and concepts. When we introduce a new word, we'll use *italics*.",
"mouse": "You can use any input device to edit the map, but this walkthrough assumes you have a mouse with left and right buttons. **If you want to attach a mouse, do so now, then click OK.**",
"leftclick": "When this tutorial asks you to click or double-click, we mean with the left button. On a trackpad it might be a single-click or single-finger tap. **Left-click {num} times.**",
"rightclick": "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click {num} times.**",
"rightclick": {
"one": "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click once.**",
"other": "Sometimes we'll also ask you to right-click. This might be the same as control-click, or two-finger tap on a trackpad. Your keyboard might even have a 'menu' key that works like right-click. **Right-click {num} times.**"
},
"chapters": "So far, so good! You can use the buttons below to skip chapters at any time or to restart a chapter if you get stuck. Let's begin! **Click '{next}' to continue.**"
},
"navigation": {
Expand Down Expand Up @@ -6601,7 +6637,7 @@
"attribution": {
"text": "Terms & Feedback"
},
"description": "Imagery boundaries and capture dates. Labels appear at zoom level 13 and higher.",
"description": "Imagery boundaries and capture dates. Labels appear at zoom level 14 and higher.",
"name": "DigitalGlobe Premium Imagery Vintage"
},
"DigitalGlobe-Standard": {
Expand All @@ -6615,7 +6651,7 @@
"attribution": {
"text": "Terms & Feedback"
},
"description": "Imagery boundaries and capture dates. Labels appear at zoom level 13 and higher.",
"description": "Imagery boundaries and capture dates. Labels appear at zoom level 14 and higher.",
"name": "DigitalGlobe Standard Imagery Vintage"
},
"EsriWorldImagery": {
Expand All @@ -6625,13 +6661,6 @@
"description": "Esri world imagery.",
"name": "Esri World Imagery"
},
"EsriWorldImageryClarity": {
"attribution": {
"text": "Terms & Feedback"
},
"description": "Esri archive imagery that may be clearer and more accurate than the default layer.",
"name": "Esri World Imagery (Clarity) Beta"
},
"MAPNIK": {
"attribution": {
"text": "© OpenStreetMap contributors, CC-BY-SA"
Expand Down Expand Up @@ -6699,45 +6728,41 @@
"description": "Yellow = Public domain map data from the US Census. Red = Data not found in OpenStreetMap",
"name": "TIGER Roads 2017"
},
"US_Forest_Service_roads_overlay": {
"description": "Highway: Green casing = unclassified. Brown casing = track. Surface: gravel = light brown fill, Asphalt = black, paved = gray, ground =white, concrete = blue, grass = green. Seasonal = white bars",
"name": "U.S. Forest Roads Overlay"
},
"Waymarked_Trails-Cycling": {
"attribution": {
"text": "© waymarkedtrails.org, OpenStreetMap contributors, CC by-SA 3.0"
"text": "© Sarah Hoffmann, CC by-SA 3.0, map data OpenStreetMap contributors, ODbL 1.0"
},
"name": "Waymarked Trails: Cycling"
},
"Waymarked_Trails-Hiking": {
"attribution": {
"text": "© waymarkedtrails.org, OpenStreetMap contributors, CC by-SA 3.0"
"text": "© Sarah Hoffmann, CC by-SA 3.0, map data OpenStreetMap contributors, ODbL 1.0"
},
"name": "Waymarked Trails: Hiking"
},
"Waymarked_Trails-MTB": {
"attribution": {
"text": "© waymarkedtrails.org, OpenStreetMap contributors, CC by-SA 3.0"
"text": "© Sarah Hoffmann, CC by-SA 3.0, map data OpenStreetMap contributors, ODbL 1.0"
},
"name": "Waymarked Trails: MTB"
},
"Waymarked_Trails-Skating": {
"attribution": {
"text": "© waymarkedtrails.org, OpenStreetMap contributors, CC by-SA 3.0"
"text": "© Sarah Hoffmann, CC by-SA 3.0, map data OpenStreetMap contributors, ODbL 1.0"
},
"name": "Waymarked Trails: Skating"
},
"Waymarked_Trails-Winter_Sports": {
"attribution": {
"text": "© waymarkedtrails.org, OpenStreetMap contributors, CC by-SA 3.0"
"text": "© Michael Spreng, CC by-SA 3.0, map data OpenStreetMap contributors, ODbL 1.0"
},
"name": "Waymarked Trails: Winter Sports"
},
"basemap.at": {
"attribution": {
"text": "basemap.at"
},
"description": "Basemap of Austria, based on government data.",
"description": "Basemap of Austria, based on goverment data.",
"name": "basemap.at"
},
"basemap.at-orthofoto": {
Expand Down Expand Up @@ -6799,7 +6824,7 @@
},
"stamen-terrain-background": {
"attribution": {
"text": "Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL"
"text": "Map tiles by Stamen Design, under CC BY 3.0"
},
"name": "Stamen Terrain"
},
Expand Down
1 change: 1 addition & 0 deletions modules/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { utilGetAllNodes } from './util';
export { utilGetPrototypeOf } from './util';
export { utilGetSetValue } from './get_set_value';
export { utilIdleWorker} from './idle_worker';
export { t } from './locale';
export { utilNoAuto } from './util';
export { utilPrefixCSSProperty } from './util';
export { utilPrefixDOMProperty } from './util';
Expand Down
Loading

0 comments on commit 26efb6e

Please sign in to comment.