Skip to content

Commit

Permalink
feat: support multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
nodejh committed Aug 21, 2021
1 parent 3cbfc0e commit 0912af8
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 109 deletions.
17 changes: 17 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@
> ⚠️ 你需要删除这行配置: `themesDir: ../../` 。
### 2.2 默认语言
你可以通过 `defaultContentLanguage` 配置设置默认语言:
```yaml
defaultContentLanguage: en
```
默认是 `en`。目前支持以下语言:

- `en`: 英语
- `zh`: 汉语
- `nl`: 荷兰语

更多关于多语言的信息可以参考:[Multilingual Mode](https://gohugo.io/content-management/multilingual/)


### 2.2 评论功能

要使用评论功能,你需要添加下面的配置:
Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,23 @@ Take a look inside the [`exampleSite`](https://github.com/nodejh/hugo-theme-mini
> ⚠️ You may need to delete the line: `themesDir: ../../`
### 2.2 Add Comments
### 2.2 Default Content Language
You can set default content language by `defaultContentLanguage`:
```yaml
defaultContentLanguage: en
```
Default is `en`. Now support:

- `en`: English
- `zh`: Chinese
- `nl`: Dutch

More about multiple languages: [Multilingual Mode](https://gohugo.io/content-management/multilingual/).

### 2.3 Add Comments

To enable comments, add following to your config file:

Expand All @@ -82,7 +98,7 @@ To enable comments, add following to your config file:
enableComments: true
```
### 2.3 Google Analytics
### 2.4 Google Analytics
To enable google analytics, add following to your config file:
Expand All @@ -94,7 +110,7 @@ To enable google analytics, add following to your config file:
enableGoogleAnalytics: true
```

### 2.4 Logo and favicon
### 2.5 Logo and favicon

You can replace the log in the top of each page and favicon with your own images. To do that put your own logo and favicon into the `images` directory of your website static directory, then named them `avatar.png` and `favicon.ico`. For example:

Expand All @@ -106,7 +122,7 @@ You can replace the log in the top of each page and favicon with your own images
└── favicon.ico
```

### 2.5 Nearly finished
### 2.6 Nearly finished

In order to see your site in action, run Hugo's built-in local server.

Expand All @@ -116,7 +132,7 @@ $ hugo server

Now enter http://localhost:1313 in the address bar of your browser.

### 2.6 Production
### 2.7 Production

To run in production (e.g. to have Google Analytics show up), run HUGO_ENV=production before your build command. For example:

Expand Down
2 changes: 1 addition & 1 deletion exampleSite/config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Hugo
theme: hugo-theme-mini
paginate: 3

# for exampleSite only, you may need to delete the line: `themesDir: ../../`
# !!! exampleSite only, you may need to delete the line: `themesDir: ../../`
themesDir: ../../

hasCJKLanguage: true
Expand Down
24 changes: 8 additions & 16 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ languageCode: en-us
title: Hugo
theme: hugo-theme-mini

# for exampleSite only, you may need to delete the line: `themesDir: ../../`
# Default content language, support en (English) / zh (Chinese) / nl (Dutch), default 'en'
defaultContentLanguage: en

# !!! exampleSite only, you may need to delete the line: `themesDir: ../../`
themesDir: ../../

hasCJKLanguage: true
Expand All @@ -14,7 +17,7 @@ googleAnalytics: your-google-analytics-id
disqusShortname: your-disqus-shortname

# Hugo Configure Markup
# more info: https://gohugo.io/getting-started/configuration-markup#
# More info: https://gohugo.io/getting-started/configuration-markup#
markup:
highlight:
guessSyntax: true
Expand Down Expand Up @@ -44,7 +47,7 @@ params:


###########################################
# Optional
# Optional Configuration
###########################################

# To enable RSS, you could set `enableRSS: true`, default is `true`
Expand All @@ -61,19 +64,8 @@ params:
math: false
# To hidden post summary in home page, you could set `hiddenPostSummaryInHomePage: true`, default is `false`
hiddenPostSummaryInHomePage: false

# text in page
home: '' # Default: Home
about: '' # Default: About
archive: '' # Default: Archive
tags: '' # Default: Tags
subscribe: '' # Default: Subscribe
olderPosts: '' # Default: Older Posts
newerPosts: '' # Default: Newer Posts
copyright: '' # Default: © Copyright 2021 ❤️ author
title404: '' # Default: 404 - Page Not Found
subtitle404: '' # Default: The content you're looking for doesn't seem to exist.
readMore: '' # Default: Read More
# Website copy write, default: '© Copyright 2021 ❤️ {params.author}'
copyright: ''

# Extra links in navigation
links:
Expand Down
29 changes: 0 additions & 29 deletions i18n/en.toml

This file was deleted.

50 changes: 50 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
home:
other: Home

archive:
other: Archive

tags:
other: Tags

about:
other: About

subscribe:
other: Subscribe

404title:
other: 404 - Page Not Found

404subtitle:
other: The content you're looking for doesn't seem to exist.

readMore:
other: Read more

minuteRead:
other: "{{ .ReadingTime }} minute read"

publishDate:
other: '{{ .PublishDate.Format "January 2, 2006" }}'

publishDateFull:
other: '{{ .PublishDate.Format "January 2, 2006" }}'

wordCount:
one: "{{ .WordCount }} word"
other: "{{ .WordCount }} words"

postsNewer:
other: Newer posts

postsOlder:
other: Older posts

poweredBy:
other: >-
Powered by <a href='http://www.gohugo.io/'>Hugo</a> Theme By <a
href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
publishDateShort:
other: '{{ .PublishDate.Format "January 2" }}'
29 changes: 0 additions & 29 deletions i18n/nl.toml

This file was deleted.

53 changes: 53 additions & 0 deletions i18n/nl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
home:
other: Huis

archive:
other: Archief

tags:
other: Tags

subscribe:
other: Abonneren

about:
other: Over

404title:
other: 404 - Pagina Niet Gevonden

404subtitle:
other: 'De pagina waar u naar op zoek bent, lijkt niet te bestaan.'

readMore:
other: Lees meer

minuteRead:
other: "{{ .ReadingTime }} minuten leestijd"

publishDate:
other: >-
{{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }} {{ .PublishDate.Year }}
publishDateFull:
other: >-
{{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }} {{ .PublishDate.Year }}
wordCount:
one: "{{ .WordCount }} woord"
other: "{{ .WordCount }} woorden"

postsNewer:
other: Nieuwere posts

postsOlder:
other: Oudere posts

poweredBy:
other: >-
Gemaakt met <a href='http://www.gohugo.io/'>Hugo</a> Thema door <a
href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
publishDateShort:
other: >-
{{ .PublishDate.Day }} {{ index $.Site.Data.months_nl (printf "%d" .PublishDate.Month) }}
50 changes: 50 additions & 0 deletions i18n/zh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
home:
other: 首页

archive:
other: 归档

tags:
other: 标签

subscribe:
other: 订阅

about:
other: 关于

404title:
other: "404"

404subtitle:
other: 页面不存在

readMore:
other: 更多内容

minuteRead:
other: "{{ .ReadingTime }}分钟"

publishDate:
other: '{{ .PublishDate.Format "2006/01/02" }}'

publishDateFull:
other: '{{ .PublishDate.Format "2006年01月02日" }}'

wordCount:
one: "{{ .WordCount }}字"
other: "{{ .WordCount }}字"

postsNewer:
other: 下一页

postsOlder:
other: 上一页

poweredBy:
other: >-
Powered by <a href='http://www.gohugo.io/'>Hugo</a> Theme By <a
href='https://github.com/nodejh/hugo-theme-cactus-plus'>nodejh</a>
publishDateShort:
other: '{{ .PublishDate.Format "01/02" }}'
2 changes: 1 addition & 1 deletion layouts/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>{{ i18n "404title" }}</h1>
{{ with .Site.Params.readMore }}
<h2 class="read-more">{{ . }}</h2>
{{ else }}
<h2 class="read-more">{{ i18n "readmore" }}</h2>
<h2 class="read-more">{{ i18n "readMore" }}</h2>
{{ end }}


Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3 class="key">
{{ range .Pages }}
<div class="value">
<div class="date">
<time datetime="{{ .PublishDate }}">{{ i18n "publishdate" . }}</time>
<time datetime="{{ .PublishDate }}">{{ i18n "publishDateShort" . }}</time>
</div>
<div class="title">
<a href="{{ .Permalink }}">
Expand Down
Loading

0 comments on commit 0912af8

Please sign in to comment.