From f5d32f6032ea172d0f1076b1fa04c96c9205285b Mon Sep 17 00:00:00 2001 From: Jieiku Date: Tue, 26 Sep 2023 18:46:53 -0700 Subject: i18n translation system refactor --- templates/404.html | 5 ++++- templates/base.html | 26 +++++++++++++++++--------- templates/categories/list.html | 2 +- templates/index.html | 2 +- templates/macros/macros.html | 41 ++++++++++++++++++++++++++--------------- templates/page.html | 20 ++++++++++---------- templates/tags/list.html | 2 +- 7 files changed, 60 insertions(+), 38 deletions(-) (limited to 'templates') diff --git a/templates/404.html b/templates/404.html index 07f32b3..fee5607 100644 --- a/templates/404.html +++ b/templates/404.html @@ -26,7 +26,10 @@ {# Iterate through each language and display the localised 404 message #} {%- for lcode, language in config.languages -%} {%- if lcode != config.default_language -%} -
{{ trans(key="404_not_found", lang=lcode) }}. {% if config.build_search_index %}{{ trans(key="404_try_search", lang=lcode) }}{% endif %} {{ trans(key="404_go_home", lang=lcode) }}.
+ {%- set i18n_404 = load_data(path="i18n/" ~ lcode ~ '.toml', required=false) -%} + {%- if not i18n_404 -%}{%- set i18n_404 = load_data(path="themes/abridge/i18n/" ~ lcode ~ ".toml", required=false) -%}{%- endif %} + +{{ macros::translate(key="404_not_found", default="404_not_found", i18n=i18n_404) }}{{ macros::translate(key="full_stop", default=".", i18n=i18n_404) }} {% if config.build_search_index %}{{ macros::translate(key="404_try_search", default="Try searching or", i18n=i18n_404) }}{% endif %} {{ macros::translate(key="404_go_home", default="go to homepage", i18n=i18n_404) }}{{ macros::translate(key="full_stop", default=".", i18n=i18n_404) }}
{%- endif -%} {%- endfor -%} diff --git a/templates/base.html b/templates/base.html index b1172a9..72a5204 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,5 +1,9 @@ {%- import 'macros/seo.html' as macros_seo %} {%- import "macros/macros.html" as macros %} +{# Load current language i18n data from .toml files in user's '/i18n' folder, use theme as fallback. #} +{%- set i18n = load_data(path="i18n/" ~ lang ~ '.toml', required=false) -%} +{%- if not i18n -%}{%- set i18n = load_data(path="themes/abridge/i18n/" ~ lang ~ ".toml", required=false) -%}{%- endif %} + {%- set uglyurls = config.extra.uglyurls | default(value=false) -%} {%- if config.extra.offline %}{% set uglyurls = true %}{% endif %} @@ -52,7 +56,7 @@ {%- if config.extra.menu %} {%- for i in config.extra.menu -%}{% for term in terms %} [{{ term.name }}]{{ term.pages | length }} {% endfor %}