Hugo,如何设置日期语言

发布于 2025-01-12 06:15:10 字数 386 浏览 1 评论 0原文

我正在与 Hugo 一起创建一个法语博客。 目前我的所有日​​期都以英语显示(二月),但我希望它们以法语显示(février)。 如何设置语言?

我的 config.toml 看起来像这样:

baseURL = 'http://example.org/'
languageCode = 'fr-FR'
defaultContentLanguage = "fr"
defaultContentLang = "fr"
title = 'TITLE'
theme = "THEME"

我尝试将 languageCode、defaultContentLanguage 和 defaultContentLang 设置为 fr 但没有成功。

我不需要多语言支持,我只需要法语。

With Hugo, I'm creating a blog in french.
Currently all my date are displayed in english (february) but I want them to be displayed in french (février).
How to set the language ?

My config.toml looks like this:

baseURL = 'http://example.org/'
languageCode = 'fr-FR'
defaultContentLanguage = "fr"
defaultContentLang = "fr"
title = 'TITLE'
theme = "THEME"

I try to set languageCode, defaultContentLanguage and defaultContentLang to fr but with no success.

I don't need multi language support, I just only need french.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2025-01-19 06:15:10

要使用本地化,您需要使用 Hugo 函数 time.Format (它有一个别名 dateFormat)。它需要两个参数:

  • 所需的格式
  • time.Time 对象或时间戳

示例:

{{ time.Format "Jan. 2, 2006" .Date }}

{{ dateFormat "Jan. 2 , 2006" .Date }}

文档:https://gohugo.io/functions/dateformat/

.Format 方法(例如 {{.Date.Format "Jan. 2, 2006 }})将不会应用所需的本地化。

To use localization, you need to use the Hugo function time.Format (which has an alias dateFormat). It takes two parameters:

  • desired format
  • time.Time object, or timestamp

Example:

{{ time.Format "Jan. 2, 2006" .Date }}

or

{{ dateFormat "Jan. 2, 2006" .Date }}

Docs: https://gohugo.io/functions/dateformat/

The .Format method (e.g. {{.Date.Format "Jan. 2, 2006}}) will not apply the desired localization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文