diff --git a/plugins/langswitcher/CHANGELOG.md b/plugins/langswitcher/CHANGELOG.md new file mode 100644 index 0000000..165780c --- /dev/null +++ b/plugins/langswitcher/CHANGELOG.md @@ -0,0 +1,118 @@ +# v3.0.2 +## 10/05/2022 + +1. [](#new) + * Require Grav `1.7.37` to make use of the new `Pages::getSimplePagesHash()` method + * Added caching to `translated_routes` so translation work is only performed on the first load, resulting in faster subsequent page loads + +# v3.0.1 +## 08/19/2022 + +1. [](#bugfix) + * Fixed another issue with incorrect `hreflang` URLs + +# v3.0.0 +## 08/19/2022 + +1. [](#new) + * Completely rewrote the logic for translated URLs to be more robust. + * Added configuration option to use **Translated URLs** or use previous **Raw-Route** approach +1. [](#improved) + * Updated `hreflang` Twig template to use new translated URLs logic + * Added an `x-default` entry for `hreflang` template when default language has `include_default_lang` set to false + * Support `params` and `query` string parameters in URLs + * Full domain URLs for `hreflang` entries + +# v2.0.1 +## 08/04/2022 + +1. [](#bugfix) + * Fixed exception thrown instead of **404 Page not found** [#66](https://github.com/getgrav/grav-plugin-langswitcher/issues/66) + +# v2.0.0 +## 07/25/2022 + +1. [](#new) + * Support for translated slugs!!!! [#50](https://github.com/getgrav/grav-plugin-langswitcher/pull/50) + * Require Grav `1.7` +1. [](#improved) + * Improved support for home URL [#59](https://github.com/getgrav/grav-plugin-langswitcher/pull/59) + +# v1.5.0 +## 07/01/2021 + +1. [](#new) + * Made langswitcher display more customizable. See README.md for full details. + +# v1.4.3 +## 06/25/2021 + +1. [](#new) + * Made langswitcher data available in Grav object +1. [](#bugfix) + * Fix multilang alternatives [#58](https://github.com/getgrav/grav-plugin-langswitcher/pull/58) +# v1.4.2 +## 03/17/2021 + +1. [](#new) + * Pass phpstan level 1 tests + * Require Grav v1.6 +1. [](#bugfix) + * Fix `hreflang` URLs [#57](https://github.com/getgrav/grav-plugin-langswitcher/pull/57) + +# v1.4.1 +## 05/09/2019 + +1. [](#new) + * Added some translations [#45](https://github.com/getgrav/grav-plugin-langswitcher/pull/45) + +# v1.4.0 +## 06/29/2017 + +1. [](#new) + * Added the `untranslated_pages_behavior` option to determine what to do with a language link when the current page doesn't exist in that language or it exists but it's not published +1. [](#bugfix) + * Fixed generated URLs when `append_url_extension` is set, via PR [#22](https://github.com/getgrav/grav-plugin-langswitcher/pull/22) + +# v1.3.0 +## 02/17/2017 + +1. [](#new) + * Added support for `hreflang` annotations via PR [#19](https://github.com/getgrav/grav-plugin-langswitcher/pull/19) + +# v1.2.1 +## 05/28/2016 + +1. [](#bugfix) + * Display all language names, even those with non supported locales + +# v1.2.0 +## 05/03/2016 + +1. [](#improved) + * Take URI parameters into account when switching languages + * Add `external` class to avoid problems on modular pages when `jquery.singlePageNav` is loaded + +# v1.1.0 +## 10/15/2015 + +1. [](#improved) + * Added active class to language links + +# v1.0.2 +## 07/13/2015 + +1. [](#improved) + * Improved homepage routing + +# v1.0.1 +## 07/08/2015 + +1. [](#improved) + * Updated blueprints with some typo fixes + +# v1.0.0 +## 07/08/2015 + +1. [](#new) + * ChangeLog started... diff --git a/plugins/langswitcher/LICENSE b/plugins/langswitcher/LICENSE new file mode 100644 index 0000000..0e788c6 --- /dev/null +++ b/plugins/langswitcher/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Grav + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/langswitcher/README.md b/plugins/langswitcher/README.md new file mode 100644 index 0000000..81bcc04 --- /dev/null +++ b/plugins/langswitcher/README.md @@ -0,0 +1,128 @@ +# Grav LangSwitcher Plugin + +![LangSwitcher](assets/readme_1.png) + +`LangSwitcher` is a [Grav](http://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 **0.9.30** or greater. + +# Installation + +Installing the LangSwitcher plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file. + +## GPM Installation (Preferred) + +The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type: + + bin/gpm install langswitcher + +This will install the LangSwitcher plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/langswitcher`. + +## Manual Installation + +To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `langswitcher`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-langswitcher) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). + +You should now have all the plugin files under + + /your/site/grav/user/plugins/langswitcher + +# Usage + +The `langswitcher` plugin doesn't require any configuration. You do however need to add the included Twig partials template into your own theme somewhere you want the available languages to be displayed. + +```twig +{% include 'partials/langswitcher.html.twig' %} +``` + +Something you might want to do is to override the look and feel of the langswitcher, and with Grav it is super easy. + +Copy the template file [langswitcher.html.twig](templates/partials/langswitcher.html.twig) into the `templates` folder of your custom theme: + +``` +/your/site/grav/user/themes/custom-theme/templates/partials/langswitcher.html.twig +``` + +You can now edit the override and tweak it however you prefer. + +## Usage of the `hreflang` partial + +A second template is available for `hreflang` annotations in the header of the page. In order to emit language annotations for the available languages of a page you need to add the corrsponding Twig partial template into the `
` section of your page, which can typically be found in `base.html.twig`: + +```twkg +{% include 'partials/langswitcher.hreflang.html.twig' %} +``` + +This will generate something like: + +```html + + + +``` + +# Updating + +As development for the LangSwitcher plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating LangSwitcher is easy, and can be done through Grav's GPM system, as well as manually. + +## GPM Update (Preferred) + +The simplest way to update this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following: + + bin/gpm update langswitcher + +This command will check your Grav install to see if your LangSwitcher plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type `y` and hit enter. The plugin will automatically update and clear Grav's cache. + +> Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact. + +## Configuration + +Simply copy the `user/plugins/langswitcher/langswitcher.yaml` into `user/config/plugins/langswitcher.yaml` and make your modifications. + +```yaml +enabled: true +built_in_css: true +translated_urls: true +untranslated_pages_behavior: none +language_display: long +``` + +Options are pretty self explanatory. + +## Redirecting after switching language + +To have Grav redirect to the default page route after switching language, you must add the following configuration to `user/config/system.yaml` + +```yaml +pages: + redirect_default_route: true +``` + +## Customization + +The default format for the displaying of the languages is to use the native language names in a **long** format (e.g. `English`, `Deutsch`, `Français`). However, you can change the default output to use **short** names (e.g. `EN`, `DE`, `FR`). + +This can be configured via the `langswitcher.yaml` configuration file: + +```yaml +language_display: long # long | short are the valid options +``` + +You can also pass the format in directly via the Twig include: + +```twig +{% include 'partials/langswitcher.hreflang.html.twig' with {display_format: 'short'} %} +``` + +Also you can override the two Twig partials that control the actual display of the **long** and **short** output, by copying the partial int your theme's `templates/partials/` folder and modifying: + +```twig +# templates/partials/langswitcher-long.html.twig +{{ native_name(language)|capitalize }} +``` + +and + +```twig +# templates/partials/langswitcher-short.html.twig +{{ language|upper }} +``` + + diff --git a/plugins/langswitcher/assets/readme_1.png b/plugins/langswitcher/assets/readme_1.png new file mode 100644 index 0000000..8cfb824 Binary files /dev/null and b/plugins/langswitcher/assets/readme_1.png differ diff --git a/plugins/langswitcher/blueprints.yaml b/plugins/langswitcher/blueprints.yaml new file mode 100644 index 0000000..910baee --- /dev/null +++ b/plugins/langswitcher/blueprints.yaml @@ -0,0 +1,73 @@ +name: LangSwitcher +version: 3.0.2 +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: + name: Team Grav + email: devs@getgrav.org + url: http://getgrav.org +homepage: https://github.com/getgrav/grav-plugin-langswitcher +keywords: mulitlang, multilanguage, translation, switcher +bugs: https://github.com/getgrav/grav-plugin-langswitcher/issues +license: MIT +dependencies: + - { name: grav, version: '>=1.7.37' } + +form: + validation: strict + fields: + enabled: + type: toggle + label: PLUGIN_ADMIN.PLUGIN_STATUS + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + built_in_css: + type: toggle + label: PLUGIN_LANGSWITCHER.BUILTIN_CSS + help: PLUGIN_LANGSWITCHER.BUILTIN_CSS_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + translated_urls: + type: toggle + label: PLUGIN_LANGSWITCHER.TRANSLATED_URLS + help: PLUGIN_LANGSWITCHER.TRANSLATED_URLS_HELP + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + language_display: + type: select + size: small + label: PLUGIN_LANGSWITCHER.LANGUAGE_DISPLAY + help: PLUGIN_LANGSWITCHER.LANGUAGE_DISPLAY_HELP + default: long + options: + long: PLUGIN_LANGSWITCHER.LANGUAGE_DISPLAY_LONG + short: PLUGIN_LANGSWITCHER.LANGUAGE_DISPLAY_SHORT + + untranslated_pages_behavior: + type: select + size: medium + label: PLUGIN_LANGSWITCHER.UNTRANSLATED_PAGES_BEHAVIOR + help: PLUGIN_LANGSWITCHER.UNTRANSLATED_PAGES_BEHAVIOR_HELP + default: none + options: + none: PLUGIN_LANGSWITCHER.UNTRANSLATED_PAGES_BEHAVIOR_OPTION_NONE + redirect: PLUGIN_LANGSWITCHER.UNTRANSLATED_PAGES_BEHAVIOR_OPTION_REDIRECT + hide: PLUGIN_LANGSWITCHER.UNTRANSLATED_PAGES_BEHAVIOR_OPTION_HIDE diff --git a/plugins/langswitcher/composer.json b/plugins/langswitcher/composer.json new file mode 100644 index 0000000..d32049d --- /dev/null +++ b/plugins/langswitcher/composer.json @@ -0,0 +1,29 @@ +{ + "name": "grav-plugin-langswitcher", + "type": "grav-plugin", + "description": "Language switcher plugin for Grav CMS", + "keywords": ["langswitcher"], + "homepage": "https://github.com/getgrav/grav-plugin-langswitcher/", + "license": "MIT", + "authors": [ + { + "name": "Team Grav", + "email": "devs@getgrav.org", + "homepage": "http://getgrav.org", + "role": "Developer" + } + ], + "require": { + "php": ">=7.1.3", + "ext-json": "*", + "ext-mbstring": "*" + }, + "autoload": { + "classmap": ["langswitcher.php"] + }, + "config": { + "platform": { + "php": "7.1.3" + } + } +} diff --git a/plugins/langswitcher/composer.lock b/plugins/langswitcher/composer.lock new file mode 100644 index 0000000..232467f --- /dev/null +++ b/plugins/langswitcher/composer.lock @@ -0,0 +1,24 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "54479277654e1741212fe76198612572", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.1.3", + "ext-json": "*", + "ext-mbstring": "*" + }, + "platform-dev": [], + "platform-overrides": { + "php": "7.1.3" + } +} diff --git a/plugins/langswitcher/css/langswitcher.css b/plugins/langswitcher/css/langswitcher.css new file mode 100644 index 0000000..710dee3 --- /dev/null +++ b/plugins/langswitcher/css/langswitcher.css @@ -0,0 +1,22 @@ +.langswitcher { + position: relative; + top: 50%; + -webkit-transform: translateY(-50%); + -moz-transform: translateY(-50%); + -o-transform: translateY(-50%); + -ms-transform: translateY(-50%); + transform: translateY(-50%); + margin-left: 1rem !important; + display: inline-block; +} + +.langswitcher li { + display: inline-block; + margin-left: 0.5rem; + line-height: 1rem; +} + +.langswitcher .active { + font-weight: bold; + text-decoration: underline; +} diff --git a/plugins/langswitcher/langswitcher.php b/plugins/langswitcher/langswitcher.php new file mode 100644 index 0000000..82f22eb --- /dev/null +++ b/plugins/langswitcher/langswitcher.php @@ -0,0 +1,180 @@ + [ + ['autoload', 100001], + ['onPluginsInitialized', 0] + ] + ]; + } + + /** + * [onPluginsInitialized:100000] Composer autoload. + * + * @return ClassLoader + */ + public function autoload() + { + return require __DIR__ . '/vendor/autoload.php'; + } + + /** + * Initialize configuration + */ + public function onPluginsInitialized() + { + if ($this->isAdmin()) { + $this->active = false; + return; + } + + $this->enable([ + 'onTwigInitialized' => ['onTwigInitialized', 0], + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] + ]); + } + + /** Add the native_name function */ + public function onTwigInitialized() + { + $this->grav['twig']->twig()->addFunction( + new \Twig_SimpleFunction('native_name', function($key) { + return LanguageCodes::getNativeName($key); + }) + ); + } + + /** + * Add current directory to twig lookup paths. + */ + public function onTwigTemplatePaths() + { + $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; + } + + /** + * Generate localized route based on the translated slugs found through the pages hierarchy + */ + protected function getTranslatedUrl($lang, $path) + { + /** @var Language $language */ + $url = null; + /** @var Pages $pages */ + $pages = $this->grav['pages']; + /** @var Language $language */ + $language = $this->grav['language']; + + $language->init(); + $language->setActive($lang); + $pages->reset(); + $page = $pages->get($path); + if ($page) { + $url = $page->url(); + } + return $url; + } + + /** + * Set needed variables to display Langswitcher. + */ + public function onTwigSiteVariables() + { + + /** @var PageInterface $page */ + $page = $this->grav['page']; + + /** @var Pages $pages */ + $pages = $this->grav['pages']; + + /** @var Cache $cache */ + $cache = $this->grav['cache']; + + $data = new \stdClass; + $data->page_route = $page->rawRoute(); + if ($page->home()) { + $data->page_route = '/'; + } + + $translated_cache_key = md5('translated_cache_key'.$data->page_route.$pages->getSimplePagesHash()); + + $languages = $this->grav['language']->getLanguages(); + $data->languages = $languages; + + if ($this->config->get('plugins.langswitcher.untranslated_pages_behavior') !== 'none') { + $translated_pages = []; + foreach ($languages as $language) { + $translated_pages[$language] = null; + $page_name_without_ext = substr($page->name(), 0, -(strlen($page->extension()))); + $translated_page_path = $page->path() . DS . $page_name_without_ext . '.' . $language . '.md'; + if (!file_exists($translated_page_path) and $language == $this->grav['language']->getDefault()) { + $translated_page_path = $page->path() . DS . $page_name_without_ext . '.md'; + } + if (file_exists($translated_page_path)) { + $translated_page = new Page(); + $translated_page->init(new \SplFileInfo($translated_page_path), $language . '.md'); + $translated_pages[$language] = $translated_page; + } + } + $data->translated_pages = $translated_pages; + } + + $language = $this->grav['language']; + $active = $language->getActive() ?? $language->getDefault(); + + if ($this->config->get('plugins.langswitcher.translated_urls', true)) { + $data->translated_routes = $cache->fetch($translated_cache_key); + + if ($data->translated_routes === false) { + $translate_langs = $data->languages; + + if (($key = array_search($active, $translate_langs)) !== false) { + $data->translated_routes[$active] = $page->url(); + unset($translate_langs[$key]); + } + + foreach ($translate_langs as $lang) { + $data->translated_routes[$lang] = $this->getTranslatedUrl($lang, $page->path()); + if (is_null($data->translated_routes[$lang])) { + $data->translated_routes[$lang] = $data->page_route; + } + } + // Reset pages to current active language + $language->init(); + $language->setActive($active); + $this->grav['pages']->reset(); + $cache->save($translated_cache_key, $data->translated_routes); + } + } + + $data->current = $language->getLanguage(); + + $this->grav['twig']->twig_vars['langswitcher'] = $this->grav['langswitcher'] = $data; + + if ($this->config->get('plugins.langswitcher.built_in_css')) { + $this->grav['assets']->add('plugin://langswitcher/css/langswitcher.css'); + } + } + + public function getNativeName($code) { + + } +} diff --git a/plugins/langswitcher/langswitcher.yaml b/plugins/langswitcher/langswitcher.yaml new file mode 100644 index 0000000..a4973cd --- /dev/null +++ b/plugins/langswitcher/langswitcher.yaml @@ -0,0 +1,5 @@ +enabled: true +built_in_css: true +translated_urls: true +untranslated_pages_behavior: none +language_display: long diff --git a/plugins/langswitcher/languages.yaml b/plugins/langswitcher/languages.yaml new file mode 100644 index 0000000..b2ece9f --- /dev/null +++ b/plugins/langswitcher/languages.yaml @@ -0,0 +1,35 @@ +en: + PLUGIN_LANGSWITCHER: + BUILTIN_CSS: 'Use built in CSS' + BUILTIN_CSS_HELP: 'Include the CSS provided by the LangSwitcher plugin.' + UNTRANSLATED_PAGES_BEHAVIOR: 'Untranslated pages behavior' + UNTRANSLATED_PAGES_BEHAVIOR_HELP: "Determine what to do with a language link when the current page doesn't exist in that language or it exists but it's not published." + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_NONE: 'Show language (default)' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_REDIRECT: 'Show language, link to home route' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_HIDE: 'Hide language' + LANGUAGE_DISPLAY: 'Language Display' + LANGUAGE_DISPLAY_HELP: 'The format of the language display, either "long" (e.g. English), or "short" (e.g. EN)' + LANGUAGE_DISPLAY_LONG: 'Long' + LANGUAGE_DISPLAY_SHORT: 'Short' + TRANSLATED_URLS: 'Translated URLs' + TRANSLATED_URLS_HELP: 'Use the actual translated page URL rather then the raw-route' + +ru: + PLUGIN_LANGSWITCHER: + BUILTIN_CSS: 'Использовать встроенный CSS' + BUILTIN_CSS_HELP: 'Использовать CSS, предоставленный плагином LangSwitcher.' + UNTRANSLATED_PAGES_BEHAVIOR: 'Поведение непереведенных страниц' + UNTRANSLATED_PAGES_BEHAVIOR_HELP: 'Определяет что делать с языковой ссылкой, если текущая страница не существует на этом языке или существует, но не опубликована.' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_NONE: 'Показать язык (по умолчанию)' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_REDIRECT: 'Показать язык, ссылка на домашнюю страницу' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_HIDE: 'Скрыть язык' + +uk: + PLUGIN_LANGSWITCHER: + BUILTIN_CSS: 'Використовувати вбудований CSS' + BUILTIN_CSS_HELP: 'Використовувати CSS, наданий плагіном LangSwitcher.' + UNTRANSLATED_PAGES_BEHAVIOR: 'Поведінка неперекладених сторінок' + UNTRANSLATED_PAGES_BEHAVIOR_HELP: 'Визначає що робити з посиланням на мову, якщо поточна сторінка не існує на цій мові або існує, але не опублікована.' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_NONE: 'Показати мову (за умовчанням)' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_REDIRECT: 'Показати мову, посилання на домашню сторінку' + UNTRANSLATED_PAGES_BEHAVIOR_OPTION_HIDE: 'Приховати мову' diff --git a/plugins/langswitcher/templates/partials/langswitcher-long.html.twig b/plugins/langswitcher/templates/partials/langswitcher-long.html.twig new file mode 100644 index 0000000..0fea2fc --- /dev/null +++ b/plugins/langswitcher/templates/partials/langswitcher-long.html.twig @@ -0,0 +1 @@ +{{ native_name(language)|capitalize }} \ No newline at end of file diff --git a/plugins/langswitcher/templates/partials/langswitcher-short.html.twig b/plugins/langswitcher/templates/partials/langswitcher-short.html.twig new file mode 100644 index 0000000..e71027e --- /dev/null +++ b/plugins/langswitcher/templates/partials/langswitcher-short.html.twig @@ -0,0 +1 @@ +{{ language|upper }} \ No newline at end of file diff --git a/plugins/langswitcher/templates/partials/langswitcher.hreflang.html.twig b/plugins/langswitcher/templates/partials/langswitcher.hreflang.html.twig new file mode 100644 index 0000000..1646ea4 --- /dev/null +++ b/plugins/langswitcher/templates/partials/langswitcher.hreflang.html.twig @@ -0,0 +1,16 @@ +{% 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 = uri.base ~ lang_url ~ uri.params ~ (uri.query|length > 1 ? '?' ~ uri.query) %} + + {% if (language_obj.default == language and config.languages.include_default_lang == false) %} + + {% endif %} + +{% endfor %} diff --git a/plugins/langswitcher/templates/partials/langswitcher.html.twig b/plugins/langswitcher/templates/partials/langswitcher.html.twig new file mode 100644 index 0000000..3b44b1f --- /dev/null +++ b/plugins/langswitcher/templates/partials/langswitcher.html.twig @@ -0,0 +1,33 @@ +