Hi i'm using Pelican/Python for building a small static multilanguage site.
With i18n_subsites plugin I can add language buttons that shows other available languages on top of my site.
Is there any way to specify links on these language buttons to current page (article) translation? Not for main page? It will be good to stay on the same page (article).
Any help would be greatly appreciated.
May be it will be useful for someone else.
This is tempating issue. Many thanks to smartass101
You could do something like this:
{% if lang_siteurls %}
{% for lang, url in lang_siteurls.items() %}
<li{% if lang == DEFAULT_LANG %} class="active"{% endif %}>
<a href={% if article and lang != DEFAULT_LANG %}"{{ SITEURL }}/{{ article | extract_trans(lang, url) }}"
{% elif article %}"{{ SITEURL }}/{{ article.url }}"
{% elif page and lang != DEFAULT_LANG %}"{{ SITEURL }}/{{ page | extract_trans(lang, url) }}"
{% elif page %}"{{ SITEURL }}/{{ page.url }}"
{% else %}"{{ url }}"{% endif %}>{{ lang }}</a></li>
{% endfor %}
<!-- separator -->
<li style="background-color: white; padding: 5px;"> </li>
{% endif %}
where the filter is defined as
def extract_trans(article, lang, url):
for trans in article.translations:
if trans.lang == lang:
return trans.url
return url
and included using the JINJA_FILTERS setting. This code works for me for all pages and articles with exception of archives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With