TranslatePress – Translate Multilingual sites - Version 2.1.2

Version Description

  • Added Advanced option to show opposite language in shortcode language switcher
  • Added CSS class current-language-menu-item to menu language switcher to allow customization
  • Fixed notice in PHP 8 related to custom-languages
  • Corrected Swahili flag
Download this release

Release Info

Developer razvan.mo
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 2.1.2
Comparing to
See all releases

Code changes from version 2.1.1 to 2.1.2

assets/css/trp-language-switcher.css CHANGED
@@ -119,4 +119,3 @@
119
  display: block;
120
  }
121
  }
122
-
119
  display: block;
120
  }
121
  }
 
assets/images/flags/sw.png CHANGED
Binary file
class-translate-press.php CHANGED
@@ -58,7 +58,7 @@ class TRP_Translate_Press{
58
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
59
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
60
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
61
- define( 'TRP_PLUGIN_VERSION', '2.1.1' );
62
 
63
  wp_cache_add_non_persistent_groups(array('trp'));
64
 
58
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
59
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
60
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
61
+ define( 'TRP_PLUGIN_VERSION', '2.1.2' );
62
 
63
  wp_cache_add_non_persistent_groups(array('trp'));
64
 
includes/advanced-settings/opposite-flag-shortcode.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_filter( 'trp_register_advanced_settings', 'trp_show_opposite_flag_language_switcher_shortcode', 1250 );
4
+ function trp_show_opposite_flag_language_switcher_shortcode( $settings_array ){
5
+ $settings_array[] = array(
6
+ 'name' => 'show_opposite_flag_language_switcher_shortcode',
7
+ 'type' => 'checkbox',
8
+ 'label' => esc_html__( 'Show opposite language in the shortcode language switcher', 'translatepress-multilingual' ),
9
+ 'description' => wp_kses( __( 'Transforms the shortcode language switcher into a button showing the other available language, not the current one.<br> Only works when there are exactly two languages, the default one and a translation one.<br>Does not affect floating language switcher or menu language switcher.', 'translatepress-multilingual' ), array( 'br' => array()) ),
10
+ );
11
+ return $settings_array;
12
+ }
13
+
14
+ function trp_opposite_ls_current_language( $current_language, $published_languages, $TRP_LANGUAGE, $settings ){
15
+ if ( count ( $published_languages ) == 2 ) {
16
+ foreach ($published_languages as $code => $name) {
17
+ if ($code != $TRP_LANGUAGE) {
18
+ $current_language['code'] = $code;
19
+ $current_language['name'] = $name;
20
+ break;
21
+ }
22
+ }
23
+ }
24
+ return $current_language;
25
+ }
26
+
27
+ function trp_opposite_ls_other_language( $other_language, $published_languages, $TRP_LANGUAGE, $settings ){
28
+ if ( count ( $published_languages ) == 2 ) {
29
+ $other_language = array();
30
+ foreach ($published_languages as $code => $name) {
31
+ if ($code != $TRP_LANGUAGE) {
32
+ $other_language[$code] = $name;
33
+ break;
34
+ }
35
+ }
36
+ }
37
+ return $other_language;
38
+ }
39
+
40
+ function trp_opposite_ls_hide_disabled_language($return, $current_language, $current_language_preference, $settings){
41
+ if ( count( $settings['publish-languages'] ) == 2 ){
42
+ return false;
43
+ }
44
+ return $return;
45
+ }
46
+
47
+ function trp_enqueue_language_switcher_shortcode_scripts(){
48
+ $trp = TRP_Translate_Press::get_trp_instance();
49
+ $trp_languages = $trp->get_component( 'languages' );
50
+ $trp_settings = $trp->get_component( 'settings' );
51
+ $published_languages = $trp_languages->get_language_names( $trp_settings->get_settings()['publish-languages'] );
52
+ if(count ( $published_languages ) == 2 ) {
53
+ wp_add_inline_style( 'trp-language-switcher-style', '.trp-language-switcher > div {
54
+ padding: 3px 5px 3px 5px;
55
+ background-image: none;
56
+ text-align: center;}' );
57
+ }
58
+ }
59
+
60
+ function trp_show_opposite_flag_settings(){
61
+ $option = get_option( 'trp_advanced_settings', true );
62
+
63
+ if(isset($option['show_opposite_flag_language_switcher_shortcode']) && $option['show_opposite_flag_language_switcher_shortcode'] !== 'no'){
64
+ add_filter( 'trp_ls_shortcode_current_language', 'trp_opposite_ls_current_language', 10, 4 );
65
+ add_filter( 'trp_ls_shortcode_other_languages', 'trp_opposite_ls_other_language', 10, 4 );
66
+ add_filter( 'trp_ls_shortcode_show_disabled_language', 'trp_opposite_ls_hide_disabled_language', 10, 4 );
67
+ add_action( 'wp_enqueue_scripts', 'trp_enqueue_language_switcher_shortcode_scripts', 20 );
68
+ }
69
+ }
70
+
71
+ trp_show_opposite_flag_settings();
includes/class-advanced-tab.php CHANGED
@@ -227,6 +227,7 @@ class TRP_Advanced_Tab {
227
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/disable-languages-sitemap.php');
228
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/remove-duplicates-from-db.php');
229
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/do-not-translate-certain-paths.php');
 
230
  }
231
 
232
  /*
227
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/disable-languages-sitemap.php');
228
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/remove-duplicates-from-db.php');
229
  include_once(TRP_PLUGIN_DIR . 'includes/advanced-settings/do-not-translate-certain-paths.php');
230
+ include_once (TRP_PLUGIN_DIR . 'includes/advanced-settings/opposite-flag-shortcode.php');
231
  }
232
 
233
  /*
includes/class-language-switcher.php CHANGED
@@ -527,5 +527,4 @@ class TRP_Language_Switcher{
527
  return $items;
528
  }
529
 
530
-
531
  }
527
  return $items;
528
  }
529
 
 
530
  }
includes/compatibility-functions.php CHANGED
@@ -1245,12 +1245,10 @@ function trp_add_current_menu_item_css_class( $items ){
1245
  $trp_settings = $trp->get_component( 'settings' );
1246
  $settings = $trp_settings->get_settings();
1247
 
1248
- if ( $TRP_LANGUAGE === $settings['default-language'] && isset( $settings['add-subdirectory-to-default-language']) && $settings['add-subdirectory-to-default-language'] !== 'yes' ) {
1249
- return $items;
1250
- }
1251
-
1252
  foreach( $items as $item ){
1253
- if ( !in_array( 'current-menu-item', $item->classes ) && !in_array( 'menu-item-object-language_switcher', $item->classes ) && ( !empty($item->url) && $item->url !== '#')){
 
 
1254
  $url_for_language = $url_converter->get_url_for_language( $TRP_LANGUAGE, $item->url );
1255
  $url_for_language = strpos( $url_for_language, '#' ) ? substr( $url_for_language, 0, strpos( $url_for_language, '#' ) ) : $url_for_language;
1256
  $cur_page_url = set_url_scheme( untrailingslashit( $url_converter->cur_page_url() ) );
@@ -1259,6 +1257,17 @@ function trp_add_current_menu_item_css_class( $items ){
1259
  $item->classes[] = 'current-menu-item';
1260
  }
1261
  }
 
 
 
 
 
 
 
 
 
 
 
1262
  }
1263
  return $items;
1264
  }
1245
  $trp_settings = $trp->get_component( 'settings' );
1246
  $settings = $trp_settings->get_settings();
1247
 
 
 
 
 
1248
  foreach( $items as $item ){
1249
+ if ( !( $TRP_LANGUAGE === $settings['default-language'] && isset( $settings['add-subdirectory-to-default-language']) && $settings['add-subdirectory-to-default-language'] !== 'yes' ) &&
1250
+ !in_array( 'current-menu-item', $item->classes ) && !in_array( 'menu-item-object-language_switcher', $item->classes ) && ( !empty($item->url) && $item->url !== '#')
1251
+ ){
1252
  $url_for_language = $url_converter->get_url_for_language( $TRP_LANGUAGE, $item->url );
1253
  $url_for_language = strpos( $url_for_language, '#' ) ? substr( $url_for_language, 0, strpos( $url_for_language, '#' ) ) : $url_for_language;
1254
  $cur_page_url = set_url_scheme( untrailingslashit( $url_converter->cur_page_url() ) );
1257
  $item->classes[] = 'current-menu-item';
1258
  }
1259
  }
1260
+ if(!in_array('current-language-menu-item', $item->classes) && in_array('menu-item-object-language_switcher', $item->classes)){
1261
+ $current_language = $url_converter->get_lang_from_url_string($item->url);
1262
+
1263
+ if($current_language == null){
1264
+ $current_language = $settings['default-language'];
1265
+ }
1266
+
1267
+ if($current_language == $TRP_LANGUAGE){
1268
+ $item->classes[] = 'current-language-menu-item';
1269
+ }
1270
+ }
1271
  }
1272
  return $items;
1273
  }
includes/custom-language.php CHANGED
@@ -192,10 +192,9 @@ function trp_verify_custom_language_codes($is_correct_code, $settings){
192
  'message' => '',
193
  'correct_code' => $is_correct_code
194
  );
195
-
196
  }
197
 
198
- function trp_add_messages_custom_language_codes($correct_code=true, $settings, $submitted_settings){
199
 
200
  $correct_code_custom_language = trp_verify_custom_language_codes(true, $settings);
201
 
192
  'message' => '',
193
  'correct_code' => $is_correct_code
194
  );
 
195
  }
196
 
197
+ function trp_add_messages_custom_language_codes($correct_code, $settings, $submitted_settings){
198
 
199
  $correct_code_custom_language = trp_verify_custom_language_codes(true, $settings);
200
 
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site using a visual front-end translation editor, with full support for WooCommerce and site builders.
6
- Version: 2.1.1
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site using a visual front-end translation editor, with full support for WooCommerce and site builders.
6
+ Version: 2.1.2
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
languages/translatepress-multilingual.catalog.php CHANGED
@@ -376,6 +376,8 @@
376
  <?php __("Fixes attributes without spaces between them because they are not valid HTML.<br> May help fix missing or broken content from the HTML on translated pages.", "translatepress-multilingual"); ?>
377
  <?php __("Force slash at end of home url:", "translatepress-multilingual"); ?>
378
  <?php __("Ads a slash at the end of the home_url() function", "translatepress-multilingual"); ?>
 
 
379
  <?php __("Remove duplicate rows", "translatepress-multilingual"); ?>
380
  <?php __("Click <a href=\"%s\">here</a> to remove duplicate rows from the database.", "translatepress-multilingual"); ?>
381
  <?php __("Troubleshooting", "translatepress-multilingual"); ?>
376
  <?php __("Fixes attributes without spaces between them because they are not valid HTML.<br> May help fix missing or broken content from the HTML on translated pages.", "translatepress-multilingual"); ?>
377
  <?php __("Force slash at end of home url:", "translatepress-multilingual"); ?>
378
  <?php __("Ads a slash at the end of the home_url() function", "translatepress-multilingual"); ?>
379
+ <?php __("Show opposite language in the shortcode language switcher", "translatepress-multilingual"); ?>
380
+ <?php __("Transforms the shortcode language switcher into a button showing the other available language, not the current one.<br> Only works when there are exactly two languages, the default one and a translation one.<br>Does not affect floating language switcher or menu language switcher.", "translatepress-multilingual"); ?>
381
  <?php __("Remove duplicate rows", "translatepress-multilingual"); ?>
382
  <?php __("Click <a href=\"%s\">here</a> to remove duplicate rows from the database.", "translatepress-multilingual"); ?>
383
  <?php __("Troubleshooting", "translatepress-multilingual"); ?>
languages/translatepress-multilingual.pot CHANGED
@@ -49,23 +49,23 @@ msgstr ""
49
  msgid "Settings saved."
50
  msgstr ""
51
 
52
- #: includes/class-advanced-tab.php:311, includes/class-error-manager.php:172, partials/machine-translation-settings-page.php:13, partials/machine-translation-settings-page.php:117, partials/machine-translation-settings-page.php:150, partials/main-settings-page.php:41, partials/main-settings-page.php:54, partials/main-settings-page.php:67
53
  msgid "Yes"
54
  msgstr ""
55
 
56
- #: includes/class-advanced-tab.php:508, includes/class-advanced-tab.php:519, includes/class-advanced-tab.php:613, includes/class-advanced-tab.php:644
57
  msgid "Are you sure you want to remove this item?"
58
  msgstr ""
59
 
60
- #: includes/class-advanced-tab.php:508, includes/class-advanced-tab.php:519, includes/class-advanced-tab.php:613, includes/class-advanced-tab.php:644, partials/main-settings-language-selector.php:40, add-ons-advanced/extra-languages/partials/language-selector-pro.php:43
61
  msgid "Remove"
62
  msgstr ""
63
 
64
- #: includes/class-advanced-tab.php:519, includes/class-advanced-tab.php:644, partials/main-settings-language-selector.php:82, add-ons-advanced/extra-languages/partials/language-selector-pro.php:84
65
  msgid "Add"
66
  msgstr ""
67
 
68
- #: includes/class-advanced-tab.php:597, includes/class-advanced-tab.php:631
69
  msgid "Select..."
70
  msgstr ""
71
 
@@ -865,7 +865,7 @@ msgstr ""
865
  msgid "<strong>TranslatePress</strong> requires <strong><a href=\"http://php.net/manual/en/book.mbstring.php\">Multibyte String PHP library</a></strong>. Please contact your server administrator to install it on your server."
866
  msgstr ""
867
 
868
- #: includes/compatibility-functions.php:1494
869
  msgid "Detected long query limitation on WPEngine hosting. Some large pages may appear untranslated. You can remove limitation by adding the following to your site’s wp-config.php: define( 'WPE_GOVERNOR', false ); "
870
  msgstr ""
871
 
@@ -1527,6 +1527,14 @@ msgstr ""
1527
  msgid "Ads a slash at the end of the home_url() function"
1528
  msgstr ""
1529
 
 
 
 
 
 
 
 
 
1530
  #: includes/advanced-settings/remove-duplicates-from-db.php:7
1531
  msgid "Remove duplicate rows"
1532
  msgstr ""
49
  msgid "Settings saved."
50
  msgstr ""
51
 
52
+ #: includes/class-advanced-tab.php:312, includes/class-error-manager.php:172, partials/machine-translation-settings-page.php:13, partials/machine-translation-settings-page.php:117, partials/machine-translation-settings-page.php:150, partials/main-settings-page.php:41, partials/main-settings-page.php:54, partials/main-settings-page.php:67
53
  msgid "Yes"
54
  msgstr ""
55
 
56
+ #: includes/class-advanced-tab.php:509, includes/class-advanced-tab.php:520, includes/class-advanced-tab.php:614, includes/class-advanced-tab.php:645
57
  msgid "Are you sure you want to remove this item?"
58
  msgstr ""
59
 
60
+ #: includes/class-advanced-tab.php:509, includes/class-advanced-tab.php:520, includes/class-advanced-tab.php:614, includes/class-advanced-tab.php:645, partials/main-settings-language-selector.php:40, add-ons-advanced/extra-languages/partials/language-selector-pro.php:43
61
  msgid "Remove"
62
  msgstr ""
63
 
64
+ #: includes/class-advanced-tab.php:520, includes/class-advanced-tab.php:645, partials/main-settings-language-selector.php:82, add-ons-advanced/extra-languages/partials/language-selector-pro.php:84
65
  msgid "Add"
66
  msgstr ""
67
 
68
+ #: includes/class-advanced-tab.php:598, includes/class-advanced-tab.php:632
69
  msgid "Select..."
70
  msgstr ""
71
 
865
  msgid "<strong>TranslatePress</strong> requires <strong><a href=\"http://php.net/manual/en/book.mbstring.php\">Multibyte String PHP library</a></strong>. Please contact your server administrator to install it on your server."
866
  msgstr ""
867
 
868
+ #: includes/compatibility-functions.php:1503
869
  msgid "Detected long query limitation on WPEngine hosting. Some large pages may appear untranslated. You can remove limitation by adding the following to your site’s wp-config.php: define( 'WPE_GOVERNOR', false ); "
870
  msgstr ""
871
 
1527
  msgid "Ads a slash at the end of the home_url() function"
1528
  msgstr ""
1529
 
1530
+ #: includes/advanced-settings/opposite-flag-shortcode.php:8
1531
+ msgid "Show opposite language in the shortcode language switcher"
1532
+ msgstr ""
1533
+
1534
+ #: includes/advanced-settings/opposite-flag-shortcode.php:9
1535
+ msgid "Transforms the shortcode language switcher into a button showing the other available language, not the current one.<br> Only works when there are exactly two languages, the default one and a translation one.<br>Does not affect floating language switcher or menu language switcher."
1536
+ msgstr ""
1537
+
1538
  #: includes/advanced-settings/remove-duplicates-from-db.php:7
1539
  msgid "Remove duplicate rows"
1540
  msgstr ""
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: cozmoslabs, razvan.mo, madalin.ungureanu, sareiodata, cristophor
3
  Donate link: https://www.translatepress.com/
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
- Tested up to: 5.8
7
  Requires PHP: 5.6.20
8
- Stable tag: 2.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -140,6 +140,12 @@ For more information please check out our [documentation](https://translatepress
140
 
141
 
142
  == Changelog ==
 
 
 
 
 
 
143
  = 2.1.1 =
144
  * Improved Custom Languages feature
145
  * Added possibility to easily edit existing language name or flag through Custom Language
3
  Donate link: https://www.translatepress.com/
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
+ Tested up to: 5.8.1
7
  Requires PHP: 5.6.20
8
+ Stable tag: 2.1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
140
 
141
 
142
  == Changelog ==
143
+ = 2.1.2 =
144
+ * Added Advanced option to show opposite language in shortcode language switcher
145
+ * Added CSS class current-language-menu-item to menu language switcher to allow customization
146
+ * Fixed notice in PHP 8 related to custom-languages
147
+ * Corrected Swahili flag
148
+
149
  = 2.1.1 =
150
  * Improved Custom Languages feature
151
  * Added possibility to easily edit existing language name or flag through Custom Language