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

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

Closed
Wivik opened this issue Nov 8, 2023 · 2 comments
Closed

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

Wivik opened this issue Nov 8, 2023 · 2 comments

Comments

@Wivik
Copy link

Wivik commented Nov 8, 2023

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

  • Multilingual site fr + en
  • fr is the default language
  • Two i18n files made : fr.yaml, en.yaml

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 <THEMENAME>"
   - 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 <SECTIONNAME>/<FILENAME>.<FORMAT>".
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

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

image

👍

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

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

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

Thanks for your help !

@jmooring
Copy link
Member

jmooring commented Nov 8, 2023

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:
gohugoio/hugoDocs#2311

@jmooring jmooring closed this as completed Nov 8, 2023
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 Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants