From 25ba1159ad5cabfe79c80a40ead158c389a68bef Mon Sep 17 00:00:00 2001 From: Youssif Shaaban Alsager Date: Wed, 24 Aug 2022 05:32:40 +0200 Subject: [PATCH] feat: Add internationalization (i18n) support (#182) --- assets/styles/base.scss | 5 ++- i18n/ar.toml | 65 +++++++++++++++++++++++++++++++++ i18n/en.toml | 65 +++++++++++++++++++++++++++++++++ layouts/404.html | 7 ++-- layouts/_default/baseof.html | 2 +- layouts/_default/section.html | 5 +-- layouts/_default/single.html | 3 +- layouts/_default/taxonomy.html | 7 ++-- layouts/_default/term.html | 5 +-- layouts/partials/backlinks.html | 4 +- layouts/partials/contact.html | 11 ++++-- layouts/partials/darkmode.html | 4 +- layouts/partials/github.html | 2 +- layouts/partials/graph.html | 2 +- layouts/partials/head.html | 39 +++++++++++--------- layouts/partials/header.html | 7 ++-- layouts/partials/recent.html | 2 +- layouts/partials/search.html | 4 +- layouts/partials/toc.html | 2 +- 19 files changed, 189 insertions(+), 52 deletions(-) create mode 100644 i18n/ar.toml create mode 100644 i18n/en.toml diff --git a/assets/styles/base.scss b/assets/styles/base.scss index 2b3d90758..fa1a06c0b 100644 --- a/assets/styles/base.scss +++ b/assets/styles/base.scss @@ -10,11 +10,14 @@ html { scroll-behavior: smooth; &:lang(ar) { - & p, & h1, & h2, & h3, article { + & p, & h1, & h2, & h3, article, header { direction: rtl; text-align: right; } } + & footer > p { + text-align: center !important; + } } .singlePage { diff --git a/i18n/ar.toml b/i18n/ar.toml new file mode 100644 index 000000000..631c07155 --- /dev/null +++ b/i18n/ar.toml @@ -0,0 +1,65 @@ +[404_message] +other = "يبدو أنك ضللت الطريق. هذه الصفحة غير موجودة (أو قد تكون خاصة)." + +[404_back] +other = "↳ العودة للرئيسية." + +[all_posts] +other = "كل منشورات {{.Title}}" + +[last_updated] +other = "آخر تعديل" + +[notes_count] +other = "ملاحظات بهذه التسمية" + +[first_10] +other = "(تعرض أول 10 نتائج فقط)" + +[tag] +other = "التسمية" + +[backlinks] +other = "الروابط الخلفية" + +[no_backlinks] +other = "لا توجد روابط خلفية" + +[home] +other = "الرئيسية" + +[light_mode] +other = "السمة الفاتحة" + +[dark_mode] +other = "السمة الداكنة" + +[edit_source] +other = "تعديل المصدر" + +[interactive_graph] +other = "المخطط التفاعلي" + +[search] +other = "البحث" + +[search_icon] +other = "أيقونة البحث" + +[icon_search] +other = "أيقونة فتح نافذة البحث" + +[recent_notes] +other = "الملاحظات اﻷخيرة" + +[first_3_notes] +other = "أول 3 {{ .notes }}" + +[search_for_something] +other = "ابحث عن شيء ما..." + +[toc] +other = "الفهرس" + +[copyright] +other = "صُمم بواسطة {{ .name }} باستخدام كوارتز، {{ .year }} ©" diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 000000000..b9ce33e6c --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,65 @@ +[404_message] +other = "Hey! You look a little lost. This page doesn't exist (or may be private)." + +[404_back] +other = "↳ Let's get you home." + +[all_posts] +other = "All {{.Title}}" + +[last_updated] +other = "Last updated" + +[notes_count] +other = "notes with this tag" + +[first_10] +other = "showing first 10 results" + +[tag] +other = "Tag" + +[backlinks] +other = "Backlinks" + +[no_backlinks] +other = "No backlinks found" + +[home] +other = "Home" + +[light_mode] +other = "Light Mode" + +[dark_mode] +other = "Dark Mode" + +[edit_source] +other = "Edit Source" + +[interactive_graph] +other = "Interactive Graph" + +[search] +other = "Search" + +[search_icon] +other = "Search Icon" + +[icon_search] +other = "Icon to open search" + +[recent_notes] +other = "Recent Notes" + +[first_3_notes] +other = "first 3 {{ .notes }}" + +[search_for_something] +other = "Search for something..." + +[toc] +other = "Table of Contents" + +[copyright] +other = "Made by {{ .name }} using Quartz, © {{ .year }}" diff --git a/layouts/404.html b/layouts/404.html index 424839502..5607e6345 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,5 +1,5 @@ - + {{ partial "head.html" . }} @@ -7,10 +7,9 @@ {{partial "darkmode.html" .}}

404.

-

Hey! You look a little lost. This page doesn't exist (or may be private).

- ↳ Let's get you home. +

{{ i18n "404_message" }}

+ {{ i18n "404_back" }}
- diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index ccb3b93ac..8754b1f28 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,5 +1,5 @@ - + {{ block "head" . }} {{ end }} diff --git a/layouts/_default/section.html b/layouts/_default/section.html index 96611c4ce..f88b85fce 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -1,5 +1,5 @@ - + {{ partial "head.html" . }} @@ -8,7 +8,7 @@ {{partial "header.html" .}}
-

All {{.Title}}

+

{{ i18n "all_posts" . }}

{{with .Params.description}}

{{.}}

{{end}} @@ -18,5 +18,4 @@ {{partial "contact.html" .}} - diff --git a/layouts/_default/single.html b/layouts/_default/single.html index b4dd6dee1..c59abc87b 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -10,7 +10,7 @@
{{if .Title}}

{{ .Title }}

{{end}}

- Last updated {{ partial "date-fmt.html" .}} + {{ i18n "last_updated" }} {{ partial "date-fmt.html" .}} {{ partial "github.html" . }}

    @@ -24,5 +24,4 @@ {{partial "footer.html" .}} - diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index 7e401ae03..01ec325ac 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -1,5 +1,5 @@ - + {{ partial "head.html" . }} @@ -8,7 +8,7 @@ {{partial "header.html" .}}
    -

    All {{.Title}}

    +

    {{ i18n "all_posts" . }}

    {{with .Params.description}}

    {{.}}

    {{end}} @@ -16,7 +16,7 @@ {{ range .Site.Taxonomies.tags.ByCount }}

    {{ .Page.Title | humanize }}

    -

    {{ .Count }} notes with this tag {{if gt .Count 10}}(showing first 10 results){{end}}

    +

    {{ .Count }} {{ i18n "notes_count" }} {{if gt .Count 10}}({{ i18n "first_10"}}){{end}}

    {{ with ($.Site.GetPage (printf "/tags/%s" .Page.Title)) }} {{partial "page-list.html" (first 10 .Pages.ByLastmod.Reverse)}} @@ -27,5 +27,4 @@ {{partial "contact.html" .}} - diff --git a/layouts/_default/term.html b/layouts/_default/term.html index 79bd4eb05..6bda201bc 100644 --- a/layouts/_default/term.html +++ b/layouts/_default/term.html @@ -1,5 +1,5 @@ - + {{ partial "head.html" . }} @@ -8,7 +8,7 @@ {{partial "header.html" .}}
    -

    Tag: {{ .Title }}

    +

    {{ i18n "tag" }}: {{ .Title }}

    {{with .Params.description}}

    {{.}}

    {{end}} @@ -18,5 +18,4 @@ {{partial "contact.html" .}} - diff --git a/layouts/partials/backlinks.html b/layouts/partials/backlinks.html index 23c9091a5..ae6ea1a8e 100644 --- a/layouts/partials/backlinks.html +++ b/layouts/partials/backlinks.html @@ -1,4 +1,4 @@ -

    Backlinks

    +

    {{ i18n "backlinks" }}

    diff --git a/layouts/partials/contact.html b/layouts/partials/contact.html index e52dc4474..3de7d2c68 100644 --- a/layouts/partials/contact.html +++ b/layouts/partials/contact.html @@ -1,12 +1,17 @@ + +{{ $config := cond (eq $.Site.Language.Lang "en") "config" (printf "config.%s" $.Site.Language.Lang) }} +{{ $data := index $.Site.Data $config }}