gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.8k stars 7.53k forks source link

i18n a field named "description" disable the translation #11687

Closed Wivik closed 1 year ago

Wivik commented 1 year ago

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

$ hugo version
hugo v0.119.0+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

Reproduced with hugo v0.120.4-f11bca5fec2ebb3a02727fb2a5cfb08da96fd9df linux/amd64 BuildDate=2023-11-08T11:18:07Z VendorInfo=gohugoio

The problem

In the i18n file for the language, creating this key named something.description: will disable the translation :

something:
  description: "A description"

It looks like the key description is reserved or something. I just hope I haven't missed it in the documentation and I apologize if it's the case.

Setup

Reproduced on a fresh hugo site

Details

``` hugo new site test Congratulations! Your new Hugo site was created in /home/seb/kDrive/Documents/blog/test. Just a few more steps... 1. Change the current directory to ...../test. 2. Create or install a theme: - Create a new theme with the command "hugo new theme " - Install a theme from https://themes.gohugo.io/ 3. Edit hugo.toml, setting the "theme" property to the theme name. 4. Create new content with the command "hugo new content /.". 5. Start the embedded web server with the command "hugo server --buildDrafts". hugo new theme test Creating new theme in ........../test/themes/test ```

Directory structure :

Details

``` tree . . ├── archetypes │   └── default.md ├── assets ├── content │   ├── en │   │   └── text.md │   └── fr │   └── text.md ├── data ├── hugo.yaml ├── i18n │   ├── en.yaml │   └── fr.yaml ├── layouts ├── static └── themes └── test ├── archetypes │   └── default.md ├── assets │   ├── css │   │   └── main.css │   └── js │   └── main.js ├── content │   ├── _index.md │   └── posts │   ├── _index.md │   ├── post-1.md │   ├── post-2.md │   └── post-3 │   ├── bryce-canyon.jpg │   └── index.md ├── data ├── hugo.toml ├── i18n ├── layouts │   ├── _default │   │   ├── baseof.html │   │   ├── home.html │   │   ├── list.html │   │   └── single.html │   └── partials │   ├── footer.html │   ├── head │   │   ├── css.html │   │   └── js.html │   ├── header.html │   ├── head.html │   ├── menu.html │   └── terms.html ├── LICENSE ├── README.md ├── static │   └── favicon.ico └── theme.toml 26 directories, 31 files ```

Hugo config

Details

```yaml baseURL: 'https://example.com/' theme: test defaultContentLanguage: fr defaultContentLanguageInSubdir: true languages: fr: contentDir: content/fr disabled: false languageCode: fr-FR languageName: Français title: 'Test fr' weight: 1 menu: main: - identifier: home name: 'Accueil' url: /fr/ weight: 10 en: contentDir: content/en languageCode: en-GB languageName: English title: 'Test En' disabled: false weight: 2 menu: main: - identifier: home name: 'Home' url: /en/ weight: 10 ```

Translation files

fr.yaml

home:
  some-content: "Du contenu"
  some-description: "Une description"
  # description: "Une description"

something:
  else: "ça marche"

en.yaml

home:
  some-content: "Some content"
  some-description: "Some description"
  # description: "Some description"

something:
  else: "is working"

Steps to reproduce

In themes/<theme>/layouts/defaults/single.html I've added these i18n calls and the lang display.

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  <p>{{ .Site.Language.Lang }}</p>
  <p>{{ i18n "home.some-content" }}</p>
  <p>{{ i18n "home.some-description" }}</p>
  <p>{{ i18n "home.description" }}</p>
  <p>{{ i18n "something.else" }}</p>

  {{ $dateMachine := .Date | time.Format "2006-01-02T15:04:05-07:00" }}
  {{ $dateHuman := .Date | time.Format ":date_long" }}
  <time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>

  {{ .Content }}
  {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
{{ end }}
Screenshots

![image](https://github.com/gohugoio/hugo/assets/48727868/3f7674c3-489e-4b14-b579-7d68a831c433) ![image](https://github.com/gohugoio/hugo/assets/48727868/1ba69368-973b-476e-9ab0-b50b74e9b679)

:+1:

If I enable description: in the English language file, the translation revers to default lang => French in my case.

home:
  some-content: "Some content"
  some-description: "Some description"
  description: "Some description"

something:
  else: "is working"
Screenshots

![image](https://github.com/gohugoio/hugo/assets/48727868/8cca1d27-30fe-4456-88b7-53d88ea791f7)

The English translation is disabled.

If I enable description: in the French file, both English and French i18n lines are lost :

home:
  some-content: "Du contenu"
  some-description: "Une description"
  description: "Une description"

something:
  else: "ça marche"
Screenshots

![Peek 2023-11-08 22-38](https://github.com/gohugoio/hugo/assets/48727868/21c095c7-f65d-49bb-9b5b-bd3090603fde)

hugo --printI18nWarnings returns missing translations :

hugo print i18n warnings

``` hugo --printI18nWarnings Start building sites … hugo v0.119.0+extended linux/amd64 BuildDate=unknown WARN i18n|MISSING_TRANSLATION|fr|home WARN i18n|MISSING_TRANSLATION|fr|home.some-content WARN i18n|MISSING_TRANSLATION|fr|home.some-description WARN i18n|MISSING_TRANSLATION|fr|home.description WARN i18n|MISSING_TRANSLATION|en|home WARN i18n|MISSING_TRANSLATION|en|home.some-content WARN i18n|MISSING_TRANSLATION|en|home.some-description WARN i18n|MISSING_TRANSLATION|en|home.description | FR | EN -------------------+----+----- Pages | 18 | 7 Paginator pages | 0 | 0 Non-page files | 1 | 0 Static files | 1 | 1 Processed images | 0 | 0 Aliases | 1 | 0 Sitemaps | 2 | 1 Cleaned | 0 | 0 Total in 28 ms ```

Please note that the other YAML parts are not impacted.

Screenshot

![Peek 2023-11-08 22-44](https://github.com/gohugoio/hugo/assets/48727868/9e149119-4100-4dfb-af9f-5f3092f60d85)

Thanks for your help !

jmooring commented 1 year ago

We use the nicksnyder/go-i18n package to handle translations. There are several reserved words in the translation data structure:

id
: Uniquely identifies the message.

description
: Describes the message to give additional context to translators that may be relevant for translation.

hash
: Uniquely identifies the content of the message that this message was translated from.

leftdelim
: The left Go template delimiter.

rightdelim
: The right Go template delimiter.

zero
: The content of the message for the CLDR plural form "zero".

one
: The content of the message for the CLDR plural form "one".

two
: The content of the message for the CLDR plural form "two".

few
: The content of the message for the CLDR plural form "few".

many
: The content of the message for the CLDR plural form "many".

other
: The content of the message for the CLDR plural form "other".

I've created an issue in the documentation repository to list these somewhere: https://github.com/gohugoio/hugoDocs/issues/2311

github-actions[bot] commented 11 months ago

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.