Disable language selector in the panel for specific roles and set the language based on the panel language


I’ve got two roles in a multilanguage site (en/fr):

  • admin
  • traveler

For the traveler role, I would like to disable (or better hide) the language selector in the panel and redirect the traveler user automatically to its own language based on its panel language which is French or English.

I don’t want for French or English users with traveler role to have to choose the language of their content.
The panel language selector should be set to English by default for English traveler user and set to French by default for French traveler user with no possibility to switch between the two languages in the panel.

Is that possible?

You could hide the switcher via CSS based on the data-role attribute and combine that with the home option:

The target language can be added as query string…

(Not tested).

Thanks Sonja, you put me on the right direction.

Hide the language selector with CSS was easy but I don’t find how to target language in the query string. So I made a custom method for the site object in a plugin that redirects the user to the right language panel view and call this method with the home option.

For those interrested, this is my index.php plugin code:


Kirby::plugin('gillesvauvarin/gillesvauvarin-extend-site-methods', [
    'siteMethods' => [
        'goCorrespondingLanguage' => function () {
            $current_user = kirby()->user();
            if ( $current_user->role() == 'traveller' ) :
                if ( $current_user->language() == 'fr' ) :
                    go( kirby()->site()->panel()->url() . '?language=fr' );
                elseif( $current_user->language() == 'en' ) :
                    go( kirby()->site()->panel()->url() . '?language=en' );


I have the same task on my multilanguage site. Users should only be able to work on their own language (defined panel language) content.

I could easy hide the language selector and also your plugin-code is working fine. Thanks for sharing!

BUT users are still able to change the language by manually modifying the url in the browser:

Is there a way to prevent this?
That would be perfect!


I think it would be possible with a custom route, something like (not tested …)

// /site/config/config.php

return [
  'routes' => [
      'pattern' => '(:any)?language=en',
      'action'  => function($any) {
        if ( $kirby->user()->language() == 'fr' ) :
           go($any . '/?language=fr');

If a french user try to access to an URL ended by “?language=en” you redirect him/her to the french URL.
Do the same with an English user.

Unfortunately, I don’t think @gillesvauvarin solution will work like this, because

  1. query strings/parameters in patterns are ignored
  2. you cannot overwrite Panel routes

A viable solution would be to intercept the route in a route:before hook and throw an error from there.

Thanks, both of you!
The snippet from @gillesvauvarin actually doesn’t work. I liked the idea.

Being new to Kirby this is quite complex for me. How can I get the user-panel-language in route:before and what can I do with the result? Just alert an error message like: “You are not allowed to work on these pages.”? AND how this should be coded?

Thanks in advance for any help!

You can find an example hook here: Author acces to only the pages they've created