Language aware get_page function and and listing all inactive languages

Hello,

I am trying to solve the following two riddles for a multilingual website:

  1. How do I make the get_page function to become language aware?
{% set page = get_page(path="pages/welcome.md") %}
	{{ page.title | safe }}
	{{ page.content | safe }}

English is the default language but there are also pages/welcome.de.md and pages/welcome.pl.md. What needs to be done in order to match the currently active language with the respective language file?

  1. How do I list all inactive languages with a link to the respective starting page?
active language: en
-> list: <a href="base_url/de">de</a> <a href="base_url/pl">pl</a>

or

active language: de
-> list: <a href="base_url">en</a> <a href="base_url/pl">pl</a>

Any help is much appreciated!

I found a solution for the first problem:

{% if lang=="en" %}
	{% set page = get_page(path="pages/welcome.md") %}
		{{ page.title | safe }}
		{{ page.content | safe }}
	{% elif lang=="de" %}
		{% set page = get_page(path="pages/welcome.de.md") %}
		{{ page.title | safe }}
		{{ page.content | safe }}
	{% elif lang=="pl" %}
		{% set page = get_page(path="pages/welcome.pl.md") %}
		{{ page.title | safe }}
		{{ page.content | safe }}
{% endif %}

But I still struggle the second one. So far I have:

{% for t in section.translations %}
	<a href="{{t.permalink|safe}}">{{t.lang| replace(from="{{lang}}", to="")}}</a>
{% endfor %}

But that outputs all languages instead of the inactive ones…

You can pass the lang:

{% set page = get_page(path="pages/welcome.md", lang=lang) %}

The current lang is available as the lang variable. You can iterate on the langs from the config and skip the one where the language code is the same as lang.

1 Like

Thanks! This helped me to figure out this solution:

{% for t in section.translations %}
	{% if t.lang == lang %} {% continue %} {% endif %}
	<a href="{{t.permalink|safe}}">{{t.lang}}</a>
{% endfor %}

Alright, I got it. Everything is solved now for me. Thank you again.