TranslatePress – Translate Multilingual sites - Version 1.9.2

Version Description

  • Fixed Norwegian language not working with Google Automatic Translation
  • Fixed loading localization text-domain in different language than expected.
  • Fixed gettext strings in incorrect language.
  • Fixed WooCommerce country and states translations.
Download this release

Release Info

Developer madalin.ungureanu
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 1.9.2
Comparing to
See all releases

Code changes from version 1.9.1 to 1.9.2

class-translate-press.php CHANGED
@@ -57,7 +57,7 @@ class TRP_Translate_Press{
57
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
58
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
59
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
60
- define( 'TRP_PLUGIN_VERSION', '1.9.1' );
61
 
62
  wp_cache_add_non_persistent_groups(array('trp'));
63
 
@@ -323,9 +323,11 @@ class TRP_Translate_Press{
323
 
324
  /* handle dynamic texts with gettext */
325
  $this->loader->add_filter( 'locale', $this->languages, 'change_locale', 99999 );
 
326
 
327
  $this->loader->add_action( 'init', $this->translation_manager, 'create_gettext_translated_global' );
328
  $this->loader->add_action( 'init', $this->translation_manager, 'initialize_gettext_processing' );
 
329
  $this->loader->add_action( 'shutdown', $this->translation_manager, 'machine_translate_gettext', 100 );
330
 
331
 
57
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
58
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
59
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
60
+ define( 'TRP_PLUGIN_VERSION', '1.9.2' );
61
 
62
  wp_cache_add_non_persistent_groups(array('trp'));
63
 
323
 
324
  /* handle dynamic texts with gettext */
325
  $this->loader->add_filter( 'locale', $this->languages, 'change_locale', 99999 );
326
+ $this->loader->add_filter( 'plugin_locale', $this->languages, 'change_locale', 99999 );
327
 
328
  $this->loader->add_action( 'init', $this->translation_manager, 'create_gettext_translated_global' );
329
  $this->loader->add_action( 'init', $this->translation_manager, 'initialize_gettext_processing' );
330
+ $this->loader->add_action( 'trp_call_gettext_filters', $this->translation_manager, 'verify_locale_of_loaded_textdomain' );
331
  $this->loader->add_action( 'shutdown', $this->translation_manager, 'machine_translate_gettext', 100 );
332
 
333
 
includes/class-languages.php CHANGED
@@ -93,6 +93,7 @@ class TRP_Languages{
93
  'zh_HK' => 'zh-TW',
94
  'zh_TW' => 'zh-TW',
95
  'zh_CN' => 'zh-CN',
 
96
  ) );
97
  foreach ( $language_codes as $language_code ) {
98
  if ( $map_google_codes && isset( $map_wp_codes_to_google[$language_code] ) ){
93
  'zh_HK' => 'zh-TW',
94
  'zh_TW' => 'zh-TW',
95
  'zh_CN' => 'zh-CN',
96
+ 'nb_NO' => 'no'
97
  ) );
98
  foreach ( $language_codes as $language_code ) {
99
  if ( $map_google_codes && isset( $map_wp_codes_to_google[$language_code] ) ){
includes/class-translation-manager.php CHANGED
@@ -524,14 +524,14 @@ class TRP_Translation_Manager
524
 
525
  global $trp_translated_gettext_texts;
526
  if (!is_admin() || $this::is_ajax_on_frontend()) {
527
- global $TRP_LANGUAGE;
528
 
529
  if (!$this->trp_query) {
530
  $trp = TRP_Translate_Press::get_trp_instance();
531
  $this->trp_query = $trp->get_component('query');
532
  }
533
 
534
- $strings = $this->trp_query->get_all_gettext_strings($TRP_LANGUAGE);
535
  if (!empty($strings)) {
536
  $trp_translated_gettext_texts = $strings;
537
 
@@ -601,7 +601,59 @@ class TRP_Translation_Manager
601
  add_filter('gettext_with_context', array($this, $prefix . 'process_gettext_strings_with_context'), 100, 4);
602
  add_filter('ngettext', array($this, $prefix . 'process_ngettext_strings'), 100, 5);
603
  add_filter('ngettext_with_context', array($this, $prefix . 'process_ngettext_strings_with_context'), 100, 6);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  }
 
 
 
605
  }
606
 
607
  /**
@@ -737,6 +789,10 @@ class TRP_Translation_Manager
737
  $tp_gettext_is_ajax_on_frontend = $this::is_ajax_on_frontend();
738
 
739
  if (!defined('DOING_AJAX') || $tp_gettext_is_ajax_on_frontend) {
 
 
 
 
740
  $db_id = '';
741
  $skip_gettext_querying = apply_filters('trp_skip_gettext_querying', false, $translation, $text, $domain);
742
  if (!$skip_gettext_querying) {
524
 
525
  global $trp_translated_gettext_texts;
526
  if (!is_admin() || $this::is_ajax_on_frontend()) {
527
+ $language = get_locale();
528
 
529
  if (!$this->trp_query) {
530
  $trp = TRP_Translate_Press::get_trp_instance();
531
  $this->trp_query = $trp->get_component('query');
532
  }
533
 
534
+ $strings = $this->trp_query->get_all_gettext_strings($language);
535
  if (!empty($strings)) {
536
  $trp_translated_gettext_texts = $strings;
537
 
601
  add_filter('gettext_with_context', array($this, $prefix . 'process_gettext_strings_with_context'), 100, 4);
602
  add_filter('ngettext', array($this, $prefix . 'process_ngettext_strings'), 100, 5);
603
  add_filter('ngettext_with_context', array($this, $prefix . 'process_ngettext_strings_with_context'), 100, 6);
604
+
605
+ do_action('trp_call_gettext_filters');
606
+ }
607
+ }
608
+
609
+ public function is_domain_loaded_in_locale( $domain, $locale ){
610
+ $localemo = $locale . '.mo';
611
+ $length = strlen( $localemo );
612
+
613
+ global $l10n;
614
+ if ( isset( $l10n[$domain] ) && is_object( $l10n[$domain] ) ) {
615
+ $mo_filename = $l10n[$domain]->get_filename();
616
+
617
+ // $mo_filename does not end with string $locale
618
+ if ( substr( strtolower( $mo_filename ), -$length ) == strtolower( $localemo ) ) {
619
+ return true;
620
+ }else{
621
+ return false;
622
+ }
623
+ }
624
+
625
+ // if something is not as expected, return true so that we do not interfere
626
+ return true;
627
+ }
628
+
629
+ public function verify_locale_of_loaded_textdomain(){
630
+ global $l10n;
631
+ if ( !empty( $l10n) && is_array( $l10n ) ){
632
+
633
+ $reload_domains = array();
634
+ $locale = get_locale();
635
+
636
+
637
+ foreach($l10n as $domain => $item ){
638
+ if ( !$this->is_domain_loaded_in_locale( $domain, $locale ) ) {
639
+ $reload_domains[] = $domain;
640
+ }
641
+ }
642
+
643
+ foreach($reload_domains as $domain ){
644
+ if ( isset( $l10n[$domain] ) && is_object( $l10n[$domain] ) ) {
645
+ $path = $l10n[ $domain ]->get_filename();
646
+ $new_path = preg_replace( '/' . $domain . '-(.*).mo$/i', $domain . '-' . $locale . '.mo', $path );
647
+ if ( $new_path !== $path ) {
648
+ unset( $l10n[ $domain ] );
649
+ load_textdomain( $domain, $new_path );
650
+ }
651
+ }
652
+ }
653
  }
654
+
655
+ // do this function only once per execution. The init hook can be called more than once
656
+ remove_action( 'trp_call_gettext_filters', array( $this, 'verify_locale_of_loaded_textdomain' ) );
657
  }
658
 
659
  /**
789
  $tp_gettext_is_ajax_on_frontend = $this::is_ajax_on_frontend();
790
 
791
  if (!defined('DOING_AJAX') || $tp_gettext_is_ajax_on_frontend) {
792
+ if ( !$this->is_domain_loaded_in_locale($domain, $current_locale) ){
793
+ $translation = $text;
794
+ }
795
+
796
  $db_id = '';
797
  $skip_gettext_querying = apply_filters('trp_skip_gettext_querying', false, $translation, $text, $domain);
798
  if (!$skip_gettext_querying) {
includes/compatibility-functions.php CHANGED
@@ -239,7 +239,7 @@ function trp_woo_data_strip_trpst( $data ){
239
  add_filter( 'trp_skip_selectors_from_dynamic_translation', 'trp_woo_skip_dynamic_translation' );
240
  function trp_woo_skip_dynamic_translation( $skip_selectors ){
241
  if( class_exists( 'WooCommerce' ) ) {
242
- $add_skip_selectors = array( '#select2-billing_country-results', '#select2-shipping_country-results' );
243
  return array_merge( $skip_selectors, $add_skip_selectors );
244
  }
245
  return $skip_selectors;
239
  add_filter( 'trp_skip_selectors_from_dynamic_translation', 'trp_woo_skip_dynamic_translation' );
240
  function trp_woo_skip_dynamic_translation( $skip_selectors ){
241
  if( class_exists( 'WooCommerce' ) ) {
242
+ $add_skip_selectors = array( '#billing_country', '#shipping_country', '#billing_state', '#shipping_state', '#select2-billing_country-results', '#select2-billing_state-results', '#select2-shipping_country-results', '#select2-shipping_state-results' );
243
  return array_merge( $skip_selectors, $add_skip_selectors );
244
  }
245
  return $skip_selectors;
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: 1.9.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: 1.9.2
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
languages/translatepress-multilingual.pot CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2020 TranslatePress Multilingual
2
  # This file is distributed under the same license as the TranslatePress Multilingual package.
3
  msgid ""
4
  msgstr ""
@@ -681,11 +681,11 @@ msgstr ""
681
  msgid "Translate Page"
682
  msgstr ""
683
 
684
- #: includes/class-translation-manager.php:1205
685
  msgid "Security check"
686
  msgstr ""
687
 
688
- #: includes/class-translation-manager.php:1279
689
  msgid "<strong>Warning:</strong> Some strings have possibly incorrectly encoded characters. This may result in breaking the queries, rendering the page untranslated in live mode. Consider revising the following strings or their method of outputting."
690
  msgstr ""
691
 
1
+ # Copyright (C) 2021 TranslatePress Multilingual
2
  # This file is distributed under the same license as the TranslatePress Multilingual package.
3
  msgid ""
4
  msgstr ""
681
  msgid "Translate Page"
682
  msgstr ""
683
 
684
+ #: includes/class-translation-manager.php:1261
685
  msgid "Security check"
686
  msgstr ""
687
 
688
+ #: includes/class-translation-manager.php:1335
689
  msgid "<strong>Warning:</strong> Some strings have possibly incorrectly encoded characters. This may result in breaking the queries, rendering the page untranslated in live mode. Consider revising the following strings or their method of outputting."
690
  msgstr ""
691
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: translate, translation, multilingual, automatic translation, bilingual, fr
5
  Requires at least: 3.1.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.6.20
8
- Stable tag: 1.9.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -138,6 +138,12 @@ For more information please check out our [documentation](https://translatepress
138
 
139
 
140
  == Changelog ==
 
 
 
 
 
 
141
  = 1.9.1 =
142
  * Fixing issue with WooCommerce slugs resulting in 404 if they were changed manually from the defaults in certain cases
143
  * Added a new cleanup option in settings
5
  Requires at least: 3.1.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.6.20
8
+ Stable tag: 1.9.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
138
 
139
 
140
  == Changelog ==
141
+ = 1.9.2 =
142
+ * Fixed Norwegian language not working with Google Automatic Translation
143
+ * Fixed loading localization text-domain in different language than expected.
144
+ * Fixed gettext strings in incorrect language.
145
+ * Fixed WooCommerce country and states translations.
146
+
147
  = 1.9.1 =
148
  * Fixing issue with WooCommerce slugs resulting in 404 if they were changed manually from the defaults in certain cases
149
  * Added a new cleanup option in settings