Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 5c7126f

Browse files
committed
fix load theme localization files
1 parent c8409c4 commit 5c7126f

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

core/class-wpm-setup.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Class WPM_Setup
1313
* @package WPM\Core
1414
* @author VaLeXaR
15-
* @version 1.2.0
15+
* @version 1.2.1
1616
*/
1717
class WPM_Setup {
1818

@@ -99,6 +99,7 @@ public function __construct() {
9999
add_action( 'upgrader_process_complete', __NAMESPACE__ . '\WPM_Config::load_config_run' );
100100
add_action( 'wpm_init', array( $this, 'load_vendor' ) );
101101
add_action( 'template_redirect', array( $this, 'set_not_found' ) );
102+
add_action( 'init', array( $this, 'switch_to_language' ) );
102103
$this->init();
103104
}
104105

@@ -282,18 +283,15 @@ public function set_user_language() {
282283
* Set locale from user language
283284
*/
284285
public function set_locale() {
285-
286-
if ( ! did_action( 'before_wpm_init' ) ) {
287-
return;
288-
}
286+
global $locale;
289287

290288
$languages = $this->get_languages();
291289
$default_locale = $this->get_default_locale();
292290

293291
foreach ( $languages as $key => $value ) {
294292
$user_language = $this->get_user_language();
295293
if ( ( $value == $user_language ) ) {
296-
switch_to_locale( $key );
294+
$locale = $key;
297295
if ( $key == $default_locale && ! is_admin() && ! isset( $_GET['lang'] ) ) {
298296
wp_redirect( home_url( str_replace( '/' . $user_language . '/', '/', $_SERVER['REQUEST_URI'] ) ) );
299297
exit;
@@ -460,12 +458,19 @@ private function get_browser_language() {
460458
* Set 404 headers for not available language
461459
*/
462460
public function set_not_found() {
463-
$languages = $this->get_languages();
461+
$languages = $this->get_languages();
464462

465463
if ( ! in_array( $this->user_language, $languages ) ) {
466464
global $wp_query;
467465
$wp_query->set_404();
468466
status_header( 404 );
469467
}
470468
}
469+
470+
/**
471+
* Switch locale to language
472+
*/
473+
public function switch_to_language() {
474+
switch_to_locale( get_locale() );
475+
}
471476
}

readme.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: valexar
44
Tags: localization, multilanguage, multilingual, translation, multilang
55
Requires at least: 4.7
66
Tested up to: 4.8
7-
Stable tag: 1.3.4
7+
Stable tag: 1.3.5
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -133,6 +133,10 @@ Compatible with multisite not tested.
133133

134134
== Changelog ==
135135

136+
= 1.3.5 =
137+
* hide wp language settings
138+
* fix load theme localization files
139+
136140
= 1.3.4 =
137141
* add 404 error for not available language
138142
* fix translate option in init

wp-multilang.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
99
* Text Domain: wpm
1010
* Domain Path: /languages
11-
* Version: 1.3.4
11+
* Version: 1.3.5
1212
*
1313
* @package WPM
1414
* @category Core
@@ -33,7 +33,7 @@
3333
* Main WP_Multilang.
3434
*
3535
* @class WPM
36-
* @version 1.0.2
36+
* @version 1.0.3
3737
*/
3838
final class WP_Multilang {
3939

@@ -42,7 +42,7 @@ final class WP_Multilang {
4242
*
4343
* @var string
4444
*/
45-
public $version = '1.3.4';
45+
public $version = '1.3.5';
4646

4747
/**
4848
* The single instance of the class.
@@ -99,6 +99,7 @@ public function __construct() {
9999
private function init_hooks() {
100100
register_activation_hook( __FILE__, array( 'WPM\Core\WPM_Install', 'install' ) );
101101
add_action( 'init', array( $this, 'init' ), 0 );
102+
add_action( 'setup_theme', array( $this, 'setup' ), 0 );
102103
}
103104

104105
/**
@@ -158,15 +159,18 @@ public function includes() {
158159
}
159160
}
160161

162+
163+
public function setup() {
164+
Core\WPM_Setup::instance();
165+
}
166+
161167
/**
162168
* Init Multilang when WordPress Initialises.
163169
*/
164170
public function init() {
165171
// Before init action.
166172
do_action( 'before_wpm_init' );
167173

168-
Core\WPM_Setup::instance();
169-
170174
// Set up localisation.
171175
$this->load_plugin_textdomain();
172176

0 commit comments

Comments
 (0)