Simpler i18n
parent
88dd168707
commit
88ed7ae7b2
|
@ -11,6 +11,8 @@ highlight_code = false
|
||||||
# Whether to build a search index to be used later on by a JavaScript library
|
# Whether to build a search index to be used later on by a JavaScript library
|
||||||
build_search_index = false
|
build_search_index = false
|
||||||
|
|
||||||
|
default_language = "en"
|
||||||
|
|
||||||
languages = [
|
languages = [
|
||||||
{code = "fr", rss = true}
|
{code = "fr", rss = true}
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<footer>
|
<footer>
|
||||||
{% if config.extra.forge %}
|
{% if config.extra.forge %}
|
||||||
<aside class="source">
|
<aside class="source">
|
||||||
{% set translated = widgets::i18n(key="source") %}
|
{% set translated = trans(key="source", lang=lang) %}
|
||||||
{% if section %}
|
{% if section %}
|
||||||
<a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a>
|
<a href="{{ config.extra.forge.browse }}content/{{ section.path }}_index.md">{{ translated }}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<div>
|
<div>
|
||||||
<h1 class="p-name">{{ page.title }}</h1>
|
<h1 class="p-name">{{ page.title }}</h1>
|
||||||
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
|
<a class="u-url" hidden aria-hidden="true" href="{{ page.permalink }}">Permalink</a>
|
||||||
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅 {{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
|
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅 {{ page.date | date(format=trans(key="dateFormat", lang=lang)) }}</time>{%- endif -%}
|
||||||
</div>
|
</div>
|
||||||
<div class="e-content">{{ page.content | safe }}</div>
|
<div class="e-content">{{ page.content | safe }}</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
<article>
|
<article>
|
||||||
<div>
|
<div>
|
||||||
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
|
<a class="u-url" href="{{ page.permalink }}"><h2>{{ page.title }}</h2></a>
|
||||||
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅 {{ page.date | date(format=widgets::i18n(key="dateFormat")) }}</time>{%- endif -%}
|
{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅 {{ page.date | date(format=trans(key="dateFormat", lang=lang)) }}</time>{%- endif -%}
|
||||||
</div>
|
</div>
|
||||||
{% if page.summary %}
|
{% if page.summary %}
|
||||||
<div class="p-summary e-content">
|
<div class="p-summary e-content">
|
||||||
{{ page.summary | markdown | safe }}
|
{{ 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>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="e-content">
|
<div class="e-content">
|
||||||
|
@ -28,10 +28,10 @@
|
||||||
{% if paginator and paginator.number_pagers > 1 %}
|
{% if paginator and paginator.number_pagers > 1 %}
|
||||||
<aside class="pagination">
|
<aside class="pagination">
|
||||||
{% if paginator.previous %}
|
{% if paginator.previous %}
|
||||||
<a href="{{ paginator.previous }}"><-- {{ widgets::i18n(key="previousPage") }}</a>
|
<a href="{{ paginator.previous }}"><-- {{ trans(key="previousPage", lang=lang) }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if paginator.next %}
|
{% if paginator.next %}
|
||||||
<a href="{{ paginator.next }}">{{ widgets::i18n(key="nextPage") }} --></a>
|
<a href="{{ paginator.next }}">{{ trans(key="nextPage", lang=lang) }} --></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</aside>
|
</aside>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -17,25 +17,28 @@ a submenu. A submenu is an actual list
|
||||||
######################################}
|
######################################}
|
||||||
{% macro menu(content) %}
|
{% macro menu(content) %}
|
||||||
<nav class="nav-menu" role="navigation">
|
<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 -#}
|
{%- 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 %}
|
{%- for entry in entries %}
|
||||||
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}{# strip paragraph tags away for nicer markup #}
|
{{ entry | trim | replace(from="<p>", to="") | replace(from="</p>", to="") | safe }}
|
||||||
|
{# strip paragraph tags away for nicer markup #}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</nav>
|
</nav>
|
||||||
{% endmacro menu %}
|
{% endmacro menu %}
|
||||||
|
|
||||||
{%- macro i18n(key) -%}
|
{%- macro i18n_path(path) -%}
|
||||||
{{ trans(key=key, lang=lang) }}
|
{% if lang == "en" %}{{ path }}
|
||||||
{%- endmacro i18n -%}
|
|
||||||
|
|
||||||
{%- macro i18n_page(page) -%}
|
|
||||||
{% if lang == "en" %}{{ page }}
|
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{%- set parts = page | split(pat=".md") -%}
|
{%- set parts = path | split(pat=".md") -%}
|
||||||
{%- for part in parts -%}
|
{%- for part in parts -%}
|
||||||
{%- if part and not loop.first -%}.md{%- endif -%}
|
{%- if part and not loop.first -%}.md{%- endif -%}
|
||||||
{%- if not loop.last -%}{{ part }}{%- endif -%}
|
{%- if not loop.last -%}{{ part }}{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
.{{ lang }}.md
|
.{{ lang }}.md
|
||||||
{%- endif -%}
|
{%- 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…
Reference in New Issue