equal
deleted
inserted
replaced
43 * Stores the original locale as well as a list of all available languages. |
43 * Stores the original locale as well as a list of all available languages. |
44 * |
44 * |
45 * @since 4.7.0 |
45 * @since 4.7.0 |
46 */ |
46 */ |
47 public function __construct() { |
47 public function __construct() { |
48 $this->original_locale = is_admin() ? get_user_locale() : get_locale(); |
48 $this->original_locale = determine_locale(); |
49 $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() ); |
49 $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() ); |
50 } |
50 } |
51 |
51 |
52 /** |
52 /** |
53 * Initializes the locale switcher. |
53 * Initializes the locale switcher. |
54 * |
54 * |
55 * Hooks into the {@see 'locale'} filter to change the locale on the fly. |
55 * Hooks into the {@see 'locale'} filter to change the locale on the fly. |
|
56 * |
|
57 * @since 4.7.0 |
56 */ |
58 */ |
57 public function init() { |
59 public function init() { |
58 add_filter( 'locale', array( $this, 'filter_locale' ) ); |
60 add_filter( 'locale', array( $this, 'filter_locale' ) ); |
59 } |
61 } |
60 |
62 |
65 * |
67 * |
66 * @param string $locale The locale to switch to. |
68 * @param string $locale The locale to switch to. |
67 * @return bool True on success, false on failure. |
69 * @return bool True on success, false on failure. |
68 */ |
70 */ |
69 public function switch_to_locale( $locale ) { |
71 public function switch_to_locale( $locale ) { |
70 $current_locale = is_admin() ? get_user_locale() : get_locale(); |
72 $current_locale = determine_locale(); |
71 if ( $current_locale === $locale ) { |
73 if ( $current_locale === $locale ) { |
72 return false; |
74 return false; |
73 } |
75 } |
74 |
76 |
75 if ( ! in_array( $locale, $this->available_languages, true ) ) { |
77 if ( ! in_array( $locale, $this->available_languages, true ) ) { |