From 89d53b05c0a8253ee534ddeed067b3e747e8251b Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 6 Feb 2025 16:15:31 +0800 Subject: refactor(i18n): exploit Hugo's built-in i18n feature --- i18n/en.yml | 9 +++++++++ i18n/zh.yml | 9 +++++++++ layouts/partials/components/comment.html | 12 ++---------- layouts/partials/footer.html | 4 ++-- layouts/partials/scripts.html | 2 +- layouts/section/posts.html | 4 ++-- 6 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 i18n/en.yml create mode 100644 i18n/zh.yml diff --git a/i18n/en.yml b/i18n/en.yml new file mode 100644 index 00000000..03b0384f --- /dev/null +++ b/i18n/en.yml @@ -0,0 +1,9 @@ +lang: en +archivePage: + postCountMonthly: '{{ . }} POSTS' + postCountAnnual: '{{ . }} TOTAL POSTS' +postPage: + commentNotLoaded: if comment is not loaded, please try refreshing +footer: + wordCount: '🪦 {{ . }} words are buried here' + licenseStatement: 'Licensed under {{ . }}' diff --git a/i18n/zh.yml b/i18n/zh.yml new file mode 100644 index 00000000..2fd051f5 --- /dev/null +++ b/i18n/zh.yml @@ -0,0 +1,9 @@ +lang: zh-CN +archivePage: + postCountMonthly: '{{ . }} 篇文章' + postCountAnnual: '共计 {{ . }} 篇文章' +postPage: + commentNotLoaded: 如果评论未加载,请尝试刷新页面 +footer: + wordCount: '🪦 {{ . }} 字在这里死去' + licenseStatement: '以 {{ . }} 协议授权' diff --git a/layouts/partials/components/comment.html b/layouts/partials/components/comment.html index f3cdbded..0058713f 100644 --- a/layouts/partials/components/comment.html +++ b/layouts/partials/components/comment.html @@ -2,11 +2,7 @@

- {{ if eq .Site.Language.Lang "en" }} - if comment is not loaded, please try refreshing - {{ else if eq .Site.Language.Lang "zh" }} - 如果评论未加载,请尝试刷新页面 - {{ end }} + {{ T "postPage.commentNotLoaded" }}

{{ if eq .Site.Language.Lang "zh" }} @@ -23,11 +19,7 @@ data-emit-metadata="0" data-input-position="top" data-theme="preferred_color_scheme" - {{ if eq .Site.Language.Lang "en" }} - data-lang="en" - {{ else if eq .Site.Language.Lang "zh" }} - data-lang="zh-CN" - {{ end }} + data-lang="{{ T "lang" }}" crossorigin="anonymous" async> diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 8f19be9f..acf81efd 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,7 +1,7 @@
diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 9c980c77..95010ada 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -45,7 +45,7 @@ function loadGiscus() { script.setAttribute('data-emit-metadata', '0'); script.setAttribute('data-input-position', 'bottom'); script.setAttribute('data-theme', 'light'); - script.setAttribute('data-lang', 'en'); + script.setAttribute('data-lang', '{{ T "lang" }}'); script.crossOrigin = 'anonymous'; script.async = true; diff --git a/layouts/section/posts.html b/layouts/section/posts.html index 03668a6d..de06b2aa 100644 --- a/layouts/section/posts.html +++ b/layouts/section/posts.html @@ -11,7 +11,7 @@

{{ .Key }} - {{ len .Pages }} TOTAL POSTS + {{ T "archivePage.postCountAnnual" (len .Pages) }}

{{ range .Pages.GroupByDate "January" }} @@ -19,7 +19,7 @@

{{ .Key }} - {{ len .Pages }} POSTS + {{ T "archivePage.postCountMonthly" (len .Pages) }}

    -- cgit v1.2.3