-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix singular/plural translation section #1410
Comments
So I think this page currently describes how go-i18n V1 behaved. We are now using go-i18n V2. |
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 `.Count`. 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. Fixes gohugoio#8454 Closes gohugoio#7822 See gohugoio/hugoDocs#1410
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 `.Count`. 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. Fixes gohugoio#8454 Closes gohugoio#7822 See gohugoio/hugoDocs#1410
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 `.Count`. 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. Fixes gohugoio#8454 Closes gohugoio#7822 See gohugoio/hugoDocs#1410
The The Unicode Common Locale Data Repository (CLDR) defines plural rules for each language. Take a look at the "cardinal" categories in this table. Examples:
The https://github.com/nicksnyder/go-i18n package handles the plural rules for Hugo, but there are few important things to remember. 1) Cardinal categories defined in the i18n file that are not defined in the CLDR plural rules will be ignored. In the example below, all but
[cat]
zero = "kittens" # ignored
one = "cat"
two = "kitties" # ignored
few = "fur balls" # ignored
many = "beasts" # ignored
other = "cats" 2) When a cardinal category is defined in the CLDR plural rules but is missing from the i18n file, then (a) the value from the
[cat]
one = "kot"
other = "koty" The CLDR plural rules specify two additional cardinal categories for the Polish language:
3) Although the current implementation of https://github.com/nicksnyder/go-i18n uses |
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 `.Count`. 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. Fixes gohugoio#8454 Closes gohugoio#7822 See gohugoio/hugoDocs#1410
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 `.Count`. 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. Fixes gohugoio#8454 Closes gohugoio#7822 See gohugoio/hugoDocs#1410
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
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 #8454 Closes #7822 See gohugoio/hugoDocs#1410
Additional info for when we (I) get around to updating this page. This comes into play when
This produces the same results as
The Unicode Common Locale Data Repository (CLDR) defines plural rules for 208 languages. For 165 of those languages, the cardinal category The other 43 languages use a variety of cardinal categories when the quantity specified for the translation is zero, including
|
Closing in favor of #2099. |
https://gohugo.io/content-management/multilingual/#query-a-singularplural-translation
No.
No.
No.
Maybe some of this was true in an earlier version, but none of it is true now.
.ReadingTime
is just anint
. It doesn't have a "built-in Count" property.The only way to get
T/i18n
to return the singular value from the translation table is to pass the integer value 1.If you pass a float it complains.
T/i18n
always returns the plural value from the translation table when you pass a string, slice, or dict. All of these return the plural value:[hugo v0.83.0-DEV+extended linux/amd64 BuildDate=unknown]
The text was updated successfully, but these errors were encountered: