You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: support inline multi-form plurals and refined language rules
- Added support for inline multi-form plural syntax: {{plural:count|one:item|other:{{count}} items}}
- Refined plural rules for French (0 and 1 are 'one')
- Added more comprehensive language coverage in internal/plural
- Updated README, docs, tests, and examples with new pluralization features
@@ -146,6 +148,7 @@ All fields of `msgcat.Config`:
146
148
- **Template tokens (named parameters)**
147
149
- `{{name}}`— simple substitution.
148
150
- `{{plural:count|singular|plural}}`— binary plural by named count parameter.
151
+
- `{{plural:count|one:item|few:items|many:items|other:items}}`— multi-form plural by named count parameter using CLDR rules (supports 0, 1, 2, few, many, other depending on language).
149
152
- **CLDR plural forms** — optional `short_forms` / `long_forms` per entry (keys: `zero`, `one`, `two`, `few`, `many`, `other`) for full locale rules; see [CLDR and messages in Go](docs/CLDR_AND_GO_MESSAGES_PLAN.md).
150
153
- `{{num:amount}}`— localized number for named parameter.
151
154
- `{{date:when}}`— localized date for named parameter (`time.Time` or `*time.Time`).
Copy file name to clipboardExpand all lines: docs/CLDR_AND_GO_MESSAGES_PLAN.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,20 @@
2
2
3
3
Plan to add **CLDR-style plural forms** and **messages defined in Go with extract** to msgcat, closing the gap with go-i18n.
4
4
5
-
**Implementation status:** Done. Library has `ShortForms`/`LongForms`/`PluralParam` on `RawMessage`, `internal/plural` for form selection, `MessageDef` type, CLI extract finds MessageDef literals and merges into YAML, merge copies plural fields. See README, examples/cldr_plural, examples/msgdef.
5
+
**Implementation status:** Done. Library has `ShortForms`/`LongForms`/`PluralParam` on `RawMessage`, **inline multi-form plural syntax**`{{plural:count|one:...|other:...}}`, `internal/plural` for form selection, `MessageDef` type, CLI extract finds MessageDef literals and merges into YAML, merge copies plural fields. See README, examples/cldr_plural, examples/msgdef.
6
6
7
7
---
8
8
9
9
## 1. CLDR plurals
10
10
11
11
### 1.1 Goal
12
12
13
-
Support the full set of CLDR plural categories (**zero**, **one**, **two**, **few**, **many**, **other**) so that languages with more than two forms (e.g. Arabic, Russian, Welsh) can have correct pluralization. Current msgcat only has binary `{{plural:count|singular|plural}}`.
13
+
Support the full set of CLDR plural categories (**zero**, **one**, **two**, **few**, **many**, **other**) so that languages with more than two forms (e.g. Arabic, Russian, Welsh) can have correct pluralization. Support both optional entry-level maps and **inline multi-form tokens**.
14
14
15
15
### 1.2 Backward compatibility
16
16
17
-
- Keep existing **short** / **long** strings and **`{{plural:count|singular|plural}}`** unchanged. No breaking change.
17
+
- Keep existing **short** / **long** strings and **`{{plural:count|singular|plural}}`** (binary) unchanged. No breaking change.
18
+
- Add **inline multi-form support**: `{{plural:count|one:item|other:items}}` uses the language rule to pick a form.
18
19
- Add **optional** plural form maps. When present, they are used instead of the binary plural token for that entry.
19
20
20
21
### 1.3 YAML format (optional plural forms)
@@ -162,7 +163,7 @@ type MessageDef struct {
162
163
163
164
## 4. Out of scope (for this plan)
164
165
165
-
- **Changing existing binary plural token:** `{{plural:count|singular|plural}}` stays as-is when CLDR forms are not used.
0 commit comments