From 238f84de305c629d225610bf1b73bf3d018bf9e0 Mon Sep 17 00:00:00 2001 From: daudix Date: Thu, 20 Jun 2024 19:24:31 +0300 Subject: [PATCH] Make dates respect current locale (deprecations!) And make comments use it in a smart way (it's not but it works) Deprecate "extra.date_format" and "extra.comments.locale" and replace it with "date_format" and "date_locale" in translation files --- config.toml | 18 +++++++----------- content/demo/code.ar.md | 3 +++ content/demo/code.ru.md | 3 +++ content/demo/comments.ar.md | 8 ++++++++ content/demo/comments.ru.md | 8 ++++++++ content/demo/page.ar.md | 4 ++++ content/demo/page.ru.md | 4 ++++ i18n/ar.toml | 15 ++++++++------- i18n/en.toml | 10 ++++++++-- i18n/ru.toml | 10 ++++++++-- templates/article.html | 4 +++- templates/article_list.html | 4 +++- templates/partials/comments.html | 2 +- templates/partials/language_switcher.html | 3 +-- templates/taxonomy_single.html | 4 +++- theme.toml | 3 --- 16 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 content/demo/code.ar.md create mode 100644 content/demo/code.ru.md create mode 100644 content/demo/comments.ar.md create mode 100644 content/demo/comments.ru.md create mode 100644 content/demo/page.ar.md create mode 100644 content/demo/page.ru.md diff --git a/config.toml b/config.toml index a005249..c7600bc 100644 --- a/config.toml +++ b/config.toml @@ -9,10 +9,15 @@ feed_filename = "atom.xml" build_search_index = false author = "Duck Quack" -# To translate the entire theme, there must be a file with the same ISO 639-1 -# (or IETF BCP 47) Code in the `i18n` folder of your site or the Duckquill theme +# Based on https://github.com/welpo/tabi +# +# To translate the entire theme, there must be a file with the same ISO 639-1 or BCP 47 +# language code in the `i18n` directory of your site or the Duckquill theme. # For example, "i18n/fr.toml" for French or "i18n/zh-Hans.toml" for Simplified Chinese. # Otherwise the theme will be in English. +# +# ISO 639-1: https://localizely.com/iso-639-1-list/ +# BCP 47: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry default_language = "en" taxonomies = [{ name = "tags", feed = true }] @@ -51,11 +56,6 @@ primary_color_alpha = "rgba(255, 120, 0, 0.2)" emoji_favicon = false # Whether the favicon is an animated GIF or not animated_favicon = false -# Tera Date format used when listing posts -# (post publication date, tag posts list...). -# Not used in comments. -# See https://docs.rs/chrono/0.4.31/chrono/format/strftime/index.html -date_format = "%d %B %Y" # URL to website's issue tracker issues_url = "https://codeberg.org/daudix/duckquill/issues" # URL to website's source code @@ -134,10 +134,6 @@ host = "vmst.io" user = "daudix" # Whether to show the QR code to Mastodon post show_qr = true -# BCP 47 locale used for comment timestamps; -# See https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry -# Default: "en-IE" -# locale = "YOUR_LOCALE" # GoatCounter analytics; enabled only if present in config. [extra.goatcounter] diff --git a/content/demo/code.ar.md b/content/demo/code.ar.md new file mode 100644 index 0000000..813e390 --- /dev/null +++ b/content/demo/code.ar.md @@ -0,0 +1,3 @@ ++++ +title = "Code Block Demo (العربية)" ++++ diff --git a/content/demo/code.ru.md b/content/demo/code.ru.md new file mode 100644 index 0000000..be7dc38 --- /dev/null +++ b/content/demo/code.ru.md @@ -0,0 +1,3 @@ ++++ +title = "Code Block Demo (Русский)" ++++ diff --git a/content/demo/comments.ar.md b/content/demo/comments.ar.md new file mode 100644 index 0000000..7bc93f4 --- /dev/null +++ b/content/demo/comments.ar.md @@ -0,0 +1,8 @@ ++++ +template = "article.html" +title = "ActivityPub/​Fediverse comments demo (العربية)" +[extra.comments] +host = "toot.community" +user = "sungsphinx" +id = "111784580759701190" ++++ diff --git a/content/demo/comments.ru.md b/content/demo/comments.ru.md new file mode 100644 index 0000000..791b03c --- /dev/null +++ b/content/demo/comments.ru.md @@ -0,0 +1,8 @@ ++++ +template = "article.html" +title = "ActivityPub/​Fediverse comments demo (Русский)" +[extra.comments] +host = "toot.community" +user = "sungsphinx" +id = "111784580759701190" ++++ diff --git a/content/demo/page.ar.md b/content/demo/page.ar.md new file mode 100644 index 0000000..774f301 --- /dev/null +++ b/content/demo/page.ar.md @@ -0,0 +1,4 @@ ++++ ++++ + +# Welcome to the cake party (العربية) diff --git a/content/demo/page.ru.md b/content/demo/page.ru.md new file mode 100644 index 0000000..68160e4 --- /dev/null +++ b/content/demo/page.ru.md @@ -0,0 +1,4 @@ ++++ ++++ + +# Welcome to the cake party (Русский) diff --git a/i18n/ar.toml b/i18n/ar.toml index 59a3add..315de82 100644 --- a/i18n/ar.toml +++ b/i18n/ar.toml @@ -1,10 +1,11 @@ -# Hello, the Arabic language has many pronouns and words, and each word indicates a different meaning, -# unlike the English language, in which, on the other hand, the word can refer to a person and a group. -# This translation is for individual use, if you are a company or organization, I have put a comment in -# front of each translation that refers to the person and the other word that refers to the organization - -language_name = "العربية" # Shown in language picker for multi-language sites. -date_locale = "ar-SA" # The locale code for time and date formatting. +# Shown in language picker for multi-language sites +language_name = "العربية" +# Tera date format used for listing posts +# (post publication date, tag posts list...). +# Not used in comments, "date_locale" is used instead. +# See https://docs.rs/chrono/0.4.31/chrono/format/strftime/index.html +date_format = "%d %B %Y" +date_locale = "ar_SA" # Menu items. # Should match the names in config.extra.nav.links and config.extra.footer.links. diff --git a/i18n/en.toml b/i18n/en.toml index 5d4fc7d..ddb1a80 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -1,5 +1,11 @@ -language_name = "English" # Shown in language picker for multi-language sites. -date_locale = "en-GB" +# Shown in language picker for multi-language sites +language_name = "English" +# Tera date format used for listing posts +# (post publication date, tag posts list...). +# Not used in comments, "date_locale" is used instead. +# See https://docs.rs/chrono/0.4.31/chrono/format/strftime/index.html +date_format = "%d %B %Y" +date_locale = "en_IE" # Menu items. # Should match the names in config.extra.nav.links and config.extra.footer.links. diff --git a/i18n/ru.toml b/i18n/ru.toml index b6e5fa9..d9eff6d 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -1,5 +1,11 @@ -language_name = "Русский" # Shown in language picker for multi-language sites. -date_locale = "ru-RU" +# Shown in language picker for multi-language sites +language_name = "Русский" +# Tera date format used for listing posts +# (post publication date, tag posts list...). +# Not used in comments, "date_locale" is used instead. +# See https://docs.rs/chrono/0.4.31/chrono/format/strftime/index.html +date_format = "%d %B %Y г." +date_locale = "ru_RU" # Note on pluralization prefixes: # - few_: for numbers ending in 2-4, except 12-14, in genitive singular. diff --git a/templates/article.html b/templates/article.html index 77a3231..aafc7dd 100644 --- a/templates/article.html +++ b/templates/article.html @@ -1,13 +1,15 @@ {% extends "base.html" %} {% block content %} +{% set date_format = macros_translate::translate(key="date_format", default="%d %B %Y", language_strings=language_strings) %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en_IE", language_strings=language_strings) %}

{{ page.title }}

{%- if page.date %} {%- if page.authors %} diff --git a/templates/article_list.html b/templates/article_list.html index 1348a6d..c8c8f31 100644 --- a/templates/article_list.html +++ b/templates/article_list.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% block content %} +{% set date_format = macros_translate::translate(key="date_format", default="%d %B %Y", language_strings=language_strings) %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en_IE", language_strings=language_strings) %}

{{ section.title }}

{{ section.description | markdown | safe }} @@ -35,7 +37,7 @@ {%- if page.date %} {%- if page.authors %} diff --git a/templates/partials/comments.html b/templates/partials/comments.html index b746613..1283abc 100644 --- a/templates/partials/comments.html +++ b/templates/partials/comments.html @@ -13,7 +13,7 @@ {% endif %} {% set id = page.extra.comments.id %} -{% set date_locale = macros_translate::translate(key="date_locale", default="en-GB", language_strings=language_strings) %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en-IE", language_strings=language_strings) | replace(from="_", to="-") %}
{% if config.extra.comments.show_qr %} diff --git a/templates/partials/language_switcher.html b/templates/partials/language_switcher.html index 3c3a7c8..38ca47f 100644 --- a/templates/partials/language_switcher.html +++ b/templates/partials/language_switcher.html @@ -18,8 +18,7 @@ {%- set other_language_strings = load_data(path="themes/tabi/i18n/" ~ lcode ~ ".toml", required=false) -%} {%- endif -%} {#- Use the loaded language strings to get the language name -#} - {% set language_name = macros_translate::translate(key="language_name", default=lcode, - language_strings=other_language_strings) %} + {% set language_name = macros_translate::translate(key="language_name", default=lcode, language_strings=other_language_strings) %} {#- Check if the language code matches the default language -#} {%- if lcode == config.default_language -%} {#- If it does, link to the root path (no language code in URL) -#} diff --git a/templates/taxonomy_single.html b/templates/taxonomy_single.html index fd6ee92..12c9f34 100644 --- a/templates/taxonomy_single.html +++ b/templates/taxonomy_single.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% block content %} +{% set date_format = macros_translate::translate(key="date_format", default="%d %B %Y", language_strings=language_strings) %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en_IE", language_strings=language_strings) %} {% set number_of_posts = term.pages | length %}

{{ macros_translate::translate(key="posts_with_tag", default="Posts with tag", language_strings=language_strings) }} “{{ term.name }}”

@@ -34,7 +36,7 @@ {%- if page.date %} {%- if page.authors %} diff --git a/theme.toml b/theme.toml index 24d8b35..c07ff9a 100644 --- a/theme.toml +++ b/theme.toml @@ -8,9 +8,6 @@ demo = "https://daudix.codeberg.page/duckquill" [extra] primary_color = "#9a9996" primary_color_alpha = "rgba(154, 153, 150, 0.2)" -date_format = "%d %B %Y" -issues_url = "" -source_url = "" [author] name = "David Lapshin"