How can I set up multi language admin ui?

There are a couple of methods that this can be done without the overhead of plugins.

Method 1

The first method involves hooking to the load_textdomain_mofile filter.

(This must go into a separate plugin)

function wpse31785_change_mofile( $mofile, $domain ) {
    if ( $domain == 'default'
        and get_current_user() == 'riccardo' )
            return substr($mofile, 0, -8).'it_IT.mo';
    return $mofile;
}

add_filter( 'load_textdomain_mofile', 'wpse31785_change_mofile', null, 2 );

Method 2

This method involves modifying your wp-config.php file in order to conditionally set WPLANG.

// store the language in session
if ( isset($_GET['lang']) ) $_SESSION['lang'] = $_GET['lang'];

if ( isset($_SESSION['lang']) ) // pick the language conditionally
    if ( $_SESSION['lang'] == 'it' ) define( 'WPLANG', 'it_IT' );
    elseif ( $_SESSION['lang'] == 'en' ) define ( 'WPLANG' , 'en_EN' );

// the default fallback
if ( !defined( 'WPLANG' ) ) define ( 'WPLANG', '' );

With this in your wp-config.php you are able to provide an additional GET parameter to set the language for the session. http://yoursite.com/wp-admin/?lang=it will set the WPLANG constant to it_IT.

Alternatively you can store the chosen language in the cookies with setcookie() and get them from the $_COOKIE global instead of using the session variables.

Leave a Comment