Change WordPress user roles and capabilities Forums How to or FAQ deliver another language file for one user role

Tagged: 

  • This topic has 2 replies, 2 voices, and was last updated 5 years ago by tobe.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6184
    tobe
    Participant

    Hello, support,

    we would like to deliver another language file for one user role. How can we do this?

    Thank you very much for your help!

    #6188
    Vladimir
    Keymaster

    Hi,

    Site admin can install needed language file for WordPress temporally changing site language at the Settings->General page. (Change language, update settings, change language back).

    WordPress offers special filter ‘locale’, which allows to automatically change language according your own conditions. You may use code below as a starting point, change ‘author’ role to your own:

    
    // Change site language for a role
    add_filter( 'locale', 'change_site_lang_for_role', 10, 1 );
    
    function change_site_lang_for_role( $locale ) {
        
        if ( !is_user_logged_in() ) {
            return $locale;
        }
        
        $user = wp_get_current_user();
        if ( !is_array( $user->roles ) ) {
            return $locale;
        }
        
        if ( in_array('author', $user->roles ) ) {
        
            $locale = 'de_DE';
        }
    
        return $locale;
    }
    // end of change_site_lang_for_role()
    
    #6189
    tobe
    Participant

    Hello, Vladimir,

    thank you very much – this works great!

    Many greetings

    Tobias

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.