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

Commit 9838ddd

Browse files
committed
fix save translation for enable languages without deleting translations for disable languages
1 parent d4a060e commit 9838ddd

6 files changed

+36
-10
lines changed

core/admin/class-wpm-admin-posts.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @author VaLeXaR
66
* @category Admin
77
* @package WPM/Core/Admin
8+
* @version 1.0.2
89
*/
910

1011
namespace WPM\Core\Admin;
@@ -193,7 +194,7 @@ public function render_language_column( $column ) {
193194
$text = $post->post_title . $post->post_content;
194195
$strings = wpm_value_to_ml_array( $text );
195196
$options = wpm_get_options();
196-
$languages = wpm_get_languages();
197+
$languages = wpm_get_all_languages();
197198

198199
foreach ( $languages as $locale => $language ) {
199200
if ( isset( $strings[ $language ] ) && ! empty( $strings[ $language ] ) ) {

core/admin/class-wpm-admin-taxonomies.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @author VaLeXaR
66
* @category Admin
77
* @package WPM/Core/Admin
8+
* @version 1.0.2
89
*/
910

1011
namespace WPM\Core\Admin;
@@ -207,7 +208,7 @@ public function render_language_column( $columns, $column, $term_id ) {
207208
$text = $term->name . $term->description;
208209
$strings = wpm_value_to_ml_array( $text );
209210
$options = wpm_get_options();
210-
$languages = wpm_get_languages();
211+
$languages = wpm_get_all_languages();
211212

212213
foreach ( $languages as $locale => $language ) {
213214
if ( isset( $strings[ $language ] ) && ! empty( $strings[ $language ] ) ) {

core/wpm-language-functions.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @author VaLeXaR
88
* @category Core
99
* @package WPM/Functions
10+
* @version 1.0.2
1011
*/
1112

1213
if ( ! defined( 'ABSPATH' ) ) {
@@ -26,6 +27,24 @@ function wpm_get_languages() {
2627
return WPM_Setup::instance()->get_languages();
2728
}
2829

30+
/**
31+
* Get enabled languages
32+
*
33+
* @see WPM_Setup::get_languages()
34+
*
35+
* @return array
36+
*/
37+
function wpm_get_all_languages() {
38+
$options = wpm_get_options();
39+
$languages = array();
40+
41+
foreach ( $options as $locale => $language ) {
42+
$languages[ $locale ] = $language['slug'];
43+
}
44+
45+
return $languages;
46+
}
47+
2948
/**
3049
* Get user language
3150
*
@@ -99,7 +118,8 @@ function wpm_get_translations() {
99118
*/
100119
function wpm_get_language() {
101120
if ( is_admin() ) {
102-
$lang = isset( $_GET['edit_lang'] ) ? wpm_clean( $_GET['edit_lang'] ) : ( isset( $_COOKIE['edit_language'] ) ? wpm_clean( $_COOKIE['edit_language'] ) : wpm_get_user_language() );
121+
$languages = wpm_get_languages();
122+
$lang = ( isset( $_GET['edit_lang'] ) && in_array( wpm_clean( $_GET['edit_lang'] ), $languages ) ) ? wpm_clean( $_GET['edit_lang'] ) : ( ( isset( $_COOKIE['edit_language'] ) && in_array( wpm_clean( $_COOKIE['edit_language'] ), $languages ) ) ? wpm_clean( $_COOKIE['edit_language'] ) : wpm_get_user_language() );
103123
} else {
104124
$lang = wpm_get_user_language();
105125
}

core/wpm-translation-functions.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @author VaLeXaR
88
* @category Core
99
* @package WPM/Functions
10+
* @version 1.0.2
1011
*/
1112
if ( ! defined( 'ABSPATH' ) ) {
1213
exit;
@@ -166,7 +167,7 @@ function wpm_string_to_ml_array( $string ) {
166167

167168
$result = array();
168169

169-
$languages = wpm_get_languages();
170+
$languages = wpm_get_all_languages();
170171

171172
foreach ( $languages as $language ) {
172173
$result[ $language ] = '';
@@ -248,7 +249,7 @@ function wpm_ml_array_to_string( $strings ) {
248249
return $string;
249250
}
250251

251-
$languages = wpm_get_languages();
252+
$languages = wpm_get_all_languages();
252253
foreach ( $strings as $key => $value ) {
253254
if ( in_array( $key, $languages ) && ! empty( $value ) ) {
254255
if ( wpm_is_ml_string( $value ) ) {
@@ -418,7 +419,7 @@ function wpm_is_ml_array( $array ) {
418419
return false;
419420
}
420421

421-
$languages = wpm_get_languages();
422+
$languages = wpm_get_all_languages();
422423

423424
foreach ( $array as $key => $item ) {
424425
if ( ! is_string( $key ) || ! in_array( $key, $languages ) ) {

readme.txt

+4-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.7
7-
Stable tag: 1.0.1
7+
Stable tag: 1.0.2
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -116,6 +116,9 @@ Compatible with multisite not tested.
116116

117117
== Changelog ==
118118

119+
= 1.0.2 =
120+
* fix save translation for enable languages without deleting translations for disable languages
121+
119122
= 1.0.1 =
120123
* fix update options when deleting language
121124
* fix set edit lang cookie

wp-multilang.php

+3-3
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.0.1
11+
* Version: 1.0.2
1212
*
1313
* @package WPM
1414
* @category Core
@@ -33,7 +33,7 @@
3333
* Main WP_Multilang.
3434
*
3535
* @class WPM
36-
* @version 1.0.1
36+
* @version 1.0.2
3737
*/
3838
final class WP_Multilang {
3939

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

4747
/**
4848
* The single instance of the class.

0 commit comments

Comments
 (0)