Giter Site home page Giter Site logo

getgrav / grav-plugin-langswitcher Goto Github PK

View Code? Open in Web Editor NEW
26.0 6.0 26.0 133 KB

Grav LangSwitcher Plugin

Home Page: https://getgrav.org

License: MIT License

CSS 5.35% PHP 63.34% Twig 31.31%
grav grav-plugin multilanguage multilingual internationalization i18n

grav-plugin-langswitcher's Introduction

Grav LangSwitcher Plugin

LangSwitcher

LangSwitcher is a Grav plugin that provides native language text links to switch between Multiple Languages 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) 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 or via GetGrav.org.

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.

{% 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 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 <head> section of your page, which can typically be found in base.html.twig:

{% include 'partials/langswitcher.hreflang.html.twig' %}

This will generate something like:

<link rel="alternate" href="http://example.com/en" hreflang="en" />
<link rel="alternate" href="http://example.com/de" hreflang="de" />
<link rel="alternate" href="http://example.com/zh-cn" hreflang="zh-cn" />

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). 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.

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

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:

language_display: long              # long | short are the valid options

You can also pass the format in directly via the Twig include:

{% 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:

# templates/partials/langswitcher-long.html.twig
{{ native_name(language)|capitalize }}

and

# templates/partials/langswitcher-short.html.twig
{{ language|upper }}

grav-plugin-langswitcher's People

Contributors

benface avatar feuzeu avatar flagar avatar flaviocopes avatar karmalakas avatar lordalcol avatar lufog avatar mahagr avatar rhukster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

grav-plugin-langswitcher's Issues

Inactive language with trailing slash

There is problem with the url of the home page for inactive language.
A trailing slash is added even if no extension are set in config.

The problem is visible for both langswitcher.hreflang.html.twig and langswitcher.html.twig:

For exemple if English page is active it render:

<link rel="alternate" href="/en" hreflang="en" />
<link rel="alternate" href="/fr" hreflang="fr/" />

and

<ul class="langswitcher">
<li><a class="langswitcher-button" active href="en">English</a></li>
<li><a class="langswitcher-button" href="fr/">Français</a></li>
</ul>

The problem is also visible on the url bar if redirect trailing slash is set to off in config.

3.0 update slows down site

Hi, I've updated to the latest version of langSwicher (from 2.0.1 to 3.0.1) and my site suddenly became very sluggish.

I noticed that in debugger - debugbar Messages I saw repeated setting of active language.
msg

I do have custom twig files that I use, so it could be the issue there. However, I was just wondering if you'd have some insight into why it is happening. Thanks much,

Session storage "traps" user in a language

Context

I have a site set up so that English is the default language and French is a second language.

When the user switches to French, /fr/ is inserted just after the root me.net/page -> me.net/fr/page.

With session_store_active : false this behaviour works as expected both ways, changing language will add or remove the /fr/ appropriately.

Issue

However, setting session_store: true "traps" the user in French: trying to change the language to English points the user to me.net/page as expected but a 302 redirect bounces them back to me.net/fr/page.

Changing just the session_store setting and nothing else makes this behaviour systematically repeatable.

Useful data

# /user/config/system.yaml
# ...
absolute_urls: false
default_locale: null
reverse_proxy_setup: false
custom_base_url: ''
intl_enabled: true
session:
  enabled: true
languages:
  supported:
    - en
    - fr
  include_default_lang: false
  translations: true
  translations_fallback: true
  session_store_active: true   # <- Flip this boolean to replicate
  http_accept_language: true
  override_locale: false
  0: en
  1: fr
pages:
  redirect_default_route: false
  redirect_default_code: '302'
  redirect_trailing_slash: true
# ...
# /user/config/plugins/langswitcher.yaml
enabled: true
built_in_css: false
untranslated_pages_behavior: none
<!-- /user/themes/custom-theme/templates/partials/langswitcher.html.twig -->
{% for language in langswitcher.languages %}

    {% set show_language = true %}
    {% if language == langswitcher.current %}
        {% set show_language = false %}
        {% set lang_url = page.url %}
    {% else %}
        {% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
        {% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
        {% 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 ~ '/' %}
                {% elseif untranslated_pages_behavior == 'hide' %}
                    {% set show_language = false %}
                {% endif %}
            {% endif %}
        {% endif %}
        {% set active_class = '' %}
    {% endif %}

    {% if show_language %}
        <a href="{{ lang_url ~ uri.params }}" class="navbar-link language-selection">{{ native_name(language)|capitalize }}</a>
    {% endif %}

{% endfor %}

Absolute url

As the documentation says:

{% include 'partials/langswitcher.hreflang.html.twig' %}

Will generate something like:

<link rel="alternate" href="http://example.com/en" hreflang="en" />
<link rel="alternate" href="http://example.com/de" hreflang="de" />

But this only works if user is using Absolute URLs setting of Grav.
Without this settings it generate something like this:

<link rel="alternate" href="/en" hreflang="en" />
<link rel="alternate" href="/de" hreflang="de/" />

And that's not good, as "rel=alternate" are suppose to always be absolute for SEO.

So how make this work for those how want to keep their URLs relatives? (which is way better 😄)

Localised slug/routes support

The provided langswitcher template always redirects to the default locale route (non-localised).

Example :

01.page-1
|---- default.en.md with slug: first-page, ie route is /en/first-page
|---- default.fr.md with slug: premiere-page ie route is /fr/premiere-page

When on /en/first-page, the lang-switcher will redirect either on /en/first-page [EN link] or /fr/first-page [FR link]

The "better" way would be to display both localised link : /en/first-page [EN link] and /fr/premiere-page [FR link]

If 'default route' is set for a given page, this page’s children become inaccessible via the Langswitcher button -- secondary langauges only

For secondary languages: If a parent page has routes: default: </xyz> set, this page's children can no longer be reached via the Langswitcher entries on the website. When trying to do so, the path to the expected page is correct in the browser address bar but the page itself is a 404.

Live test system at (godfatherjohn.com/test01).
The test system's pages folder is attached as a Zip file.

About the test website:
vanilla Grav v1.7.35, Quark theme, Langswitcher v2.0.1 (as at August 15th, 2022)

Grav language settings:
Supported: en, fr
default_lang: null
Include default language: No
Everything else is installation default, incl. "Overwrite default language: "

Langswitcher plugin settings:
Installation default, no changes

The primary language is EN, the secondary language is FR.
Every folder has two .md files: default.en.md and default.fr.md (as a workaround for issue #69).
Every .md file has a slug set (as a workaround for issue #67).

/home
|   default.en.md  
|   default.fr.md  
|---/level1
    |   default.en.md  
    |   default.fr.md  
    |---/level2
        |   default.en.md
        |   default.fr.md  (routes: default: '/test')
        |---/level3
            |   default.en.md  
            |   default.fr.md  <-- Only accessible via the nav menu. 
                                   One cannot access this page if one is on the EN version of 
                                   this page and then clicking on the Langswitcher "FR" entry
                                   on the website. 
                                   YOU CAN TRY THIS on the live test website. On the FR version,
                                   use the nav menu to go to 'Niveau3'. You will be served with the page. 
                                   Then click on "EN" (at the top in middle) and then click on "FR" and
                                   you will be served a 404 error page instead of this page.

Workaround: Do not set default routes.

Change shown name of language in language switcher

for zh (chinese)

中文 (简体)

is shown. That means simplified chinese. Where does the plugin get this information from? How can I let it show

中文

(chinese) instead?

It's annoying especially when using zh-cn for traditional chinese, which shows

中文 (简体) (cn)

switching works fine on localhost but fails when on the server

dear all,

is there any possible configuration on the server-side that could make the switch not functional?

i've installed the plugin on a fresh grav and it works totally fine on the localhost apache + php but as soon as i deploy on an app service on azure with php stack it doesnt work anymore.

Editable plugin fail to work after installation of Langswitcher

Hi,

I'm building multilingual website for my client using Editable and Langswitcher plugin.

It was actually working fine when on localhost but since I moved website on my webhost editable fail to work together with Langswitcher. When I remove Langswitcher plugin everything is fine.
I see that contenttools editor is loaded when I log in in frontend but shortcodes are not processed from some reason.

Website is on subdomain at the moment here

Do you have any idea what could cause the problem?

Thank you very much!

using page's override default_route instead of raw_route

I've encountered a scenario that the langswitcher isn't handling as I would expect.

I have my blog under the directory /knowledge/blog but I have the default route overridden with /blog.
screen shot 2018-03-28 at 12 22 34

screen shot 2018-03-28 at 12 23 29

grav itself has no issue when routing to the underlying blog pages, or the blog itself. But when I am on a blog page and use the langswitcher because it is using the rawRoute it includes the folder structure instead of using the overridden default route

I've been digging around the code a bit and I think in order to make this work, the grav library would need to expose the default_route override so that we could make use of it in the langswitcher plugin.

The reason I'm looking to address this is for SEO purposes, we don't want to have the /knowledge/blog url showing up at all.

[Suggestion and request] the plugin is poor configuration

There are no options to use flags;

I have modified the code a bit since the first versions and it seems to work in the last, here it is:

https://github.com/getgrav/grav-plugin-langswitcher/blob/develop/templates/partials/langswitcher.html.twig

<style>
a.active img {
	width: 30px !important;
	height 40px !important;
}
</style>
<ul class="langswitcher">
{% set langobj = grav['language'] %}

{% for key in langswitcher.languages %}

    {% if key == langswitcher.current %}
        {% set lang_url = page.url %}
        {% set active_class = ' active' %}
    {% else %}
        {% set lang_url = base_url_simple ~ langobj.getLanguageURLPrefix(key)~langswitcher.page_route ?: '/' %}
        {% set active_class = '' %}
    {% endif %}

    <li><a href="{{ lang_url ~ uri.params }}" class="external{{ active_class }}">{% if native_name(key) == 'Português (br)' %}{{ '<img width="20px"  src="/images/langswitcher/br-flag.svg" />' }}{% else %}{{ '<img width="20px" src="/images/langswitcher/us-flag.svg" />' }}{% endif %}</a></li>

{% endfor %}
</ul>

I think it would be great to give some settings as a flag option for each language.

Mouse over show wrong url

I don't know if it is a plugin or grav issue, please address.

In multilingual environment the url on mouse over the language switcher shows folder based urls but the link itself directs correctly to the slug set url.

Where to add language selector code?

Hello, I'm a new user of Grav, though I'm not new to programming or to flat file CMSs. I created a multilingual site and need to display a language selector. To this end, I installed and activated the LangSwitcher plugin, which requires adding {% include 'partials/langswitcher.hreflang.html.twig' %} to the theme. My site uses the Typhoon theme, which appears to be the current state of the art for Grav.

Could anyone kindly tell me exactly where this code (which path and file, which line number?) should go to add a language selector to the upper right of the navbar in both desktop and mobile views? I've been trying to add it to different files but Grav keeps returning error messages. Evidently I don't yet know how Grav parses template files. Many thanks in advance for any assistance.

Let the root url be the default language without any language path

Hello folks,

I run a multi-lang page with two languages. EN is my default.
Right now when I go to the root domain. I get redirected to the path /en.
Is it possible to not do that? Like the root domain is en with out any path and if the language gets switched to German it is /de.

It would get a better page speed for the root domain since there is no redirect.
Any ideas how to do that?

Absolute url

Hey,

First thanks for this nice plugin.

I just have a question about langswitcher.hreflang.html.twig. Why it returns a relative url?

From what I've read the best practice is to use an absolute url like for link rel="canonical".

Plugin generates wrong hreflang code

I have a blog setup with 2 languages (en, it).
Showing an english page from my blog I get the following:

While the en code is ok, where does the extra /blog/ in the it link come from ?

Starting from an IT page I get exactly the same problem plus the fact that it does not see EN as the default language and sets the IT page as canonical:

Maybe there is something wrong in the blog configuration ? Where do I set the default language ?

Any help appreciated
Thanks
r

Problem with custom slug in lang switching

Hello!

I have a blog post with folder 2013-10-26-background-image. Two languages md in it has custom slugs: background-image for EN and fonovaya-kartinka for RU (translit).

All works fine with selected language but after language switching becomes 2013-10-26-background-image for both langs.

Steps:

  1. We have EN lang in root and go to posts: site.com/en/posts
  2. Select our post, looks right: site.com/en/events/background-image
  3. Change lang to RU and url becomes: site.com/ru/events/2013-10-26-background-image
  4. Change lang to EN and url becomes the same: site.com/en/events/2013-10-26-background-image
    Present with another initial lang in the same way.

Env:
Grav v1.1.0-rc.1
LangSwitcher v1.2.1 with standard langswitcher.html.twig

Images support

Would it be possible to implement images support ? Without images support the langswitcher plugin feels spoon-feeding to use text only. The flags lovers and the icon user are left out. Explicitly new ideas about language suggestion are left out also.

When `http_accept_language` is set to true, manual switching does not work

When I add the language switcher to my website, but enable http_accept_language in config/system.yml, clicking on anything else than the browser preferred language will fall back to the browser preferred language.

langswitcher preferences:

enabled: true
built_in_css: true
untranslated_pages_behavior: none
language_display: long

Is there a way to automatically set the language of the browser, but allow a user to switch to another language through the langswitcher plugin? Now these options seem to be fighting. And the http_accept_language wins every time.

Support slugs in links

I have a site with 2 languages:

  • nl (default)
  • en

Dutch page is in folder diensten
English page has a slug services

On a Dutch page the links are

  • nl/diensten
  • en/diensten

On a English page the links are

  • nl/diensten
  • en/services

It would be nice if the links would use the slugs

Plugin ignores the configured slug(s) of the page(s) when changing the language

The primary folder structure is e.g. [/en]/animal/cat, where pages may or may not have a slug set because it would be the same as the directory name in English.

The second language is e.g. Czech, where the content of the URL [/(cs)]/zvire/kocka, defined via slug, should be displayed.

Now we are in the English version. The issue is that the link for Czech version does not include [/(cs)]/zvire/kocka, but [/(cs)]/animal/cat. While the content appears correct (from default.cs.md) but on the wrong link. Consequently, the link for Czech is already correct.

Non-existent page: Call to a member function slug() on null

When I go to a page that does not exist, instead of 404 page, I'm greeted with an ugly error caused by langswitcher:

Error thrown with message "Call to a member function slug() on null"

Stacktrace:
#48 Error in /var/www/html/user/plugins/langswitcher/langswitcher.php:80
#47 Grav\Plugin\LangSwitcherPlugin:_getTranslatedUrl in /var/www/html/user/plugins/langswitcher/langswitcher.php:143
#46 Grav\Plugin\LangSwitcherPlugin:onTwigSiteVariables in /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:264
#45 Symfony\Component\EventDispatcher\EventDispatcher:doDispatch in /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:239
#44 Symfony\Component\EventDispatcher\EventDispatcher:callListeners in /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:73
#43 Symfony\Component\EventDispatcher\EventDispatcher:dispatch in /var/www/html/system/src/Grav/Common/Grav.php:592
#42 Grav\Common\Grav:fireEvent in /var/www/html/system/src/Grav/Common/Twig/Twig.php:413
#41 Grav\Common\Twig\Twig:processSite in /var/www/html/system/src/Grav/Common/Service/OutputServiceProvider.php:36
#40 Grav\Common\Service\OutputServiceProvider:Grav\Common\Service\{closure} in /var/www/html/vendor/pimple/pimple/src/Pimple/Container.php:122
#39 Pimple\Container:offsetGet in /var/www/html/system/src/Grav/Common/Processors/RenderProcessor.php:40
#38 Grav\Common\Processors\RenderProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#37 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#36 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php:38
#35 Grav\Common\Processors\DebuggerAssetsProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#34 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#33 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/PagesProcessor.php:112
#32 Grav\Common\Processors\PagesProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#31 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#30 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/TwigProcessor.php:38
#29 Grav\Common\Processors\TwigProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#28 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#27 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/AssetsProcessor.php:39
#26 Grav\Common\Processors\AssetsProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#25 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#24 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/SchedulerProcessor.php:40
#23 Grav\Common\Processors\SchedulerProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#22 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#21 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/BackupsProcessor.php:39
#20 Grav\Common\Processors\BackupsProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#19 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#18 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/TasksProcessor.php:69
#17 Grav\Common\Processors\TasksProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#16 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#15 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/RequestProcessor.php:64
#14 Grav\Common\Processors\RequestProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#13 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#12 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/ThemesProcessor.php:38
#11 Grav\Common\Processors\ThemesProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#10 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#9 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/PluginsProcessor.php:39
#8 Grav\Common\Processors\PluginsProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#7 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#6 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Processors/InitializeProcessor.php:130
#5 Grav\Common\Processors\InitializeProcessor:Grav\Common\Processors\{closure} in /var/www/html/system/src/Grav/Common/Debugger.php:546
#4 Grav\Common\Debugger:profile in /var/www/html/system/src/Grav/Common/Processors/InitializeProcessor.php:131
#3 Grav\Common\Processors\InitializeProcessor:process in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:50
#2 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:62
#1 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/system/src/Grav/Common/Grav.php:307
#0 Grav\Common\Grav:process in /var/www/html/index.php:47

Switching to default slug name.

The language switcher isn't taking in account slug overrides.

I have a page within a folder named "about". I used about-us and a-propos-de-nous as slugs because I wanted the urls to be translated and that is working fine.

But, the language switcher is first linking to example.com/en/about or example.com/fr/about instead of example.com/en/about-us or example.com/fr/a-propos-de-nous.

Edit: Closed, it was already answered here

No support for dash separated locales - en-US, zh-TW, zh-CN etc.

So I added zh-TW but langswitcher doesn't show it in navigation. zh alone works so I suspect you cover a language but not all locales. Please add them too as I would like to have both Chinese Traditional (zh-TW) and Chinese Simplified (zh-CN) on my site.

Using grav['page']->route() instead of grav['page']->rawRoute()

Hey guys.

This is a very good plugin. Just want suggestion. I noticed you guys use grav['page']->rawRoute() to get the route of the page and put it in the href. The thing is, using rawRoute reject any possible custom routes specified by the user at the page frontmatter.

Example:
I have a page in pages/evets/myevent but I want users to be able to enter the page without having to write /events part so I do this:
routes: default: '/myevent'
No problem. But the Langswitcher page_route variable throws me the events/myevent route. Anyway, changing t to route(), according to the API docs will: Gets the route for the page based on the route headers if available, else from the parents route and the current Page's slug

I believe it will more suitable for customization routes. That or just add another variable in the code, like custom_route or something.

problem after upgrading to 1.2.1

I have a twig filter named: {% include 'modular/svg-blog-section-' ~ langswitcher.current ~ '.html.twig' %} for svg-blog-section-fr.html.twig, svg-blog-section-ja.html.twig etc...

After upgrade, I have an Runtime 404 error Template "modular/svg-blog-section-.html.twig" is not defined

Seems that langswitcher.current is not working anymore: what should I do?

Adding x-default fallback?

Hi,
I might be mistaken, but the plugin currently doesn't output the fallback tag/attribute, such as

<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />

According to this article, https://www.contentkingapp.com/academy/hreflang/, the fallback should always be there for SEO reasons.

Any chances that you might add it?

TIA

Tailing slashes vary

I have the problem, that tailing slashes are in hreflang tags are different for some languages.
I changes the hreflang-twig so it would trim the tailing slash for the url:

<link rel="alternate" hreflang="{{ key }}" href="{{ rtrim(lang_url,"/") ~ uri.params }}" />

Now it works.

langswitcher does not respect custom slugs

I found that the links to visible pages called from langswitcher plugin do not respect custom slugs set in grav pages. I don't know if it is a grav or langswitcher plugin issue, please sort.

Link without language

Hi,

getLanguageURLPrefix function in Language service is not defined in Grav v0.45 master branch, so the plugin doesn't work.

stylesheet is not working, I had to change the code:

.langswitcher li {
    display: inline-block;
    margin-left: 0.5rem;
    line-height: 1rem;
}

.langswitcher .active {
    font-weight: bold;
    text-decoration: underline;
}

to

a.external.active
{
    font-weight: bold;
    text-decoration: underline;
}
a.external {
    display: inline-block;
    margin-left: 0.7rem;
    line-height: 1rem;
}

because not all themes create langswitcher class

Two URLs for additional laguage using slug

Don't know where exactly put this issue, let it be here.

I have site with default ru language and additional pl language. All folder names (URLs) based on ru title transliteration.

For example, I have 02.metodologiya folder, http://sitename.com/ru/metodologiya as result URL. pl version have slug: metodyka and http://sitename.com/pl/metodyka URL.

When I use default language (http://sitename.com/ru/metodologiya) and switch it to pl from langswitcher menu, my URL not changed to slug, only lang (http://sitename.com/pl/metodologiya). But when I use pl lang (http://sitename.com/pl/metodyka) and switch it to ru, all works fine (http://sitename.com/ru/metodologiya).

As result, I have two URLs for second language:

  1. http://sitename.com/pl/metodologiya
  2. http://sitename.com/pl/metodyka

I think it's not good for SEO.

How to change this behavior?
Maybe there is some option in the Admin panel?

Arabic not displaying properly

my site has 2 languages English and Arabic.
When I'm using it in Arabic Both languages are shown correctly.
But when I'm using it in English , the Arabic language title is being shown as weird symbols. (English is correct)
about rima rimaworks
I tested with different directions for the html lan direction , but it is the same. ( right to left ,left to right and auto).

Plugin doesn't work with include_default_lang: false

If you have "include_default_lang: false" set (so that your main language doesn't use the language code in the URL (example: site.com/ site.com/fr/ vs site.com/en/ site.com/fr/)) then the language switcher will switch to any non-default language you select, but is unable to switch back to the default one when selected.

How to display a short version of the language name like EN FR ES RU ...

It's more than I'm not a developer and I learn by example but I didn't find anything to show me how to transform this line (I think it is in this line) : {{ native_name(language)|capitalize }}

Let's me try to explain what I expect :

I expect to have a EN / FR or en / fr menu which in html will look like :
<a href="./en/">EN</a> / <a href="./fr/">FR</a>

instead of :

            <li>
            <a href="/en/blog.html" class="external">
                English
            </a>
        </li>
            <li>
            <a href="/fr/blog.html" class="external">
                Français
            </a>
        </li>

Thanks a lot :)

Jonathan

How to change the Display of the the Languages

The functionality of this plugin is flawless. It works as intended. Although, Im kinda new with grav and I wanna achieve something like this, but Ive been trying to configure it but nothing shows up.

lang

If anyone can show me how to put them inside a dropdown and still make it work that'd be awesome! Thanks

wrong hreflang genereated when run in subdirectory

I'm running my grav site in a subdirectory site. I have configured en and de as languages.

When I am on http://localhost/site/de/page, the following hreflang entries are generated (using the default partial that comes with the plugin):

<link rel="alternate" hreflang="de" href="http://localhost/site/de/page">
<link rel="alternate" hreflang="en" href="http://localhost/en/page">

Clearly the non-active language is generated wrong. Might be related to #43?

Big bug - last part of url are not translated to alternate language - the same value of rawRoute() is used for all languages

Hi
use as example this website
http://www.cremonte.me/proizvodi

if you are in the english version of that website and pass the mouse hover the "Me" and "English" you can see that the urls are both in the english at the end part.

now if you change to "Me" language, the last part with be both in russian

http://www.cremonte.me/proizvodi
http://www.cremonte.me/en/proizvodi

http://www.cremonte.me/proizvodi
http://www.cremonte.me/en/products

looking inside langswitcher.php at the line 78 you pass the same value to all languages

$data->page_route = $page->rawRoute();

instead all urls should be different for each language

now I've seen that rawRoute use $this->folder instead of $this->slug

so the url of not current languages are wrong

After some hours I've solved all bugs in this plugin, I can help you to fix them to get a better version of grav

Full path not being created for other-language pages

This commit, in release 2.0.0, seems to cause a regression for me.

When on the default language on a certain page, a link to a translated language (in this case English), would previously be output as /en/kapitl1/lektsye1/kultur. However, now it's being output as /en/kultur. Namely, the intermediate folders between the root and the page folder are being omitted.

I've confirmed that when I change the line in twig from
{% set lang_url = base_lang_url ~ langswitcher.translated_routes[language] ~ page.urlExtension %}
back to
{% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
the regression is fixed. Beyond that, though, I haven't yet figured out what the issue is.

hreflang url does not works properly

Hello guys

I have a problem with the langswitcher plugin.
The website has 2 languages: en and es

The main language is defined the English language. All pages are translated (titles, slugs, etc).

When I switch from the es language to en main language the urls of hreflang works correclty. But when I am in the main language (en) and switch to secondary language (es) the metadata of the page translated is not working.

An example:

In a url with url "/en/princing" I switch to spanish version translated like "es/precios" I see in the html code generated:

<link rel="alternate" hreflang="en" href="/en/pricing" />
<link rel="alternate" hreflang="es" href="/es/pricing" />

Nevertheless, if I go to Spanish page (secondary language in Grav) and the switcher is working ok:

<link rel="alternate" hreflang="en" href="/en/pricing" />
<link rel="alternate" hreflang="es" href="/es/precios" />

I.e. the "es" page name translation is not included

I don't know if it's a bug or a problem with my configuration but I think all is configured ok.

Thank you

Lang Switcher URL problem

The new update causing problem, the url and data change suddenly to number and only the active language that have the url. see this , even the name change into number. Ah
1
2

Default language doesn't appear under certain configurations

My experience is that the default language doesn't appear on translated pages when untranslated_pages_behavior is set to hide in the plugin configuration, and the .md file for the default language doesn't include a language extension -- as is the case if, for example, the page was created when include_default_lang_file_extension is set to false in the site config.

A detailed analysis and proposed fix is in the PR below.

Langswitcher.html.twig doesn't work properly with include_default_lang: false

Is there any way please how to amend langswitcher.html.twig provided with the project so it will work when include_default_lang is set to false?

With include_default_lang: true it works properly.

But with false following problem happens:

  • let's say that Grav site www.gravsite.com has two languages, Italiano set like a default and English set like a secondary.
  • when user switches using the language switcher to English (so it starts to be default language), he can't switch back to Italiano anymore, because the switcher has following link set for Italiano: www.gravsite.com which redirects now to www.gravsite.com/en.
  • the only way how to switch now to the Italian is to type directly the URL, such like www.gravsite.com\it, which returns switcher back to Italiano.
  • the proper language switcher needed here should have language prefix in all URL's, also for the default language and should reflect the default language change

I tried to amend the provided Twig template, but didn't get any good result yet.

Here is my full config for languages:

languages:
  supported:
    - it
    - en
  include_default_lang: false
  translations: true
  translations_fallback: true
  session_store_active: true
  http_accept_language: false
  override_locale: false

Is there even any way how to do such amendment? Or the language switcher can be used only with all languages prefixed?

Thank you for any hint.

Not working with G5/hydrogen theme

The plugin work perfectly with Antimatter but not with Hydrogen (G5 theme).

As Hydrogen is the base free theme of G5 it could be a good idea to modify either Hydrogen or lanswicher.
I can't figure out to make it work .
May be it's possible to replace the plugin with an atom or a particle...
Any help will be appreciate. :-)

langswitcher with multisite setup ?

Do you have an idea how to use langswitcher in a multisite environnment ?

Here's my folder structure

- public_html
-- user
--- sites
---- site A
---- site B

so for example home page of site A (same issue with all pages)
http://domain.com/sitea

language url
fr: http://domain.com/sitea
en: http://domain.com/en --> instead of http://domain.com/sitea/en
de: http://domain.com/de --> instead of http://domain.com/sitea/de

in system.yaml :

pages:
  redirect_default_route: true

Thanks for info

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.