From 406da3563a70639a328f2553cbcab8dd60673d5a Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Thu, 8 Dec 2016 17:53:02 +0100 Subject: [PATCH 1/2] Use the user locale for the locale. --- i18n-module.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/i18n-module.php b/i18n-module.php index 990b280..af3f98b 100644 --- a/i18n-module.php +++ b/i18n-module.php @@ -111,7 +111,7 @@ public function __construct( $args ) { return; } - $this->locale = get_locale(); + $this->locale = get_admin_locale(); if ( 'en_US' === $this->locale ) { return; } @@ -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. * From a51518e25b72155076f530ff1a3d5d3443ee6586 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 2 Jan 2017 11:34:06 +0100 Subject: [PATCH 2/2] Fix method call. --- i18n-module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i18n-module.php b/i18n-module.php index af3f98b..d19ab9c 100644 --- a/i18n-module.php +++ b/i18n-module.php @@ -111,7 +111,7 @@ public function __construct( $args ) { return; } - $this->locale = get_admin_locale(); + $this->locale = $this->get_admin_locale(); if ( 'en_US' === $this->locale ) { return; }