From 8261eed6f8c2aeb2488a481f1d89ab9c8ff3a119 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Sat, 29 Jul 2023 17:33:12 +0700 Subject: Support multilingual --- archetypes/blog.md | 4 +-- archetypes/book.md | 4 +-- archetypes/default.md | 4 +-- assets/css/custom.css | 0 assets/css/theme.css | 7 +++++ i18n/en.toml | 13 +++++++++ i18n/fr.toml | 13 +++++++++ i18n/vi.toml | 11 ++++++++ layouts/_default/baseof.html | 4 +++ layouts/_default/list.html | 40 +++++++++++++++++++--------- layouts/_default/single.html | 4 +-- layouts/index.html | 14 +++++----- layouts/partials/footer.html | 5 ++-- layouts/partials/head.html | 5 +++- layouts/partials/header.html | 5 +++- layouts/partials/language-switcher.html | 11 ++++++++ layouts/partials/post-language-switcher.html | 6 ++--- 17 files changed, 113 insertions(+), 37 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 assets/css/theme.css create mode 100644 i18n/en.toml create mode 100644 i18n/fr.toml create mode 100644 i18n/vi.toml create mode 100644 layouts/partials/language-switcher.html diff --git a/archetypes/blog.md b/archetypes/blog.md index 2f7a907..4299061 100644 --- a/archetypes/blog.md +++ b/archetypes/blog.md @@ -1,6 +1,6 @@ -+++ +--- title: "{{ replace .Name "-" " " | title }}" date: {{ now.Format "2026-01-02" }} categories: [ blog ] draft: true -+++ +--- diff --git a/archetypes/book.md b/archetypes/book.md index 0da07c8..0218afb 100644 --- a/archetypes/book.md +++ b/archetypes/book.md @@ -1,6 +1,6 @@ -+++ +--- title: "{{ replace .Name "-" " " | title }}" weight: categories: [ book ] draft: true -+++ +--- diff --git a/archetypes/default.md b/archetypes/default.md index 351a260..26f317f 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -1,5 +1,5 @@ -+++ +--- title: "{{ replace .Name "-" " " | title }}" date: {{ .Date }} draft: true -+++ +--- diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..e69de29 diff --git a/assets/css/theme.css b/assets/css/theme.css new file mode 100644 index 0000000..ae5acde --- /dev/null +++ b/assets/css/theme.css @@ -0,0 +1,7 @@ +nav ul, nav ul li { + display: inline-block; +} + +footer { + padding-top: 1.5rem; +} diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..1cf0f8a --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,13 @@ +["choose language"] +other = "Choose another language:" + +[current] +other = "current" + +["word count"] +one = "{{ .WordCount }} word" +other = "{{ .WordCount }} words" + +["reading time"] +one = "approximately {{ .Count }} minute reading" +other = "approximately {{ .Count }} minutes reading" diff --git a/i18n/fr.toml b/i18n/fr.toml new file mode 100644 index 0000000..563b24a --- /dev/null +++ b/i18n/fr.toml @@ -0,0 +1,13 @@ +["choose language"] +other = "Choisir une autre langue:" + +[current] +other = "actuelle" + +["word count"] +one = "{{ .WordCount }} mot" +other = "{{ .WordCount }} mots" + +["reading time"] +one = "environ {{ .Count }} minute de lecture" +other = "environ {{ .Count }} minutes de lecture" diff --git a/i18n/vi.toml b/i18n/vi.toml new file mode 100644 index 0000000..c327799 --- /dev/null +++ b/i18n/vi.toml @@ -0,0 +1,11 @@ +["choose language"] +other = "Chọn ngôn ngữ khác:" + +[current] +other = "hiện tại" + +["word count"] +other = "{{ .WordCount }} từ" + +["reading time"] +other = "đọc hết khoảng {{ .Count }} phút" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b17f8ce..bd9f83d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -5,7 +5,11 @@ SPDX-License-Identifier: MIT */}} +{{ with .Page.Params.Lang }} + +{{ else }} +{{ end }} {{ block "head" . }} {{ partial "head.html" . }} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index ecac06c..7c774d5 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -11,26 +11,40 @@ SPDX-License-Identifier: MIT {{ if in .Params.categories "book" }}
    + {{ range .Page.Translations | append .Page }} {{ range sort .Pages "Weight" }} -
  1. - {{ trim .Title " " }} - {{ partial "post-language-switcher.html" . }} - {{ partial "post-info.html" . }} -
  2. +
  3. + {{ trim .Title " " }} + {{ partial "post-info.html" . }} +
  4. {{ end }} -
      + {{ end }} +
- {{ else }} + {{ else if in .Params.categories "blog" }}
+
    + {{ range sort .Pages "Date" "desc" }} +
  1. + : + {{ trim .Title " " }} + {{ partial "post-language-switcher.html" . }} + {{ partial "post-info.html" . }} +
  2. + {{ end }}
      +
+ {{ else }} +
+
{{ end }} {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 3dc85e7..d2d60dd 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -8,8 +8,8 @@ SPDX-License-Identifier: MIT

{{ trim .Title " " }}

- {{ .WordCount }} words - ({{ div .WordCount 240}}~{{ div .WordCount 180}} minutes reading) + {{ i18n "word count" . }} + ({{ i18n "reading time" .ReadingTime }}) {{ partial "post-language-switcher.html" . }} {{ partial "post-navigation.html" . }} diff --git a/layouts/index.html b/layouts/index.html index 07fbc94..5a9c4ed 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,10 +1,8 @@ {{ define "main" }} -
- {{ .Content }} - -
+{{ .Content }} + {{ end }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 619beab..341bed7 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -5,10 +5,9 @@ SPDX-License-Identifier: MIT */}}