Support partial site translations

Now only some pages can be translated. It won't break anything, and will be
propertly displayed. The only requirement is to add a few localized strings
for a new language into config.toml

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2022-11-26 17:20:38 +01:00 committed by Alexander Borsuk
parent 4d6c6482d8
commit 9f5ade2db0
4 changed files with 38 additions and 58 deletions

View file

@ -25,18 +25,14 @@ stripe = "https://donate.organicmaps.app/"
# Default English translation
[translations]
address = "Address"
back = "Back to News"
contact = "Contact Us"
donate = "Donate"
home = "Home"
back = "Back to News"
contact = "Contact Us"
install-appgallery = "Install Organic Maps from Huawei AppGallery"
install-appstore = "Install Organic Maps from the AppStore"
install-googleplay = "Install Organic Maps from Google Play"
install-fdroid="Install Organic Maps from F-Droid"
language = "English"
name = "Name"
news = "News"
support-us = "Support Us"
token = "Token"
# Please sort all other translation sections and values in alphabetical order.
@ -45,16 +41,12 @@ token = "Token"
address = "Adresse"
back = "Zurück zu Neuigkeiten"
contact = "Kontakt"
donate = "Spenden"
home = "Startseite"
install-appgallery = "Organic Maps aus der Huawei AppGallery installieren"
install-appstore = "Installiere Organic Maps aus dem AppStore"
install-googleplay = "Organic Maps von Google Play installieren"
install-fdroid="Organic Maps von F-Droid installieren"
language = "Deutsch"
name = "Name"
news = "Neuigkeiten"
support-us = "Beitragen"
token = "Token"
[languages.it]
@ -62,16 +54,12 @@ token = "Token"
address = "Indirizzo"
back = "Indietro"
contact = "Contattaci"
donate = "Dona"
home = "Pagina Iniziale"
install-appgallery = "Installa Organic Maps da Huawei AppGallery"
install-appstore = "Installa Organic Maps dall'AppStore"
install-fdroid="Installa Organic Maps da F-Droid"
install-googleplay = "Installa Organic Maps da Google Play"
language = "Italiano"
name = "Nome"
news = "Notizie"
support-us = "Contribuisci"
token = "Token"
[languages.pl]
@ -79,48 +67,36 @@ token = "Token"
address = "Adres"
back = "Z powrotem"
contact = "Kontakt"
donate = "Wspomóż"
home = "Strona główna"
install-appgallery = "Zainstaluj Organic Maps z Huawei AppGallery"
install-appstore = "Zainstaluj Organic Maps z App Store"
install-fdroid="Zainstaluj Organic Maps z F-Droid"
install-googleplay = "Zainstaluj Organic Maps z Google Play"
name = "Nazwa"
news = "Wiadomości"
language = "Polski"
support-us = "Przyczyń się"
token = "Token"
[languages.ru]
[languages.ru.translations]
address = "Адрес"
back = "Назад"
contact = "Связаться с нами"
donate = "Поддержать деньгами"
home = "Главная"
contact = "Связаться с нами"
install-appgallery = "Установить Organic Maps из Huawei AppGallery"
install-appstore = "Установить Organic Maps из Apple AppStore"
install-fdroid="Установить Organic Maps из F-Droid"
install-googleplay = "Установить Organic Maps из Google Play"
name = "Название"
news = "Новости"
language = "Русский"
support-us = "Помочь проекту"
name = "Название"
token = "Токен"
[languages.tr]
[languages.tr.translations]
address = "Adres"
back = "Haberlere geri dön"
contact = "Bize ulaşın"
donate = "Bağış Yapın"
home = "Ana Sayfa"
back = "Haberlere geri dön"
contact = "Bize ulaşın"
install-appgallery = "Organic Maps'i Huawei AppGallery'den İndir"
install-appstore = "Organic Maps'i AppStore'dan İndir"
install-fdroid="Organic Maps'i F-Droid'den İndir"
install-googleplay = "Organic Maps'i Google Play'den İndir"
language = "Türkçe"
name = "İsim"
news = "Haberler"
support-us = "Bizi destekleyin"
token = "Token"

View file

