From 6b2b8e81e631a1fec44bdb94d5177cf5c56287c9 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sat, 28 May 2022 15:15:11 +0200 Subject: Added multilanguage support --- CHANGELOG.md | 5 ++++ exampleSite/config.toml | 7 ++++++ i18n/en.toml | 38 ++++++++++++++++++++++++++++++ i18n/ru.toml | 38 ++++++++++++++++++++++++++++++ layouts/404.html | 12 +++------- layouts/_default/baseof.html | 13 ++++++---- layouts/_default/home.manifest.webmanifest | 6 +++-- layouts/_default/list.json.json | 2 +- layouts/_default/teaser.html | 3 +-- layouts/dramas/single.html | 2 +- layouts/narratives/single.html | 2 +- layouts/partials/footer.html | 2 +- layouts/partials/mini-toc.html | 3 +-- layouts/partials/post-meta/date.html | 5 ++-- layouts/partials/post-toc-summary.html | 2 +- layouts/partials/sidebar-toc.html | 5 ++-- layouts/poems/single.html | 2 +- layouts/shortcodes/form-contact.html | 7 +++--- theme.toml | 6 +++-- 19 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 i18n/en.toml create mode 100644 i18n/ru.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 3573a4c..13c553d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/sergeyklay/gohugo-theme-ed/compare/v0.1.0...HEAD) +### Added + +- Added multilanguage support +- Added Russian translation + ### Changed - Amend documentation diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 3b82dc0..e2982d9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -1,7 +1,9 @@ +# You may need to change this line for your real project. baseURL = 'https://gohugo-theme-ed.netlify.app/' languageCode = 'en-us' defaultContentLanguage = 'en' + # Keep title short to prevent overflow. # There’s no official guidance on this, but 40 characters for # mobile and 60 for desktop is roughly the sweet spot. @@ -9,8 +11,13 @@ defaultContentLanguage = 'en' # NB: Final title of shareable pages will be this plus the # title of the page. Eg. "Contacts - Ed." title = 'Ed.' + +# You may need to change this line for your real project. theme = ['github.com/sergeyklay/gohugo-theme-ed'] + +# You may need to delete this line for your real project. resourceDir = '../resources' + enableRobotsTXT = true # When using ref or relref to resolve page links and a link cannot diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..5792b4a --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,38 @@ +[home] + other = 'Home' + +[top] + other = 'Return to Top' + +[more] + other = 'Read more...' + +[updated_at] + other = 'Updated at' + +[latest_publications] + other = 'Latest publications' + +[your_name] + other = 'Your name' + +[email_addres] + other = 'Email address' + +[message] + other = 'Message' + +[edited_by] + other = 'Edited by {{ . }}' + +[404_title] + other = 'Page not found' + +[404_description] + other = "Sorry, we've misplaced that URL or it's pointing to something that doesn't exist." + +[404_back] + other = 'Head back home to try finding it again' + +[by] + other = 'by {{ . }}' diff --git a/i18n/ru.toml b/i18n/ru.toml new file mode 100644 index 0000000..102c34d --- /dev/null +++ b/i18n/ru.toml @@ -0,0 +1,38 @@ +[home] + other = 'На главную' + +[top] + other = 'Вернуться наверх' + +[more] + other = 'Далее...' + +[updated_at] + other = 'Обновлено' + +[latest_publications] + other = 'Последние публикации' + +[your_name] + other = 'Ваше имя' + +[email_addres] + other = 'Email' + +[message] + other = 'Сообщение' + +[edited_by] + other = 'Редактор {{ . }}' + +[404_title] + other = 'Страница не найдена' + +[404_description] + other = 'Извините, мы потеряли этот адрес или он указывает на что-то несуществующее.' + +[404_back] + other = 'Вернитесь на главную, чтобы попытаться найти страницу снова' + +[by] + other = '{{ . }}' diff --git a/layouts/404.html b/layouts/404.html index 5584276..1412779 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -3,17 +3,11 @@

404

-

Page not found

+

{{ i18n "404_title" }}

-

- Sorry, we've misplaced that URL or it's pointing to something - that doesn't exist. -

- -

- Head back home to try finding it again. -

+

{{ i18n "404_description" }}

+

{{ i18n "404_back" }} .


diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 355f674..e05a918 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,21 +1,24 @@ - {{- partial "head.html" . -}} + {{ partial "head.html" . }} - {{ if .Params.toc }}{{ partial "sidebar-toc.html" . }}{{ else }}{{ partial "sidebar.html" . }}{{ end }} + {{ if .Params.toc }} + {{ partial "sidebar-toc.html" . }} + {{ else }} + {{ partial "sidebar.html" . }} + {{ end }}

- {{/* TODO: Translate titlle */}} - {{ site.Title }} + {{ site.Title }}
{{ site.Params.tagline }}

- {{- block "main" . }}{{- end }} + {{ block "main" . }}{{ end }}
diff --git a/layouts/_default/home.manifest.webmanifest b/layouts/_default/home.manifest.webmanifest index 0a84c55..c9437df 100644 --- a/layouts/_default/home.manifest.webmanifest +++ b/layouts/_default/home.manifest.webmanifest @@ -5,8 +5,8 @@ "name": {{ site.Title | htmlUnescape | jsonify }}, {{ with site.Params.tagline }}"short_name": {{ . | htmlUnescape | jsonify }},{{ end }} {{ with site.Params.description }}"description": {{ . | htmlUnescape | jsonify }},{{ end }} - {{ with site.LanguageCode }}"lang": {{ . | jsonify }}, - "dir": "ltr", {{/* TODO: Get dir from lang */}}{{ end }} + "lang": "{{ site.LanguageCode | default site.Language.Lang }}",{{ with partialCached "func/GetLanguageDirection" "GetLanguageDirection" }} + "dir": {{ . | jsonify }},{{ end }} "start_url": "/index.html?homescreen=1", "display": "fullscreen", "theme_color": "#ffffff", @@ -28,3 +28,5 @@ }{{ if ne . 512 }},{{ end }}{{- end }} ] } + + diff --git a/layouts/_default/list.json.json b/layouts/_default/list.json.json index 308bd96..30b6f80 100644 --- a/layouts/_default/list.json.json +++ b/layouts/_default/list.json.json @@ -16,7 +16,7 @@ { "version": "https://jsonfeed.org/version/1.1", - "title": {{ (printf "%s" (partial "title.html" .)) | htmlUnescape | jsonify }},{{/* TODO: Translate title */}} + "title": {{ (printf "%s" (partial "title.html" .)) | htmlUnescape | jsonify }}, "home_page_url": {{ printf "%s?utm_source=json_feed" site.BaseURL | absURL | jsonify }}, {{ with .OutputFormats.Get "JSON" }}"feed_url": {{ .Permalink | absURL | jsonify }},{{ end }} {{ with site.Params.description}}"description": {{ site.Params.description | jsonify }},{{ end }} diff --git a/layouts/_default/teaser.html b/layouts/_default/teaser.html index 8e161c1..8edf8b4 100644 --- a/layouts/_default/teaser.html +++ b/layouts/_default/teaser.html @@ -12,8 +12,7 @@ {{- if site.Params.readmore }} {{- if .Truncated }} {{- end }} {{- end }} diff --git a/layouts/dramas/single.html b/layouts/dramas/single.html index dc31717..865a07b 100644 --- a/layouts/dramas/single.html +++ b/layouts/dramas/single.html @@ -1,7 +1,7 @@ {{ define "main" }}

{{ .Params.caption | default .Title }}

- + {{ with .Params.author }}{{ end }} {{ .Content }}
{{ end }} diff --git a/layouts/narratives/single.html b/layouts/narratives/single.html index 030af43..e3dc1b9 100644 --- a/layouts/narratives/single.html +++ b/layouts/narratives/single.html @@ -1,7 +1,7 @@ {{ define "main" }}

{{ .Params.caption | default .Title }}

- + {{ with .Params.author }}{{ end }} {{ .Content }}
{{ end }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 7525a24..654a7a8 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -7,7 +7,7 @@ {{ end }} {{ with .Params.editor }}

- Edited by {{ . }}, + {{ i18n "edited_by" . }}, {{ if not $.Params.Lastmod.IsZero }} {{ $.Params.Lastmod.Format "2006" }} {{ else }} diff --git a/layouts/partials/mini-toc.html b/layouts/partials/mini-toc.html index 4d4d742..629169b 100644 --- a/layouts/partials/mini-toc.html +++ b/layouts/partials/mini-toc.html @@ -12,8 +12,7 @@ {{ $mxPosts := site.Params.recentPostsSize | default 5 }}