<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>English on 施国鹏 (seth-shi)</title><link>https://sethix.com/zh-cn/tags/english/</link><description>Recent content in English on 施国鹏 (seth-shi)</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Thu, 24 Apr 2025 10:42:53 +0800</lastBuildDate><atom:link href="https://sethix.com/zh-cn/tags/english/index.xml" rel="self" type="application/rss+xml"/><item><title>让你的 hugo 博客实现多语言</title><link>https://sethix.com/zh-cn/posts/2025042410/</link><pubDate>Thu, 24 Apr 2025 10:42:53 +0800</pubDate><guid>https://sethix.com/zh-cn/posts/2025042410/</guid><description>前言 首先Hugo是实现不了自动跳转, 因为它本质是一个静态生成器 https://discourse.gohugo.io/t/auto-detect-browser-preferred-language/8391 实现 我使用的主题是 https://github.com/CaiJimmy/hugo-theme-stack, 其它的可按需修改 在 config.toml 中添加语言配置 languages: zh-cn: languageName: 中文 weight: 1 en: languageName: English title: &amp;#34;seth-shi&amp;#34; weight: 2 然后加一个切换语言按钮layouts/partials/sidebar/left.html &amp;lt;li id=&amp;#34;lang-switcher&amp;#34;&amp;gt; {{ range .Site.Languages }} &amp;lt;a data-url=&amp;#34;{{ .Lang | relURL }}&amp;#34; href=&amp;#34;javascript:void(0);&amp;#34; class=&amp;#34;lang-item {{ if eq .Lang $.Site.Language.Lang }}active{{ end }}&amp;#34; &amp;gt; {{ .LanguageName }} &amp;lt;/a&amp;gt; {{ end }} &amp;lt;/li&amp;gt; 这个文件的最后加入js脚本(用于根据用户选择的语言自动跳转到对应的语言首页) &amp;lt;script const langOptions = {{ .Site.Languages }}.map(l =&amp;gt; l.Lang) const langStoreKey = &amp;#39;__lang__&amp;#39;; const defaultLang = &amp;#39;zh&amp;#39;; const homePages = langOptions.</description></item></channel></rss>