Skip to content

Commit

Permalink
feat: support multilingual
Browse files Browse the repository at this point in the history
  • Loading branch information
xslingcn committed Sep 10, 2022
1 parent 78faea7 commit c111387
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 15 deletions.
15 changes: 15 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ title = "Vno Hugo"
baseURL = "https://vno-hugo.netlify.app/"
theme = "vno-hugo"

# supported languages: en-us, zh-cn (lowercase language codes only)
defaultContentLanguage = 'en-us'
# here lists available languages, if you wish to add your own custom translation, please refer to https://gohugo.io/content-management/multilingual
[languages]
[languages.en-us]
languageName = 'English(United States)'
weight = 10
[languages.zh-cn]
languageName = '简体中文(中国大陆)'
weight = 20

# Pagination
paginate = 10
paginatePath = "page"
Expand Down Expand Up @@ -61,5 +72,9 @@ host = "your_host"
title = "Blog"
description = "Visit blog"

[params.copyright]
license = 'CC BY-NC-SA 4.0'
license_link = 'http://creativecommons.org/licenses/by-nc-sa/4.0/'

[permalinks]
posts = "/:year/:month/:title/"
14 changes: 14 additions & 0 deletions i18n/en-US.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[continue]
other = 'Continue'

[earlier]
other = 'Earlier'

[recent]
other = 'Recent'

[license]
other = 'This site is licensed under a <a href="{{ .Site.Params.copyright.license_link }}">{{ .Site.Params.copyright.license }}</a> license.'

[poweredBy]
other = 'Generated by <a href="https://gohugo.io/">Hugo</a> at {{ . }}, themed with <a href="https://github.com/xslingcn/vno-hugo"> Vno - Hugo</a>.'
14 changes: 14 additions & 0 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[continue]
other = '继续阅读'

[earlier]
other = '更早的文章'

[recent]
other = '最近的文章'

[license]
other = '本站点内容基于 <a href="{{ .Site.Params.copyright.license_link }}">{{ .Site.Params.copyright.license }}</a> 协议发布。'

[poweredBy]
other = '由 <a href="https://gohugo.io/">Hugo</a> 于 {{ . }} 生成, 采用 <a href="https://github.com/xslingcn/vno-hugo"> Vno - Hugo</a> 作为主题。'
4 changes: 2 additions & 2 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<ol class="post-list">
{{ range .Paginator.Pages }}
<li>
<h2 class="post-list__post-title post-title"><a href="{{ .RelPermalink }}" title="访问 {{ .RelPermalink }}">{{ .Title }}</a></h2>
<h2 class="post-list__post-title post-title"><a href="{{ .RelPermalink }}" title="To {{ .RelPermalink }}">{{ .Title }}</a></h2>
<p class="excerpt">{{ .Summary | truncate 250 }}&hellip;</p>
<div class="post-list__meta">
<time datetime="{{ .Date.Format " 2006-01-02 15:04:05 -0700 " }}" class="post-list__meta--date date">{{ .Date.Format "2006-01-02" }}</time>
{{ with .Params.tags }} <span class="post-list__meta--tags tags"> {{ range . }} • <a href="{{ "tags" | absURL }}/{{ . | urlize }}">{{ . }}</a> {{ end }} </span> {{ end }}
<a class="btn-border-small" href={{ .RelPermalink }}>继续阅读</a></div>
<a class="btn-border-small" href={{ .RelPermalink }}>{{ T "continue" }}</a></div>
<hr class="post-list__divider" />
</li>
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<ol class="post-list">
{{ range .Paginator.Pages }}
<li>
<h2 class="post-list__post-title post-title"><a href="{{ .RelPermalink }}" title="访问 {{ .RelPermalink }}">{{ .Title }}</a></h2>
<h2 class="post-list__post-title post-title"><a href="{{ .RelPermalink }}" title="To {{ .RelPermalink }}">{{ .Title }}</a></h2>
<p class="excerpt">{{ .Summary | truncate 250 }}&hellip;</p>
<div class="post-list__meta">
<time datetime="{{ .Date.Format " 2006-01-02 15:04:05 -0700 " }}" class="post-list__meta--date date">{{ .Date.Format "2006-01-02" }}</time>
{{ with .Params.tags }} <span class="post-list__meta--tags tags"> {{ range . }} • <a href="{{ "tags" | absURL }}/{{ . | urlize }}">{{ . }}</a> {{ end }} </span> {{ end }}
<a class="btn-border-small" href={{ .RelPermalink }}>继续阅读</a></div>
<a class="btn-border-small" href={{ .RelPermalink }}>{{ T "continue" }}</a></div>
<hr class="post-list__divider" />
</li>
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>要查看<a href="http://disqus.com/?ref_noscript"> Disqus </a>评论,请启用 JavaScript</noscript>
<noscript>To view comments from<a href="http://disqus.com/?ref_noscript"> Disqus </a>, please enable JavaScript.</noscript>

{{ else if .Site.Params.comment.duoshuo }}
<div class="ds-thread" data-thread-key="{{ .Permalink }}" data-title="{{ .Title }}" data-url="{{ .Permalink }}"></div>
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section class="footer">
<footer>
<span class="footer__copyright">本站点采用<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享 署名-非商业性使用-相同方式共享 4.0 国际 许可协议</a></span>
<span class="footer__copyright"><a href="https://gohugo.io/">Hugo</a> 于 {{ now.Format "2006-01-02" }} 生成,采用<a href="https://github.com/xslingcn/vno-hugo"> Vno - Hugo </a>作为主题</span>
<span class="footer__copyright">{{ i18n "license" . | safeHTML }}</span>
<span class="footer__copyright">{{ i18n "poweredBy" (now.Format "2006-01-02") | safeHTML }}</span>
</footer>
</section>
8 changes: 4 additions & 4 deletions layouts/partials/read-more.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<section class="read-more">
{{ if .Next }}
<div class="read-more-item">
<span class="read-more-item-dim">最近的文章</span>
<span class="read-more-item-dim">{{ T "recent" }}</span>
<h2 class="post-list__post-title post-title"><a href="{{ .Next.RelPermalink }}" title="link to {{ .Next.Title }}">{{ .Next.Title }}</a></h2>
<p class="excerpt">{{ .Next.Summary | truncate 250}}&hellip;</p>
<div class="post-list__meta">
<time datetime="{{ .Date.Format " 2006-01-02 15:04:05 -0700" }}" class="post-list__meta--date date">{{ .Next.Date.Format "2006-01-02" }}</time>
{{ with .Next.Params.tags }} <span class="post-list__meta--tags tags"> {{ range . }} • <a href="{{ "tags" | absURL }}/{{ . | urlize }}">{{ . }}</a> {{ end }} </span> {{ end }}
<a class="btn-border-small" href="{{ .Next.RelPermalink }}">继续阅读</a>
<a class="btn-border-small" href="{{ .Next.RelPermalink }}">{{ T "continue" }}</a>
</div>
</div>
{{ end }}


{{ if .Prev }}
<div class="read-more-item">
<span class="read-more-item-dim">更早的文章</span>
<span class="read-more-item-dim">{{ T "earlier" }}</span>
<h2 class="post-list__post-title post-title"><a href="{{ .Prev.RelPermalink }}" title="link to {{ .Prev.Title }}">{{ .Prev.Title }}</a></h2>
<p class="excerpt">{{ .Prev.Summary | truncate 250}}&hellip;</p>
<div class="post-list__meta">
Expand All @@ -25,7 +25,7 @@ <h2 class="post-list__post-title post-title"><a href="{{ .Prev.RelPermalink }}"
{{ range . }} • <a href="{{ "tags" | absURL }}/{{ . | urlize }}">{{ . }}</a> {{ end }}
</span>
{{ end }}
<a class="btn-border-small" href="{{ .Prev.RelPermalink }}">继续阅读</a>
<a class="btn-border-small" href="{{ .Prev.RelPermalink }}">{{ T "continue" }}</a>
</div>
</div>
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/side-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<div class="panel-main__inner panel-inverted">
<div class="panel-main__content">

<a href="/#blog" title="前往 {{ .Site.Title }} 的主页" class="blog-button"><img src="/images/avatar.jpg" width="80" alt="{{ .Site.Title }} logo" class="panel-cover__logo logo" /></a>
<h1 class="panel-cover__title panel-title"><a href="/#blog" title="link to homepage for {{ .Site.Title }}" class="blog-button">{{ .Site.Title }}</a></h1>
<a href="/#blog" title="Homepage of {{ .Site.Title }} " class="blog-button"><img src="/images/avatar.jpg" width="80" alt="{{ .Site.Title }} logo" class="panel-cover__logo logo" /></a>
<h1 class="panel-cover__title panel-title"><a href="/#blog" title="Homepage of {{ .Site.Title }}" class="blog-button">{{ .Site.Title }}</a></h1>
{{ if (.Site.Params.subTitle) }}
<span class="panel-cover__subtitle panel-subtitle">{{ .Site.Params.subTitle }}</span>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/social.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ if .Site.Params.social.weibo }}
<!-- Weibo -->
<li class="navigation__item">
<a href="http://weibo.com/{{ .Site.Params.social.weibo}}" title="@{{ .Site.Params.social.weibo}} 的微博" target="_blank">
<a href="http://weibo.com/{{ .Site.Params.social.weibo}}" title="@{{ .Site.Params.social.weibo}}" target="_blank">
<i class='social fa fa-weibo'></i>
<span class="label">Weibo</span>
</a>
Expand All @@ -14,7 +14,7 @@
{{ if .Site.Params.social.github }}
<!-- Github -->
<li class="navigation__item">
<a href="https://github.com/{{ .Site.Params.social.github}}" title="@{{ .Site.Params.social.github}} 的 Github" target="_blank">
<a href="https://github.com/{{ .Site.Params.social.github}}" title="@{{ .Site.Params.social.github}}" target="_blank">
<i class='social fa fa-github'></i>
<span class="label">Github</span>
</a>
Expand Down

0 comments on commit c111387

Please sign in to comment.