langs/i18n: Revise the plural implementation#8456
Conversation
|
@jmooring I would appreciate if you could have a look at this. Esp. look at the test cases in |
83beb65 to
082b1ad
Compare
|
OK, I have an idea of how to make this even better. Will be back in a flash. |
There were some issues introduced with the plural counting when we upgraded from v1 to v2 of go-i18n.
This commit improves that situation given the following rules:
* A single integer argument is used as plural count and passed to the i18n template as a int type with a `.Count` method. The latter is to preserve compability with v1.
* Else the plural count is either fetched from the `Count`/`count` field/method/map or from the value itself.
* Any data type is accepted, if it can be converted to an integer, that value is used.
The above means that you can now do pass a single integer and both of the below will work:
```
{{ . }} minutes to read
{{ .Count }} minutes to read
```
Fixes gohugoio#8454
Closes gohugoio#7822
See gohugoio/hugoDocs#1410
|
OK, this should be ready to go. |
That's not going to provide the expected result with, for example, the Polish language. According to the CLDR plural rules for Polish, I have not finished testing yet, but wanted to provide this early feedback. I'm sorry, this stuff is messy. |
|
I think that allowing both of these constructs will lead to problems. i18n/en.toml I will have to remember to call And let me call it either way: |
The "support both" is just to avoid breaking old templates, and what you suggest isn't technically feasible (or, not without spending a stupid amount of time on it; remember: you can pass any object as context into the translation func). My thought about this going forward is that:
I'll merge this. It's certainly an improvement. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
There were some issues introduced with the plural counting when we upgraded from v1 to v2 of go-i18n.
This commit improves that situation given the following rules:
.Countmethod. The latter is to preserve compability with v1.Count/countfield/method/map or from the value itself.The above means that you can now do pass a single integer and both of the below will work:
Fixes #8454
Closes #7822
See gohugoio/hugoDocs#1410