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

Commit 2c61739

Browse files
authored
Merge pull request #16 from Yoast/stories/af/15-use-the-user-language
Use the user locale for the locale.
2 parents e620302 + a51518e commit 2c61739

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

i18n-module.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function __construct( $args ) {
111111
return;
112112
}
113113

114-
$this->locale = get_locale();
114+
$this->locale = $this->get_admin_locale();
115115
if ( 'en_US' === $this->locale ) {
116116
return;
117117
}
@@ -123,6 +123,25 @@ public function __construct( $args ) {
123123
}
124124
}
125125

126+
/**
127+
* Returns the locale used in the admin.
128+
*
129+
* WordPress 4.7 introduced the ability for users to specify an Admin language
130+
* different from the language used on the front end. This checks if the feature
131+
* is available and returns the user's language, with a fallback to the site's language.
132+
* Can be removed when support for WordPress 4.6 will be dropped, in favor
133+
* of WordPress get_user_locale() that already fallbacks to the site’s locale.
134+
*
135+
* @returns string The locale.
136+
*/
137+
private function get_admin_locale() {
138+
if ( function_exists( 'get_user_locale' ) ) {
139+
return get_user_locale();
140+
}
141+
142+
return get_locale();
143+
}
144+
126145
/**
127146
* This is where you decide where to display the messages and where you set the plugin specific variables.
128147
*

0 commit comments

Comments
 (0)