Hugo: Hugo 0.76.* i18n .Count warning message

Created on 12 Oct 2020  Â·  6Comments  Â·  Source: gohugoio/hugo

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

NeedsInvestigation

Most helpful comment

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

All 6 comments

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

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.

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

This is per documentation

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

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?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artelse picture artelse  Â·  3Comments

vielmetti picture vielmetti  Â·  3Comments

MunifTanjim picture MunifTanjim  Â·  3Comments

ianbrandt picture ianbrandt  Â·  3Comments

kaushalmodi picture kaushalmodi  Â·  3Comments