Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 12, 2022
2 parents 9cc3e33 + 4921b7c commit efe1432
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v3.1.0
## 12/12/2022

1. [](#new)
* Using blocks in `partials/langswitcher.html.twig` to make it easier to extend without having to copy the logic

# v3.0.2
## 10/05/2022

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: LangSwitcher
version: 3.0.2
version: 3.1.0
description: LangSwitcher is a [Grav](https://github.com/getgrav/grav) plugin that provides native language text links to switch between [multiple languages](http://learn.getgrav.org/content/multi-language) in Grav **v0.9.30** or greater.
icon: globe
author:
Expand Down
29 changes: 29 additions & 0 deletions templates/partials/langswitcher-logic.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ block('language_block_start') }}
{% set display_format = display_format ?? config.get('plugins.langswitcher.language_display', 'long') %}

{% for language in langswitcher.languages %}
{% set active_class = '' %}
{% set show_language = true %}
{% if language == langswitcher.current %}
{% set active_class = 'active' %}
{% endif %}
{% if langswitcher.translated_routes[language] %}
{% set lang_url = langswitcher.translated_routes[language] ~ page.urlExtension %}
{% else %}
{% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
{% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
{% endif %}
{% set untranslated_pages_behavior = grav.config.plugins.langswitcher.untranslated_pages_behavior %}
{% if untranslated_pages_behavior != 'none' %}
{% set translated_page = langswitcher.translated_pages[language] %}
{% if (not translated_page) or (not translated_page.published) %}
{% if untranslated_pages_behavior == 'redirect' %}
{% set lang_url = url('/') %}
{% elseif untranslated_pages_behavior == 'hide' %}
{% set show_language = false %}
{% endif %}
{% endif %}
{% endif %}
{{ block('language_item') }}
{% endfor %}
{{ block('language_block_end') }}
42 changes: 12 additions & 30 deletions templates/partials/langswitcher.html.twig
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
<ul class="langswitcher">
{% set display_format = display_format ?? config.get('plugins.langswitcher.language_display', 'long') %}

{% for language in langswitcher.languages %}
{% set active_class = '' %}
{% set show_language = true %}
{% if language == langswitcher.current %}
{% set active_class = 'active' %}
{% endif %}
{% if langswitcher.translated_routes[language] %}
{% set lang_url = langswitcher.translated_routes[language] ~ page.urlExtension %}
{% else %}
{% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
{% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
{% endif %}
{% set untranslated_pages_behavior = grav.config.plugins.langswitcher.untranslated_pages_behavior %}
{% if untranslated_pages_behavior != 'none' %}
{% set translated_page = langswitcher.translated_pages[language] %}
{% if (not translated_page) or (not translated_page.published) %}
{% if untranslated_pages_behavior == 'redirect' %}
{% set lang_url = url('/') %}
{% elseif untranslated_pages_behavior == 'hide' %}
{% set show_language = false %}
{% endif %}
{% endif %}
{% endif %}
{% extends 'partials/langswitcher-logic.html.twig' %}

{% if show_language %}
<li><a href="{{ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) }}" class="external {{ active_class }}">{% include 'partials/langswitcher-' ~ display_format ~ '.html.twig' %}</a></li>
{% endif %}
{% block language_block_start %}
<ul class="langswitcher">
{% endblock %}

{% endfor %}
{% block language_block_end %}
</ul>
{% endblock %}

{% block language_item %}
{% if show_language %}
<li><a href="{{ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) }}" class="external {{ active_class }}">{% include 'partials/langswitcher-' ~ display_format ~ '.html.twig' %}</a></li>
{% endif %}
{% endblock %}

0 comments on commit efe1432

Please sign in to comment.