@ -1,17 +1,19 @@
{% set langMd = '.' ~ lang %}
{# TODO: Replace 'en' with config.default_language after upgrading Zola #}
{% if lang == 'en' %}
{% set langMd = '' %}
{% endif %}
{% set home = get_section(path='_index' ~ langMd ~ '.md') %}
{% set news = get_section(path='news/_index' ~ langMd ~ '.md') %}
{% set home = get_section(path='_index.md') %}
{% set news = get_section(path='news/_index.md') %}
<nav id="bottom-menu" role="navigation">
{% for page in [home, news] | concat(with=home.pages) %}
{% set page = page.translations | filter(attribute='lang', value=lang) %}
{% set translated = page.translations | filter(attribute='lang', value=lang) | first %}
{% if translated %}
{% if "_index" in translated.path %}
{% set page = get_section(path=translated.path) %}
{% else %}
{% set page = get_page(path=translated.path) %}
{% endif %}
{% endif %}
{% if page.extra.menu_title %}
{% if resource.path != page.path %}<a href="{{ page.path }}">{% endif %}
{% if resource.path != page.path %}<a href="{{ page.permalink | replace(from=config.base_url, to="") }}">{% endif %}
<span>{{ page.extra.menu_title }}</span>
{%- if resource.path != page.path %}</a>{% endif %}
&nbsp;

View file

@ -17,7 +17,7 @@
{% for translation in resource.translations | sort(attribute="lang") %}
{% if lang != translation.lang %}
<li class="lang-menu-item" role="menuitem">
<a class="lang-menu-link" onclick="return onLanguageClick('{{ translation.lang }}');" href="{{ translation.permalink }}">
<a class="lang-menu-link" onclick="return onLanguageClick('{{ translation.lang }}');" href="{{ translation.permalink | replace(from=config.base_url, to="") }}">
{{ trans(key="language", lang=translation.lang) }}
</a>
</li>

View file

@ -5,27 +5,29 @@
{% endif %}
<nav id="menu" role="navigation">
<a href="{{ langPathPrefix }}/"><span class="top_menu_logo"></span></a>
<span class="top_menu_items">
<span class="top_menu_item{% if '/news/' not in resource.path %}">
<a href="{{ langPathPrefix }}/news/">{% else %}_active">{% endif %}
<span>{{ trans(key='news', lang=lang) }}</span>
{%- if '/news/' not in resource.path %}</a>{% endif %}
</span>
<span class="top_menu_item{% if '/donate/' not in resource.path %}">
<a href="{{ langPathPrefix }}/donate/">{% else %}_active">{% endif %}
<span style="color: red">{{ trans(key='donate', lang=lang) }}</span>
{% if '/donate/' not in resource.path %}</a>{% endif %}
</span>
<span class="top_menu_item{% if '/support-us/' not in resource.path %}">
<a href="{{ langPathPrefix }}/support-us/">{% else %}_active">{% endif %}
<span>{{ trans(key='support-us', lang=lang) }}</span>
{% if '/support-us/' not in resource.path %}</a>{% endif %}
<span>
{% for page in [
get_section(path="news/_index.md"),
get_page(path="donate/index.md"),
get_page(path="support-us/index.md")
] %}
{% set translated = page.translations | filter(attribute='lang', value=lang) | first %}
{% if translated %}
{% if "_index" in translated.path %}
{% set page = get_section(path=translated.path) %}
{% else %}
{% set page = get_page(path=translated.path) %}
{% endif %}
{% endif %}
<span class="top_menu_{{ page.path | split(pat="/") | reverse | nth(n=1) }} top_menu_item{% if page.path != resource.path %}">
<a href="{{ page.permalink | replace(from=config.base_url, to="") }}">{% else %}_active">{% endif %}
<span>{{ page.extra.menu_title }}</span>
{%- if page.path != resource.path %}</a>{% endif %}
</span>
{% endfor %}
<span class="top_menu_item">
<a href="https://github.com/organicmaps/organicmaps" target="_blank" class="github">
<a href="https://github.com/organicmaps/organicmaps" target="_blank" class="top_menu_github">
<span>GitHub</span>
</a>
</span>