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

Hugo 0.76.* i18n .Count warning message #7822

Closed
Vimux opened this issue Oct 12, 2020 · 8 comments · Fixed by #8456
Closed

Hugo 0.76.* i18n .Count warning message #7822

Vimux opened this issue Oct 12, 2020 · 8 comments · Fixed by #8456

Comments

@Vimux
Copy link

Vimux commented Oct 12, 2020

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.76.4/extended darwin/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes.

It works correctly in 0.48.0 – 0.75.1 without any warnings.


Problem

Mainroad demo build log shows the following warning messages since bumping to Hugo 0.76.*:

WARN 2020/10/12 13:40:31 Failed to get translated string for language "en" and ID "authorbox_name": template: :1:9: executing "" at <.Count>: can't evaluate field Count in type string
WARN 2020/10/12 13:40:31 Failed to get translated string for language "en" and ID "authorbox_name": template: :1:9: executing "" at <.Count>: can't evaluate field Count in type string
WARN 2020/10/12 13:40:31 Failed to get translated string for language "en" and ID "authorbox_name": template: :1:9: executing "" at <.Count>: can't evaluate field Count in type string
WARN 2020/10/12 13:40:31 Failed to get translated string for language "en" and ID "authorbox_name": template: :1:9: executing "" at <.Count>: can't evaluate field Count in type string
WARN 2020/10/12 13:40:31 Failed to get translated string for language "en" and ID "authorbox_name": template: :1:9: executing "" at <.Count>: can't evaluate field Count in type string

As a result, i18n string (authorbox_name) does not work as before.

Screenshot

Example

You can see it in action (authorbox block at the bottom of the page):

Demo 0.48.0

Hugo Themes demo (0.76.4)

Steps to reproduce

  1. Clone Mainroad repository and cd in the exampleSite dir

    git clone https://github.com/vimux/mainroad.git
    cd mainroad/exampleSite/
  2. Run Hugo server with the following command:

    hugo server --themesDir ../..
  3. Visit http://localhost:1313/post/hugoisforlovers/ in your browser and scroll to the bottom of the page.


Related parts:
i18n/en.yaml
partials/authorbox.html

@lingsamuel
Copy link

lingsamuel commented Oct 15, 2020

I change {{ .Count }} to {{ . }}, it works as before again (in fact I don't know why the theme is using Count)

@Vimux
Copy link
Author

Vimux commented Oct 15, 2020

I change {{ .Count }} to {{ . }}, it works as before again

The problem is that it works as before in Hugo v0.76.* only. Any other versions like v0.59.1, v0.68.3, or even v0.75.1 returns a different result in that case.

in fact I don't know why the theme is using Count

I can't speak for everyone, but I use this expression to pass variable in the translation string.

@cyChop
Copy link

cyChop commented Oct 15, 2020

in fact I don't know why the theme is using Count

This is per documentation

@kevinclevenger
Copy link

Seeing the same thing with 0.76.3 and the Beautiful Hugo theme, destroys the posted on date in the generated site.

WARN 2020/10/17 16:33:10 Failed to get translated string for language "en" and ID "postedOnDate": template: :1:4: executing "" at <.Count>: can't evaluate field Count in type string

@cyChop
Copy link

cyChop commented Oct 19, 2020

A note after some experimentation on my own site: {{ .Count }} is still required for numbers (integers), but you need to use {{ . }} for any other kind of object (at least for datetimes). It adds some readability, but it's a breaking change. From what I understand, not from Hugo itself but from go-i18n.

I think it's hard to find the best way to go here. For ease of use, keeping things compatible is great, but that's a complicated way to go since developers would have to do the same for all libs Hugo depend upon (which would end being an impossible task and might kill Hugo's performances in the end).

As far as I'm concerned, and Hugo's developers will of course have the final word, this should be divided into two tasks:

  • Hugo's documentation should be updated to help make this subtlety better-known;
  • Theme developers should be informed of this change, and that their theme is no longer fully compatible with Hugo 0.76+.

A workaround for people who use not-updated themes would be to write translation files and overwrite the problematic translations in your local files. It's a quickfix, but if I'm correct on Hugo's order of precedence, it will take the translation you provide over the one included inside the theme. You would just need to write the failing translations, no more.

One open question: I don't know who adds the "Count" variable? Is it Hugo when wrapping an int it passes to go-i18n, or is it go-i18n itself? In the first case, wouldn't it be possible to send it as {{ . }}, so that all variables are called in a uniform fashion, no matter what their type is?

@nonumeros
Copy link

testing it with v0.76.4ext as the op's, if there's a variable named name somewhere, why would the same name is used as a parameter on the config file. Whether it'd be yaml or toml.

Anyhow.

if I were to have as the op's

[Author]
  name = "John Doe"

on the config file, and I'd name name to something else, or comment it out, ,then the at <.Count>: can't evaluate field Count in type string would not come up. But I have no idea whether this issue was ever resolved or not, as it shows it's still open.

atomicjeep added a commit to irissorg/transcripts.podcast.iriss.org.uk that referenced this issue Feb 2, 2021
@jmooring
Copy link
Member

Related: gohugoio/hugoDocs#1410

@bep bep modified the milestones: v0.78, v0.83 Apr 22, 2021
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
bep added a commit to bep/hugo that referenced this issue Apr 22, 2021
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
@bep bep closed this as completed in #8456 Apr 23, 2021
bep added a commit that referenced this issue Apr 23, 2021
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
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants