Add basic i18n for list and single (#30)

* add: basic i18n for list and single

* add: apply suggestions

* fix: indent using 4 tabs
This commit is contained in:
Guillaume 2022-02-07 06:54:13 +01:00 committed by GitHub
parent f6133c4eac
commit 4791a23949
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View file

@ -12,6 +12,7 @@ Etch is a simple, responsive theme for [Hugo](https://gohugo.io) with a focus on
* Syntax highlighting with customizable theme.
* Dark theme which automatically adjusts based on users' setting ([example](https://github.com/LukasJoswiak/etch/wiki/Dark-mode)).
* No external dependencies, no JavaScript, no web fonts.
* Internationalization friendly: use default English translations or create your own
## Installation

19
i18n/en.toml Normal file
View file

@ -0,0 +1,19 @@
# Learn how to use Date format (date, created, updated)
# -> https://gohugo.io/functions/dateformat/
[posts]
[posts.title]
other = "Posts"
[posts.date]
other = "Jan 2, 2006"
[post]
[post.created]
other = "Jan 2, 2006"
[post.updated]
other = "Updated Jan 2, 2006"

View file

@ -1,6 +1,6 @@
<li>
<a href="{{ .Permalink }}">
{{ .Title }}
<small><time>{{ .Date.Format "Jan 2, 2006" }}</time></small>
<small><time>{{ .Date | time.Format (i18n "posts.date") }}</time></small>
</a>
</li>

View file

@ -2,15 +2,15 @@
<article>
<header id="post-header">
<h1>{{ .Title }}</h1>
<div>
{{- if isset .Params "date" -}}
{{ if eq .Lastmod .Date }}
<time>{{ .Date.Format "January 2, 2006" }}</time>
{{ else }}
Updated <time>{{ .Lastmod.Format "January 2, 2006" }}</time>
{{ end }}
{{- end -}}
</div>
<div>
{{- if isset .Params "date" -}}
{{ if eq .Lastmod .Date }}
<time>{{ .Date | time.Format (i18n "post.created") }}</time>
{{ else }}
<time>{{ .Date | time.Format (i18n "post.updated") }}</time>
{{ end }}
{{- end -}}
</div>
</header>
{{- .Content -}}
</article>

View file

@ -1,4 +1,4 @@
<h3>Posts</h3>
<h3>{{ i18n "posts.title" }}</h3>
<ul id="posts">
{{- range where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ .Render "li" }}