From 67caafd848f65ad354dfbf2ac0f1df9b17704255 Mon Sep 17 00:00:00 2001 From: welpo Date: Fri, 1 Sep 2023 23:14:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(translation):=20s?= =?UTF-8?q?treamline=20translation=20logic=20with=20macro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/feed_style.xsl | 2 +- templates/404.html | 2 +- templates/archive.html | 6 +--- templates/atom.xml | 20 ++++++------ templates/base.html | 1 + templates/macros/add_comments.html | 2 +- templates/macros/content.html | 19 ++++++------ templates/macros/format_date.html | 6 +--- templates/macros/list_posts.html | 5 ++- templates/macros/paginate.html | 10 +++--- templates/macros/set_title.html | 6 +--- templates/macros/table_of_contents.html | 2 +- templates/macros/translate.html | 14 +++++++++ templates/partials/footer.html | 26 +++++----------- templates/partials/nav.html | 12 ++------ templates/shortcodes/multilingual_quote.html | 32 +++++++------------- templates/tags/list.html | 10 ++---- templates/tags/single.html | 2 +- 18 files changed, 74 insertions(+), 103 deletions(-) create mode 100644 templates/macros/translate.html diff --git a/static/feed_style.xsl b/static/feed_style.xsl index b0fb06be3..025ae81f3 100644 --- a/static/feed_style.xsl +++ b/static/feed_style.xsl @@ -19,7 +19,7 @@
- , . . About Feeds . . + , . . About Feeds . .
diff --git a/templates/archive.html b/templates/archive.html index 726d36880..fa2beda3f 100644 --- a/templates/archive.html +++ b/templates/archive.html @@ -5,11 +5,7 @@ {{ macros_page_header::page_header(title=section.title) }} {# Set locale for date #} -{%- if lang != config.default_language %} - {% set date_locale = trans(key="date_locale" | safe, lang=lang) %} -{% else %} - {% set date_locale = "en_GB" %} -{% endif %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en_GB") %}
    diff --git a/templates/atom.xml b/templates/atom.xml index 2bb2a8ed3..241e47266 100644 --- a/templates/atom.xml +++ b/templates/atom.xml @@ -1,34 +1,36 @@ +{% import "macros/translate.html" as macros_translate %} + {# This section stores the strings/translations for the stylised feed. If the translation is not found, the default English text will be used. #} - {%- if lang != config.default_language -%} {{ trans(key="this_is_a_web_feed" | safe, lang=lang) }} {%- else -%} This is a web feed {%- endif -%} + {{- macros_translate::translate(key="this_is_a_web_feed", default="This is a web feed") -}} - {%- if lang != config.default_language -%} {{ trans(key="also_known_as_an_Atom_feed" | safe, lang=lang) }} {%- else -%} also known as an Atom feed {%- endif -%} + {{- macros_translate::translate(key="also_known_as_an_Atom_feed", default="also known as an Atom feed") -}} - {%- if lang != config.default_language -%} {{ trans(key="subscribe" | safe, lang=lang) }} {%- else -%} Subscribe {%- endif -%} + {{- macros_translate::translate(key="subscribe", default="Subscribe") -}} - {%- if lang != config.default_language -%} {{ trans(key="by_copying_the_URL_from_the_address_bar_into_your_newsreader" | safe, lang=lang) }} {%- else -%} by copying the URL from the address bar into your newsreader {%- endif -%} + {{- macros_translate::translate(key="by_copying_the_URL_from_the_address_bar_into_your_newsreader", default="by copying the URL from the address bar into your newsreader") -}} - {%- if lang != config.default_language -%} {{ trans(key="visit" | safe, lang=lang) }} {%- else -%} Visit {%- endif -%} + {{- macros_translate::translate(key="visit", default="Visit") -}} - {%- if lang != config.default_language -%} {{ trans(key="to_learn_more_and_get_started" | safe, lang=lang) }} {%- else -%} to learn more and get started {%- endif -%} + {{- macros_translate::translate(key="to_learn_more_and_get_started", default="to learn more and get started") -}} - {%- if lang != config.default_language -%} {{ trans(key="it_s_free" | safe, lang=lang) }} {%- else -%} It's free {%- endif -%} + {{- macros_translate::translate(key="it_s_free", default="It's free") -}} - {%- if lang != config.default_language -%} {{ trans(key="website" | safe, lang=lang) }} {%- else -%} website {%- endif -%} + {{- macros_translate::translate(key="website", default="website") -}} - {%- if lang != config.default_language -%} {{ trans(key="recent_posts" | safe, lang=lang) }} {%- else -%} Recent posts {%- endif -%} + {{- macros_translate::translate(key="recent_posts", default="Recent posts") -}} diff --git a/templates/base.html b/templates/base.html index b8fc4da86..067e69215 100644 --- a/templates/base.html +++ b/templates/base.html @@ -11,6 +11,7 @@ {% import "macros/set_title.html" as macros_set_title %} {% import "macros/settings.html" as macros_settings %} {% import "macros/table_of_contents.html" as macros_toc %} +{% import "macros/translate.html" as macros_translate %} {% else %} - + {% endif %} diff --git a/templates/macros/content.html b/templates/macros/content.html index 3d7d6f57c..8ee39594d 100644 --- a/templates/macros/content.html +++ b/templates/macros/content.html @@ -54,7 +54,7 @@
      {% if page.draft %} -
    • {%- if lang != config.default_language %} {{ trans(key="draft" | safe, lang=lang) }} {% else %} DRAFT {% endif %}
    • +
    • {{ macros_translate::translate(key="draft", default="DRAFT") }}
    • {% endif %} {% if page.date %} @@ -63,25 +63,26 @@ {# page settings override config settings #} {% if macros_settings::evaluate_setting_priority(setting="show_reading_time", page=page, default_global_value=true) == "true" %} - {{ separator }}
    • {{ page.reading_time }}{%- if lang != config.default_language %} {{ trans(key="min_read" | safe, lang=lang) }} {% else %} min read {% endif %}
    • + {{ separator }}
    • {{ page.reading_time }} {{ macros_translate::translate(key="min_read", default="min read") }}
    • {% endif %} - {% if page.taxonomies and page.taxonomies.tags %} -
    •  {{ separator }} {%- if lang != config.default_language -%}{{ trans(key="tags" | safe, lang=lang) | capitalize }}{% else %}Tags{%- endif -%}: 
    • - {% for tag in page.taxonomies.tags %} + {%- if page.taxonomies and page.taxonomies.tags -%} + {{ separator }} 
    • {{- macros_translate::translate(key="tags", default="tags") | capitalize -}}: 
    • + {%- for tag in page.taxonomies.tags -%}
    • {{ tag }} {%- if not loop.last -%} ,  {%- endif -%}
    • - {% endfor %} - {% endif %} + {%- endfor -%} + {%- endif -%} {% if page.updated %} -
    • {%- if lang != config.default_language %} {{ trans(key="last_updated_on" | safe, lang=lang) }} {% else %} Last updated on {% endif %} {{ macros_format_date::format_date(date=page.updated, short=true) }}
    • +
    diff --git a/templates/macros/format_date.html b/templates/macros/format_date.html index 74e4c9838..1d7ba25ac 100644 --- a/templates/macros/format_date.html +++ b/templates/macros/format_date.html @@ -1,11 +1,7 @@ {% macro format_date(date, short) %} {# Set locale #} -{%- if lang != config.default_language %} - {% set date_locale = trans(key="date_locale" | safe, lang=lang) %} -{% else %} - {% set date_locale = "en_GB" %} -{% endif %} +{% set date_locale = macros_translate::translate(key="date_locale", default="en_GB") %} {% if config.extra.short_date_format and short %} {{ date | date(format=config.extra.short_date_format, locale=date_locale) }} diff --git a/templates/macros/list_posts.html b/templates/macros/list_posts.html index bba9aca39..ad3e980fa 100644 --- a/templates/macros/list_posts.html +++ b/templates/macros/list_posts.html @@ -37,15 +37,14 @@

    {{ post.summary | striptags | safe | trim_end_matches(pat=".") }}…

    {% endif %}
- - {%- if lang != config.default_language %} {{ trans(key="read_more" | safe, lang=lang) }} {% else %} Read more {% endif %}→ + {{ macros_translate::translate(key="read_more", default="Read more") }} →
{% endif %} {% if not loop.last %} {% if loop.index == max %}
- {%- if lang != config.default_language %} {{ trans(key="all_posts" | safe, lang=lang) }} {% else %} All posts {% endif %}⟶ + {{ macros_translate::translate(key="all_posts", default="All posts") }} ⟶
{% endif %} {% endif %} diff --git a/templates/macros/paginate.html b/templates/macros/paginate.html index 9eb43e6d9..9d649f959 100644 --- a/templates/macros/paginate.html +++ b/templates/macros/paginate.html @@ -4,25 +4,25 @@ diff --git a/templates/macros/set_title.html b/templates/macros/set_title.html index 99578d8f8..fffdb2862 100644 --- a/templates/macros/set_title.html +++ b/templates/macros/set_title.html @@ -26,11 +26,7 @@ {%- set suffix = term.name -%} {% elif taxonomy.name %} {# List of tags. #} - {%- if lang != config.default_language -%} - {%- set suffix = trans(key=taxonomy.name | safe, lang=lang) | capitalize -%} - {% else %} - {%- set suffix = taxonomy.name | capitalize -%} - {% endif %} + {%- set suffix = macros_translate::translate(key=taxonomy.name) | capitalize -%} {% else %} {%- set suffix = "404" %} {%- endif -%} diff --git a/templates/macros/table_of_contents.html b/templates/macros/table_of_contents.html index abd0140af..d355b9bfd 100644 --- a/templates/macros/table_of_contents.html +++ b/templates/macros/table_of_contents.html @@ -8,7 +8,7 @@
{% if header %} -

{%- if lang != config.default_language %} {{ trans(key="table_of_contents" | safe, lang=lang) }} {% else %} Table of Contents {% endif %}

+

{{ macros_translate::translate(key="table_of_contents", default="Table of Contents") }}

{% endif %}