-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
103 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
enabled: true | ||
built_in_css: true | ||
translated_urls: true | ||
untranslated_pages_behavior: none | ||
language_display: long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
{% set langobj = grav['language'] %} | ||
{% for key in langswitcher.languages %} | ||
{% if key == langswitcher.current %} | ||
{% set lang_url = page.url is same as('/') ? '' : page.url %} | ||
{% else %} | ||
{% set lang_url = (langobj.getLanguageURLPrefix(key) ~ langswitcher.page_route ~ page.urlExtension ?: '')|rtrim('/') %} | ||
{% endif %} | ||
<link rel="alternate" hreflang="{{ key }}" href="{{ uri.base ~ lang_url ~ uri.params }}" /> | ||
{% set language_obj = grav.language %} | ||
{% for language in langswitcher.languages %} | ||
{% 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 href_url = (url('/', true)|trim('/','right') ~ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query)) %} | ||
|
||
{% if (language_obj.default == language and config.languages.include_default_lang == false) %} | ||
<link rel="alternate" hreflang="x-default" href="{{ href_url }}" /> | ||
{% endif %} | ||
<link rel="alternate" hreflang="{{ language }}" href="{{ href_url }}" /> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
<ul class="langswitcher"> | ||
{% set display_format = display_format ?? config.get('plugins.langswitcher.language_display', 'long') %} | ||
{% for language in langswitcher.languages %} | ||
{% set display_format = display_format ?? config.get('plugins.langswitcher.language_display', 'long') %} | ||
|
||
{% set show_language = true %} | ||
{% if language == langswitcher.current %} | ||
{% set lang_url = page.url %} | ||
{% set active_class = ' active' %} | ||
{% else %} | ||
{% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %} | ||
{% set lang_url = base_lang_url ~ langswitcher.translated_routes[language] ~ page.urlExtension %} | ||
{% 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 = base_lang_url ~ '/' %} | ||
{% set lang_url = url('/') %} | ||
{% elseif untranslated_pages_behavior == 'hide' %} | ||
{% set show_language = false %} | ||
{% endif %} | ||
{% endif %} | ||
{% endif %} | ||
{% set active_class = '' %} | ||
{% endif %} | ||
|
||
{% if show_language %} | ||
<li><a href="{{ lang_url ~ uri.params }}" class="external{{ active_class }}">{% include 'partials/langswitcher-' ~ display_format ~ '.html.twig' %}</a></li> | ||
{% endif %} | ||
{% 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 %} | ||
|
||
{% endfor %} | ||
{% endfor %} | ||
</ul> |