- hugo支持多語言和多語言的生成
1. 配置默認語言和menu :config.toml
```
baseURL = "http://example.org/"
title = ""
theme = "hyde"
defaultContentLanguage = "en"
[params]
description = ""
homeMetaContent = "clouda3 personal blog"
footer = "clouda3的个人网站"
date = "2019-04-10 14:05:50"
codePenUser = "someUser"
[languages]
[language.en]
languageName = "English"
title = "English"
[[languages.en.menu.main]]
identifier = "home"
title = "my home"
name = "Home"
url = "/"
weight = 1
[[languages.en.menu.main]]
identifier = "blog"
title = "my blog"
name = "Blog"
url = "/posts/"
weight = 2
[language.cn]
languageName = "cn"
title = "中文"
[[languages.cn.menu.main]]
identifier = "home"
title = "主頁"
name = "Home"
url = "/cn"
weight = 7
[[languages.cn.menu.main]]
identifier = "blog"
title = "博客"
name = "博客"
url = "/cn/posts/"
weight = 8
```
2. 創建頁面post/first.cn.md first.en.md
3. 創建可以切換中英文的按鈕,layouts/partials/lang.html
```
<nav class="LangNav">
{{ range $.Site.Home.AllTranslations }}
<a href="{{ .Page.Permalink }}">{{ .Language.Lang }}</a>
{{ end }}
</nav>
```
4. 修改layouts/partials/sidebar.html
```
{{ partial "lang.html" . }}
```
5. 生成靜態html 目錄結構,cn是在一個目錄en是more的上一層目錄
```
public
---cn
---post
---post
```
6. 模板文字的多语言问题,创建i18n/en.toml cn.toml
```
cn.toml
[my_blog_description]
other = "云端的博客"
en.toml
[my_blog_description]
other = "yun duan's blog"
```
7. layouts/partial/sidebar.html
```
<aside class="sidebar">
<div class="container sidebar-sticky">
<div class="sidebar-about">
<a href="{{ .Site.BaseURL }}"><h1>{{ .Site.Title }}</h1></a>
<p class="lead">
{{ with .Site.Params.description }} {{.}} {{ else }}{{ i18n "my_blog_description"}}.{{end}}
</p>
</div>
{{ partial "lang.html" . }}
<nav>
<ul class="sidebar-nav">
{{ range .Site.Menus.main -}}
<li><a href="{{.URL}}"> {{ .Name }} </a></li>
{{- end }}
</ul>
</nav>
<p>{{ with .Site.Params.copyright }}{{.}}{{ else }}© {{ now.Format "2006"}}. All rights reserved. {{end}}</p>
</div>
</aside>
```
8. 打开主页看可以中英文切换
- 【入门】1:Hugo介绍
- 【入门】2:Hugo网站和主题演示
- 【入门】3:Hugo跟Wordpress和Hexo对比
- 【入门】4:20分钟快速搭建Hugo网站
- 【入门】5:免费网站托管到Gitpages
- 【入门】6:图标icon/robot.txt/404页面创建和设置
- 【入门】7:网站地图sitemap
- 【进阶】8:自定义菜单
- 【进阶】9:自定义Tag/category
- 【进阶】10:页面Meta keyword
- 【进阶】12:创建页面摘要
- 【进阶】11:创建列表【进行中...】
- 【进阶】13:创建分页
- 【进阶】14:创建统计
- 【进阶】15:创建rss
- 【高级】16:创建页面目录
- 【高级】17:创建站内搜索
- 【高级】18:创建多语言支持
- 【高级】19:显示相关内容
- 【高级】20:显示当前页面所有Tag
- 【高级】21:创建社交联系方式
- 【高级】22:创建社交分享
- 【高级】23:创建评论gitalk
- 【高级】24:自动化部署-netlify
- 【高级】25:自动化部署-Github actions