Version Description
- Fixed cases of sprintf errors when running PHP 8+
- Fixed some gettext strings not selectable in Translation Editor when on secondary languages
- Fixed edge case not being able to save CPT when slug is translated and default language subdirectory is enabled
- Improved trp_language conditional shortcode by not running contents through Automatic Translation
Download this release
Release Info
| Developer | razvan.mo |
| Plugin | |
| Version | 2.4.3 |
| Comparing to | |
| See all releases | |
Code changes from version 2.4.2 to 2.4.3
- class-translate-press.php +1 -1
- includes/class-languages.php +1 -10
- includes/class-machine-translator.php +19 -3
- includes/gettext/class-process-gettext.php +19 -2
- includes/shortcodes.php +24 -0
- index.php +2 -2
- languages/translatepress-multilingual.pot +2 -2
- readme.txt +7 -1
class-translate-press.php
CHANGED
|
@@ -64,7 +64,7 @@ class TRP_Translate_Press{
|
|
| 64 |
define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
| 65 |
define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
|
| 66 |
define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
|
| 67 |
-
define( 'TRP_PLUGIN_VERSION', '2.4.
|
| 68 |
|
| 69 |
wp_cache_add_non_persistent_groups(array('trp'));
|
| 70 |
|
| 64 |
define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
| 65 |
define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
|
| 66 |
define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
|
| 67 |
+
define( 'TRP_PLUGIN_VERSION', '2.4.3' );
|
| 68 |
|
| 69 |
wp_cache_add_non_persistent_groups(array('trp'));
|
| 70 |
|
includes/class-languages.php
CHANGED
|
@@ -51,12 +51,6 @@ class TRP_Languages{
|
|
| 51 |
* @return mixed
|
| 52 |
*/
|
| 53 |
public function change_locale( $locale ){
|
| 54 |
-
$cache_key = 'trp_locale';
|
| 55 |
-
|
| 56 |
-
$locale_cache = wp_cache_get( $cache_key );
|
| 57 |
-
if (false !== $locale_cache){
|
| 58 |
-
return $locale_cache;
|
| 59 |
-
}
|
| 60 |
|
| 61 |
if ( $this->is_string_translation_request_for_different_language() ){
|
| 62 |
$trp_ajax_language = (isset($_POST['trp_ajax_language']) ) ? sanitize_text_field( $_POST['trp_ajax_language'] ) : '';
|
|
@@ -66,19 +60,17 @@ class TRP_Languages{
|
|
| 66 |
$this->settings = $trp_settings->get_settings();
|
| 67 |
}
|
| 68 |
if ( $trp_ajax_language && in_array( $trp_ajax_language, $this->settings['translation-languages'] ) ){
|
| 69 |
-
wp_cache_set( $cache_key, $trp_ajax_language );
|
| 70 |
return $trp_ajax_language;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
-
if (
|
| 75 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 76 |
$trp_is_admin_request = $trp->get_component( 'url_converter' );
|
| 77 |
$this->is_admin_request= $trp_is_admin_request->is_admin_request();
|
| 78 |
}
|
| 79 |
|
| 80 |
if ( $this->is_admin_request ){
|
| 81 |
-
wp_cache_set( $cache_key, $locale );
|
| 82 |
return $locale;
|
| 83 |
}
|
| 84 |
|
|
@@ -86,7 +78,6 @@ class TRP_Languages{
|
|
| 86 |
if( !empty($TRP_LANGUAGE) ){
|
| 87 |
$locale = $TRP_LANGUAGE;
|
| 88 |
}
|
| 89 |
-
wp_cache_set( $cache_key, $locale );
|
| 90 |
return $locale;
|
| 91 |
}
|
| 92 |
|
| 51 |
* @return mixed
|
| 52 |
*/
|
| 53 |
public function change_locale( $locale ){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if ( $this->is_string_translation_request_for_different_language() ){
|
| 56 |
$trp_ajax_language = (isset($_POST['trp_ajax_language']) ) ? sanitize_text_field( $_POST['trp_ajax_language'] ) : '';
|
| 60 |
$this->settings = $trp_settings->get_settings();
|
| 61 |
}
|
| 62 |
if ( $trp_ajax_language && in_array( $trp_ajax_language, $this->settings['translation-languages'] ) ){
|
|
|
|
| 63 |
return $trp_ajax_language;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 67 |
+
if ( $this->is_admin_request === null ){
|
| 68 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 69 |
$trp_is_admin_request = $trp->get_component( 'url_converter' );
|
| 70 |
$this->is_admin_request= $trp_is_admin_request->is_admin_request();
|
| 71 |
}
|
| 72 |
|
| 73 |
if ( $this->is_admin_request ){
|
|
|
|
| 74 |
return $locale;
|
| 75 |
}
|
| 76 |
|
| 78 |
if( !empty($TRP_LANGUAGE) ){
|
| 79 |
$locale = $TRP_LANGUAGE;
|
| 80 |
}
|
|
|
|
| 81 |
return $locale;
|
| 82 |
}
|
| 83 |
|
includes/class-machine-translator.php
CHANGED
|
@@ -29,7 +29,8 @@ class TRP_Machine_Translator {
|
|
| 29 |
$this->trp_languages = $trp->get_component('languages');
|
| 30 |
}
|
| 31 |
$this->machine_translation_codes = $this->trp_languages->get_iso_codes($this->settings['translation-languages']);
|
| 32 |
-
add_filter( 'trp_exclude_words_from_automatic_translation', array( $this,'sort_exclude_words_from_automatic_translation_array'), 99999, 1);
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
|
@@ -316,8 +317,9 @@ class TRP_Machine_Translator {
|
|
| 316 |
if ( !empty($strings) && is_array($strings) && method_exists( $this, 'translate_array' ) && apply_filters( 'trp_disable_automatic_translations_due_to_error', false ) === false ) {
|
| 317 |
|
| 318 |
/* google has a problem translating this characters ( '%', '$', '#' )...for some reasons it puts spaces after them so we need to 'encode' them and decode them back. hopefully it won't break anything important */
|
| 319 |
-
/* we put '%s' before '%' because google seems to transform %s into % in strings for some languages which causes a 500
|
| 320 |
-
$
|
|
|
|
| 321 |
$placeholders = $this->get_placeholders(count($trp_exclude_words_from_automatic_translation));
|
| 322 |
$shortcode_tags_to_execute = apply_filters( 'trp_do_these_shortcodes_before_automatic_translation', array('trp_language') );
|
| 323 |
|
|
@@ -380,4 +382,18 @@ class TRP_Machine_Translator {
|
|
| 380 |
public function extra_request_validations( $to_language ){
|
| 381 |
return true;
|
| 382 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
}
|
| 29 |
$this->trp_languages = $trp->get_component('languages');
|
| 30 |
}
|
| 31 |
$this->machine_translation_codes = $this->trp_languages->get_iso_codes($this->settings['translation-languages']);
|
| 32 |
+
add_filter( 'trp_exclude_words_from_automatic_translation', array( $this, 'sort_exclude_words_from_automatic_translation_array' ), 99999, 1 );
|
| 33 |
+
add_filter( 'trp_exclude_words_from_automatic_translation', array( $this, 'exclude_special_symbol_from_translation' ), 9999, 2 );
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 317 |
if ( !empty($strings) && is_array($strings) && method_exists( $this, 'translate_array' ) && apply_filters( 'trp_disable_automatic_translations_due_to_error', false ) === false ) {
|
| 318 |
|
| 319 |
/* google has a problem translating this characters ( '%', '$', '#' )...for some reasons it puts spaces after them so we need to 'encode' them and decode them back. hopefully it won't break anything important */
|
| 320 |
+
/* we put '%s' before '%' because google seems to transform %s into % in strings for some languages which causes a 500 Fatal Error in PHP 8*/
|
| 321 |
+
$imploded_strings = implode(" ", $strings);
|
| 322 |
+
$trp_exclude_words_from_automatic_translation = apply_filters('trp_exclude_words_from_automatic_translation', array('%s', '%d', '%', '$', '#'), $imploded_strings);
|
| 323 |
$placeholders = $this->get_placeholders(count($trp_exclude_words_from_automatic_translation));
|
| 324 |
$shortcode_tags_to_execute = apply_filters( 'trp_do_these_shortcodes_before_automatic_translation', array('trp_language') );
|
| 325 |
|
| 382 |
public function extra_request_validations( $to_language ){
|
| 383 |
return true;
|
| 384 |
}
|
| 385 |
+
|
| 386 |
+
public function exclude_special_symbol_from_translation($array, $strings){
|
| 387 |
+
$float_array_symbols = array('d', 's', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H');
|
| 388 |
+
foreach ($float_array_symbols as $float_array_symbol){
|
| 389 |
+
for($i= 1; $i<=10; $i++) {
|
| 390 |
+
$symbol = '%'.$i .'$'.$float_array_symbol;
|
| 391 |
+
if ( strpos( $strings, $symbol ) !== false ) {
|
| 392 |
+
$array[] = '%' . $i . '$' . $float_array_symbol;
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
return $array;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
}
|
includes/gettext/class-process-gettext.php
CHANGED
|
@@ -105,7 +105,7 @@ class TRP_Process_Gettext {
|
|
| 105 |
if ( isset( $trp_translated_gettext_texts[ $context . '::' . $plural_form . '::' . $domain . '::' . $text ] ) ) {
|
| 106 |
$trp_translated_gettext_text = $trp_translated_gettext_texts[ $context . '::' . $plural_form . '::' . $domain . '::' . $text ];
|
| 107 |
|
| 108 |
-
if (!empty($trp_translated_gettext_text['translated']) && $translation != $trp_translated_gettext_text['translated'] ) {
|
| 109 |
$translation = str_replace(trim($text), trp_sanitize_string($trp_translated_gettext_text['translated']), $text);
|
| 110 |
}
|
| 111 |
$db_id = $trp_translated_gettext_text['id'];
|
|
@@ -393,11 +393,28 @@ class TRP_Process_Gettext {
|
|
| 393 |
}
|
| 394 |
|
| 395 |
if ( isset( $trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ] ) &&
|
| 396 |
-
!empty($trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ]['translated']
|
|
|
|
| 397 |
){
|
| 398 |
$translation = str_replace(trim($text), trp_sanitize_string($trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ]['translated']), $text);
|
| 399 |
}
|
| 400 |
|
| 401 |
return $translation;
|
| 402 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
}
|
| 105 |
if ( isset( $trp_translated_gettext_texts[ $context . '::' . $plural_form . '::' . $domain . '::' . $text ] ) ) {
|
| 106 |
$trp_translated_gettext_text = $trp_translated_gettext_texts[ $context . '::' . $plural_form . '::' . $domain . '::' . $text ];
|
| 107 |
|
| 108 |
+
if (!empty($trp_translated_gettext_text['translated']) && $translation != $trp_translated_gettext_text['translated'] && $this->is_sprintf_compatible( $trp_translated_gettext_text['translated'] ) ) {
|
| 109 |
$translation = str_replace(trim($text), trp_sanitize_string($trp_translated_gettext_text['translated']), $text);
|
| 110 |
}
|
| 111 |
$db_id = $trp_translated_gettext_text['id'];
|
| 393 |
}
|
| 394 |
|
| 395 |
if ( isset( $trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ] ) &&
|
| 396 |
+
!empty($trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ]['translated']) &&
|
| 397 |
+
$this->is_sprintf_compatible( $trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ]['translated'] )
|
| 398 |
){
|
| 399 |
$translation = str_replace(trim($text), trp_sanitize_string($trp_translated_gettext_texts[ 'trp_context' . '::' . 0 . '::' . $domain . '::' . $text ]['translated']), $text);
|
| 400 |
}
|
| 401 |
|
| 402 |
return $translation;
|
| 403 |
}
|
| 404 |
+
|
| 405 |
+
public function is_sprintf_compatible($string){
|
| 406 |
+
|
| 407 |
+
if (! apply_filters('trp_check_sprintf_compatibility', true ) ){
|
| 408 |
+
return true;
|
| 409 |
+
}
|
| 410 |
+
// 200 arguments should be enough. If a string has more than 200 placeholders then it might cause "Warning: sprintf(): Too few arguments" on certain php versions
|
| 411 |
+
$arr = array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
|
| 412 |
+
$is_compatible = true;
|
| 413 |
+
try{
|
| 414 |
+
$test = sprintf($string, ...$arr);
|
| 415 |
+
}catch(Throwable $e){
|
| 416 |
+
$is_compatible = false;
|
| 417 |
+
}
|
| 418 |
+
return $is_compatible;
|
| 419 |
+
}
|
| 420 |
}
|
includes/shortcodes.php
CHANGED
|
@@ -6,7 +6,16 @@ add_shortcode( 'trp_language', 'trp_language_content');
|
|
| 6 |
* Shortcode [trp_language language="en_EN"] [/trp_language]
|
| 7 |
* --------------------------------------------------------------------------- */
|
| 8 |
|
|
|
|
| 9 |
function trp_language_content( $attr, $content = null ){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
extract(shortcode_atts(array(
|
| 11 |
'language' => '',
|
| 12 |
), $attr));
|
|
@@ -20,4 +29,19 @@ function trp_language_content( $attr, $content = null ){
|
|
| 20 |
}
|
| 21 |
|
| 22 |
return $output;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 6 |
* Shortcode [trp_language language="en_EN"] [/trp_language]
|
| 7 |
* --------------------------------------------------------------------------- */
|
| 8 |
|
| 9 |
+
|
| 10 |
function trp_language_content( $attr, $content = null ){
|
| 11 |
+
|
| 12 |
+
global $TRP_LANGUAGE_SHORTCODE;
|
| 13 |
+
if (!isset($TRP_LANGUAGE_SHORTCODE)){
|
| 14 |
+
$TRP_LANGUAGE_SHORTCODE = array();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
$TRP_LANGUAGE_SHORTCODE[] = $content;
|
| 18 |
+
|
| 19 |
extract(shortcode_atts(array(
|
| 20 |
'language' => '',
|
| 21 |
), $attr));
|
| 29 |
}
|
| 30 |
|
| 31 |
return $output;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
add_filter('trp_exclude_words_from_automatic_translation', 'trp_add_shortcode_content_to_excluded_words_from_auto_translation');
|
| 35 |
+
|
| 36 |
+
function trp_add_shortcode_content_to_excluded_words_from_auto_translation($excluded_words){
|
| 37 |
+
|
| 38 |
+
global $TRP_LANGUAGE_SHORTCODE;
|
| 39 |
+
if (!isset($TRP_LANGUAGE_SHORTCODE)){
|
| 40 |
+
$TRP_LANGUAGE_SHORTCODE = array();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
$excluded_words = array_merge($excluded_words, $TRP_LANGUAGE_SHORTCODE);
|
| 44 |
+
|
| 45 |
+
return $excluded_words;
|
| 46 |
+
|
| 47 |
}
|
index.php
CHANGED
|
@@ -3,14 +3,14 @@
|
|
| 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.4.
|
| 7 |
Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
|
| 8 |
Author URI: https://cozmoslabs.com/
|
| 9 |
Text Domain: translatepress-multilingual
|
| 10 |
Domain Path: /languages
|
| 11 |
License: GPL2
|
| 12 |
WC requires at least: 2.5.0
|
| 13 |
-
WC tested up to: 7.1
|
| 14 |
|
| 15 |
== Copyright ==
|
| 16 |
Copyright 2017 Cozmoslabs (www.cozmoslabs.com)
|
| 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.4.3
|
| 7 |
Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
|
| 8 |
Author URI: https://cozmoslabs.com/
|
| 9 |
Text Domain: translatepress-multilingual
|
| 10 |
Domain Path: /languages
|
| 11 |
License: GPL2
|
| 12 |
WC requires at least: 2.5.0
|
| 13 |
+
WC tested up to: 7.1.1
|
| 14 |
|
| 15 |
== Copyright ==
|
| 16 |
Copyright 2017 Cozmoslabs (www.cozmoslabs.com)
|
languages/translatepress-multilingual.pot
CHANGED
|
@@ -297,11 +297,11 @@ msgstr ""
|
|
| 297 |
msgid "(last checked on %s)"
|
| 298 |
msgstr ""
|
| 299 |
|
| 300 |
-
#: includes/class-machine-translator.php:
|
| 301 |
msgid "Please enter your Google Translate key."
|
| 302 |
msgstr ""
|
| 303 |
|
| 304 |
-
#: includes/class-machine-translator.php:
|
| 305 |
msgid "Please enter your DeepL API key."
|
| 306 |
msgstr ""
|
| 307 |
|
| 297 |
msgid "(last checked on %s)"
|
| 298 |
msgstr ""
|
| 299 |
|
| 300 |
+
#: includes/class-machine-translator.php:138, includes/google-translate/class-google-translate-v2-machine-translator.php:181
|
| 301 |
msgid "Please enter your Google Translate key."
|
| 302 |
msgstr ""
|
| 303 |
|
| 304 |
+
#: includes/class-machine-translator.php:153, add-ons-pro/deepl/includes/class-deepl-machine-translator.php:286
|
| 305 |
msgid "Please enter your DeepL API key."
|
| 306 |
msgstr ""
|
| 307 |
|
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: 6.1.1
|
| 7 |
Requires PHP: 5.6.20
|
| 8 |
-
Stable tag: 2.4.
|
| 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.4.2 =
|
| 144 |
* Fixed issues with changing language on websites with persistent object caching
|
| 145 |
* Added filter on absolute home url
|
| 5 |
Requires at least: 3.1.0
|
| 6 |
Tested up to: 6.1.1
|
| 7 |
Requires PHP: 5.6.20
|
| 8 |
+
Stable tag: 2.4.3
|
| 9 |
License: GPLv2 or later
|
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 11 |
|
| 140 |
|
| 141 |
|
| 142 |
== Changelog ==
|
| 143 |
+
= 2.4.3 =
|
| 144 |
+
* Fixed cases of sprintf errors when running PHP 8+
|
| 145 |
+
* Fixed some gettext strings not selectable in Translation Editor when on secondary languages
|
| 146 |
+
* Fixed edge case not being able to save CPT when slug is translated and default language subdirectory is enabled
|
| 147 |
+
* Improved trp_language conditional shortcode by not running contents through Automatic Translation
|
| 148 |
+
|
| 149 |
= 2.4.2 =
|
| 150 |
* Fixed issues with changing language on websites with persistent object caching
|
| 151 |
* Added filter on absolute home url
|
