Internationalization 如何翻译Hugo中的标签(分类法)?

Internationalization 如何翻译Hugo中的标签(分类法)?,internationalization,taxonomy,hugo,Internationalization,Taxonomy,Hugo,我正在努力翻译雨果的标签 我的标签仅在我的帖子的元数据中声明: --- author: arthur.sw date: 2007-01-01T00:00:35Z tags: - experiment - reflection --- ... post content ... 我在我的语言文件中翻译了它们: /i18n/en.toml: [Experiment] one = "Experiment" other = "Experiments" [Reflection] one = "

我正在努力翻译雨果的标签

我的标签仅在我的帖子的元数据中声明:

---
author: arthur.sw
date: 2007-01-01T00:00:35Z
tags:
  - experiment
  - reflection
---

... post content ...
我在我的语言文件中翻译了它们:

/i18n/en.toml

[Experiment]
one = "Experiment"
other = "Experiments"

[Reflection]
one = "Reflection"
other = "Reflections"
[Experiment]
one = "Expérience"
other = "Expériences"

[Reflection]
one = "Réflexion"
other = "Réflexions"
[...]

        <h1 class='title'>
          {{- if eq .Kind "taxonomy" -}}
          <span class='taxonomy-type'>
            {{- ( ( i18n .Data.Singular 1 ) | default .Data.Singular ) | title -}}
            {{- print ": " -}}
          </span>
          {{- end -}}

          {{- i18n .Title -}}

        </h1>

[...]
/i18n/fr.toml

[Experiment]
one = "Experiment"
other = "Experiments"

[Reflection]
one = "Reflection"
other = "Reflections"
[Experiment]
one = "Expérience"
other = "Expériences"

[Reflection]
one = "Réflexion"
other = "Réflexions"
[...]

        <h1 class='title'>
          {{- if eq .Kind "taxonomy" -}}
          <span class='taxonomy-type'>
            {{- ( ( i18n .Data.Singular 1 ) | default .Data.Singular ) | title -}}
            {{- print ": " -}}
          </span>
          {{- end -}}

          {{- i18n .Title -}}

        </h1>

[...]
但它从不翻译标签,不管我是否使用大写字母

我还试图修改我的
布局/_default/list.html

[Experiment]
one = "Experiment"
other = "Experiments"

[Reflection]
one = "Reflection"
other = "Reflections"
[Experiment]
one = "Expérience"
other = "Expériences"

[Reflection]
one = "Réflexion"
other = "Réflexions"
[...]

        <h1 class='title'>
          {{- if eq .Kind "taxonomy" -}}
          <span class='taxonomy-type'>
            {{- ( ( i18n .Data.Singular 1 ) | default .Data.Singular ) | title -}}
            {{- print ": " -}}
          </span>
          {{- end -}}

          {{- i18n .Title -}}

        </h1>

[...]
[…]
{{-if eq.Kind“分类法”-}
{-((i18n.Data.Singular 1)| default.Data.Singular)| title-}
{{-print”:“-}
{{-end-}
{{-i18n.Title-}
[...]
(我在
.Title
之前添加了
i18n
,以翻译分类名称),但这也不起作用


如何翻译标记?

每个标记都是分类法的一部分。类别是另一个例子——这两种类型在Hugo中已经预定义了

Hugo中多语言页面的工作方式是,您将有两个单独的文件来填充不同的内容。这里您需要知道的是,分类法也是您可以在各自的内容文件中直接翻译的东西,而不是其他地方

在您的特定情况下,如果您将标记作为已翻译的标记放入post文件中,它们将显示在每个已翻译的页面中

这看起来很明显,但您很快就会认识到,如果您转到分类列表页面(例如
/tags/
),那么您将看到默认语言的所有标记。如果您切换到另一种语言,比如法语,它可能会转到另一个URI,如
/fr/tags/
,并显示该特定语言的所有标记。 接下来,您希望在这里可以单击任何标记并查看与之相关的页面。是的,您可以-但是在特定的概述页面上切换语言会显示其他语言没有这样的标记(除非它们的名称完全相同,这有时可能会发生)

这就是Hugo在两个标记之间建立连接变得有点不方便的地方,您需要在
/taxonomy/tag/.fr.md
下创建额外的模板文件,前面有一个
translationKey
属性,该属性将以小写形式包含英文名称

这就是所谓的“绕过默认链接”,您可以从相应的