Simpler i18n

master
southerntofu 3 years ago
parent 88dd168707
commit 88ed7ae7b2
  1. 2
      config.toml
  2. 2
      templates/index.html
  3. 2
      templates/page.html
  4. 8
      templates/section.html
  5. 27
      templates/widgets.html

@ -11,6 +11,8 @@ highlight_code = false
# Whether to build a search index to be used later on by a JavaScript library
build_search_index = false
default_language = "en"
languages = [
{code = "fr", rss = true}
]

@ -26,7 +26,7 @@
<footer>
{% if config.extra.forge %}
<aside class="source">
{% set translated = widgets::i18n(key="source") %}
{% set translated = trans(key="source", lang=lang) %}
{% if section %}
<a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a>
{% else %}

@ -7,7 +7,7 @@
<div>
<h1 class="p-name">{{ page.title }}</h1>
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=trans(key="dateFormat", lang=lang)) }}</time>{%- endif -%}
</div>
<div class="e-content">{{ page.content | safe }}</div>
</article>

@ -11,12 +11,12 @@
<article>
<div>
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=trans(key="dateFormat", lang=lang)) }}</time>{%- endif -%}
</div>
{% if page.summary %}
<div class="p-summary e-content">
{{ page.summary | markdown | safe }}
<a class="read-more" href="{{ page.permalink }}">--> {{ widgets::i18n(key="readmore") }} <--</a>
<a class="read-more" href="{{ page.permalink }}">--> {{ trans(key="readmore", lang=lang) }} <--</a>
</div>
{% else %}
<div class="e-content">
@ -28,10 +28,10 @@
{% if paginator and paginator.number_pagers > 1 %}
<aside class="pagination">
{% if paginator.previous %}
<a href="{{ paginator.previous }}"><--&nbsp;&nbsp;{{ widgets::i18n(key="previousPage") }}</a>
<a href="{{ paginator.previous }}"><--&nbsp;&nbsp;{{ trans(key="previousPage", lang=lang) }}</a>
{% endif %}
{% if paginator.next %}
<a href="{{ paginator.next }}">{{ widgets::i18n(key="nextPage") }}&nbsp;&nbsp;--></a>
<a href="{{ paginator.next }}">{{ trans(key="nextPage", lang=lang) }}&nbsp;&nbsp;--></a>
{% endif %}
</aside>
{% endif %}

@ -17,25 +17,28 @@ a submenu. A submenu is an actual list
######################################}
{% macro menu(content) %}
<nav class="nav-menu" role="navigation">
{%- set source = get_page(path=self::i18n_page(page=content)) %}{% set entries = source.content | split(pat="<hr />") %}{# fetch page content and divide it with separator -#}
{%- for entry in entries %}
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}{# strip paragraph tags away for nicer markup #}
{%- endfor %}
{%- set source = self::i18n_content(path=content) -%}
{% set entries = source | split(pat="<hr />") %}
{#- fetch page content and divide it with separator -#}
{%- for entry in entries %}
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}
{# strip paragraph tags away for nicer markup #}
{%- endfor %}
</nav>
{% endmacro menu %}
{%- macro i18n(key) -%}
{{ trans(key=key, lang=lang) }}
{%- endmacro i18n -%}
{%- macro i18n_page(page) -%}
{% if lang == "en" %}{{ page }}
{%- macro i18n_path(path) -%}
{% if lang == "en" %}{{ path }}
{%- else -%}
{%- set parts = page | split(pat=".md") -%}
{%- set parts = path | split(pat=".md") -%}
{%- for part in parts -%}
{%- if part and not loop.first -%}.md{%- endif -%}
{%- if not loop.last -%}{{ part }}{%- endif -%}
{%- endfor -%}
.{{ lang }}.md
{%- endif -%}
{%- endmacro i18n_page -%}
{%- endmacro i18n_path -%}
{%- macro i18n_content(path) -%}
{{ get_page(path=self::i18n_path(path=path)) | get(key="content") }}
{%- endmacro i18n_content -%}

Loading…
Cancel
Save