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

Hi,

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:

<?php

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' );
                endif;
            endif;
            
        }
  ]
]);