We could try to filter the locale (see e.g. this approach from the related list here on the right by @brasofilo, that's based on this one by @toscho ):WPLANG
option
is_admin() && add_filter( 'locale', function( $locale )
{
if( $lang = get_user_meta( get_current_user_id(), 'wpse_lang', true ) )
$locale= sanitize_text_field( $lang );
return $locale;
} );
where we check if the current user has the wpse_lang
user meta key set, with values like is_IS
, da_DK
, ...
Then we could add the language selection for each user, on the user settings page.
There we could use the wp_dropdown_languages()
function, with the get_available_languages()
function, to display the select-box for available languages.
Here's a good example by @sanchothefat on how we can add custom user settings.
We can display the user language selection with:
function wpse_user_language( $user )
{
$lang = get_user_meta( $user->ID, 'wpse_lang', true )
?>
<table class="form-table">
<tr>
<th><?php _e( 'Admin Language' ); ?></th>
<td>
<?php
wp_dropdown_languages(
[
'id' => 'wpse_lang',
'name' => 'wpse_lang',
'languages' => get_available_languages(),
'translations' => [],
'selected' => $lang,
'echo' => 1,
'show_available_translations' => false,
]
);
?>
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'wpse_user_language' );
add_action( 'edit_user_profile', 'wpse_user_language' );
and we can save it with:
function wpse_user_language_save( $user_id )
{
if( current_user_can( 'edit_user', $user_id ) && isset( $_POST['wpse_lang'] ) )
return update_user_meta( $user_id, 'wpse_lang', $_POST['wpse_lang'] );
return false;
}
add_action( 'personal_options_update', 'wpse_user_language_save' );
add_action( 'edit_user_profile_update', 'wpse_user_language_save' );
Here's an example output: