Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from Yoast/stories/af/15-use-the-user-language
Browse files Browse the repository at this point in the history
Use the user locale for the locale.
  • Loading branch information
terw-dan authored Jan 3, 2017
2 parents e620302 + a51518e commit 2c61739
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion i18n-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __construct( $args ) {
return;
}

$this->locale = get_locale();
$this->locale = $this->get_admin_locale();
if ( 'en_US' === $this->locale ) {
return;
}
Expand All @@ -123,6 +123,25 @@ public function __construct( $args ) {
}
}

/**
* Returns the locale used in the admin.
*
* WordPress 4.7 introduced the ability for users to specify an Admin language
* different from the language used on the front end. This checks if the feature
* is available and returns the user's language, with a fallback to the site's language.
* Can be removed when support for WordPress 4.6 will be dropped, in favor
* of WordPress get_user_locale() that already fallbacks to the site’s locale.
*
* @returns string The locale.
*/
private function get_admin_locale() {
if ( function_exists( 'get_user_locale' ) ) {
return get_user_locale();
}

return get_locale();
}

/**
* This is where you decide where to display the messages and where you set the plugin specific variables.
*
Expand Down

0 comments on commit 2c61739

Please sign in to comment.