How to create links for all languages ​​at the top of the Pelican site for the current page (article)

Hi, I am using Pelican / Python to create a small static multilingual site.

With the i18n_subsites plugin, I can add language buttons that show other available languages ​​on top of my site.

Is it possible to indicate links on these language buttons to the current translation of a page (article)? Not for the main page? It will be good to stay on one page (article).

Any help would be greatly appreciated. Thank.

+4
source share
1 answer

Maybe it will be useful for someone else.

This is a tempating problem. Thanks a lot smartass101

- :

{% 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;">&nbsp</li>
{% endif %}

def extract_trans(article, lang, url):
for trans in article.translations:
    if trans.lang == lang:
        return trans.url
return url

JINJA_FILTERS. , .

+2

All Articles