WPGlobus – Multilingual Everything! - Version 2.5.6

Version Description

  • (Core) Added has_translation function.
Download this release

Release Info

Developer tivnet
Plugin Icon 128x128 WPGlobus – Multilingual Everything!
Version 2.5.6
Comparing to
See all releases

Code changes from version 2.5.5 to 2.5.6

includes/class-wpglobus-core.php CHANGED
@@ -35,6 +35,7 @@ class WPGlobus_Core {
35
 
36
  /**
37
  * There are cases when numeric terms are passed here. We should not tamper with them.
 
38
  * @since 1.0.8.1 Before, was returning empty string, which was incorrect.
39
  */
40
  if ( ! is_string( $text ) ) {
@@ -63,6 +64,7 @@ class WPGlobus_Core {
63
  /**
64
  * Fix for the case
65
  * <!--:en-->ENG<!--:--><!--:ru-->RUS<!--:-->
 
66
  * @todo need careful investigation
67
  */
68
  $text = htmlspecialchars_decode( $text );
@@ -79,6 +81,7 @@ class WPGlobus_Core {
79
  /**
80
  * qTranslate compatibility
81
  * qTranslate uses these two types of delimiters
 
82
  * @example
83
  * <!--:en-->English<!--:--><!--:ru-->Russian<!--:-->
84
  * [:en]English S[:ru]Russian S
@@ -163,6 +166,7 @@ class WPGlobus_Core {
163
  if ( self::has_translations( $text ) ) {
164
  /**
165
  * Rare case of text in default language doesn't exist
 
166
  * @todo make option for return warning message or maybe another action
167
  */
168
  $text = '';
@@ -170,6 +174,7 @@ class WPGlobus_Core {
170
  } else {
171
  /**
172
  * Try the default language (recursion)
 
173
  * @qa covered by the 'one_tag' case
174
  * @see WPGlobus_QA::_test_string_parsing()
175
  */
@@ -187,8 +192,14 @@ class WPGlobus_Core {
187
  * Extract text from a string which is either:
188
  * - in the requested language (could be multiple blocks)
189
  * - or does not have the language marks
190
- * @todo May fail on large texts because regex are used.
191
  *
 
 
 
 
 
 
 
192
  * @example
193
  * Input:
194
  * '{:en}first_EN{:}{:ru}first_RU{:} blah-blah {:en}second_EN{:}{:ru}second_RU{:}'
@@ -196,12 +207,8 @@ class WPGlobus_Core {
196
  * Output:
197
  * 'first_EN blah-blah second_EN'
198
  *
199
- * @param string $text Input text.
200
- * @param string $language Language to extract. Default is the current language.
201
  *
202
- * @return string
203
- * @since 1.7.9
204
- * @since 2.2.12 Fixed regex to support line breaks in strings.
205
  */
206
  public static function extract_text( $text = '', $language = '' ) {
207
  if ( ! $text || ! is_string( $text ) ) {
@@ -240,6 +247,7 @@ class WPGlobus_Core {
240
 
241
  /**
242
  * This should detect majority of the strings with our delimiters without calling preg_match
 
243
  * @var int $pos_start
244
  */
245
  $pos_start = strpos( $string, WPGlobus::LOCALE_TAG_OPEN );
@@ -256,6 +264,79 @@ class WPGlobus_Core {
256
  return (bool) preg_match( '/(\{:|\[:|<!--:)[a-z]{2}/', $string );
257
  }
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  /**
260
  * Keeps only one language in all textual fields of the `$post` object.
261
  *
35
 
36
  /**
37
  * There are cases when numeric terms are passed here. We should not tamper with them.
38
+ *
39
  * @since 1.0.8.1 Before, was returning empty string, which was incorrect.
40
  */
41
  if ( ! is_string( $text ) ) {
64
  /**
65
  * Fix for the case
66
  * &lt;!--:en--&gt;ENG&lt;!--:--&gt;&lt;!--:ru--&gt;RUS&lt;!--:--&gt;
67
+ *
68
  * @todo need careful investigation
69
  */
70
  $text = htmlspecialchars_decode( $text );
81
  /**
82
  * qTranslate compatibility
83
  * qTranslate uses these two types of delimiters
84
+ *
85
  * @example
86
  * <!--:en-->English<!--:--><!--:ru-->Russian<!--:-->
87
  * [:en]English S[:ru]Russian S
166
  if ( self::has_translations( $text ) ) {
167
  /**
168
  * Rare case of text in default language doesn't exist
169
+ *
170
  * @todo make option for return warning message or maybe another action
171
  */
172
  $text = '';
174
  } else {
175
  /**
176
  * Try the default language (recursion)
177
+ *
178
  * @qa covered by the 'one_tag' case
179
  * @see WPGlobus_QA::_test_string_parsing()
180
  */
192
  * Extract text from a string which is either:
193
  * - in the requested language (could be multiple blocks)
194
  * - or does not have the language marks
 
195
  *
196
+ * @since 1.7.9
197
+ * @since 2.2.12 Fixed regex to support line breaks in strings.
198
+ *
199
+ * @param string $text Input text.
200
+ * @param string $language Language to extract. Default is the current language.
201
+ *
202
+ * @return string
203
  * @example
204
  * Input:
205
  * '{:en}first_EN{:}{:ru}first_RU{:} blah-blah {:en}second_EN{:}{:ru}second_RU{:}'
207
  * Output:
208
  * 'first_EN blah-blah second_EN'
209
  *
210
+ * @todo May fail on large texts because regex are used.
 
211
  *
 
 
 
212
  */
213
  public static function extract_text( $text = '', $language = '' ) {
214
  if ( ! $text || ! is_string( $text ) ) {
247
 
248
  /**
249
  * This should detect majority of the strings with our delimiters without calling preg_match
250
+ *
251
  * @var int $pos_start
252
  */
253
  $pos_start = strpos( $string, WPGlobus::LOCALE_TAG_OPEN );
264
  return (bool) preg_match( '/(\{:|\[:|<!--:)[a-z]{2}/', $string );
265
  }
266
 
267
+ /**
268
+ * True if language code is a string of two [a-z] characters.
269
+ *
270
+ * @since 2.5.6
271
+ *
272
+ * @param string $language The language code.
273
+ *
274
+ * @return bool
275
+ */
276
+ public static function is_language_code_valid( $language ) {
277
+ if (
278
+ is_string( $language )
279
+ && 2 === strlen( $language )
280
+ && ctype_lower( $language )
281
+ ) {
282
+ return true;
283
+ }
284
+
285
+ return false;
286
+ }
287
+
288
+ /**
289
+ * Check if string has language delimiters for the given language.
290
+ *
291
+ * @since 2.5.6
292
+ *
293
+ * @param string $string The string to test.
294
+ * @param string $language 2-Letter language code.
295
+ *
296
+ * @return bool
297
+ */
298
+ public static function has_translation( $string, $language = '' ) {
299
+
300
+ if ( ! is_string( $string ) || ! $string ) {
301
+ return false;
302
+ }
303
+
304
+ if ( class_exists( 'WPGlobus_Config' ) ) {
305
+ $default_language = WPGlobus::Config()->default_language;
306
+ } else {
307
+ // When in unit tests.
308
+ $default_language = 'en';
309
+ }
310
+
311
+ if ( $language ) {
312
+ if ( ! self::is_language_code_valid( $language ) ) {
313
+ return false;
314
+ }
315
+ } else {
316
+ // `$language` not passed.
317
+ $language = $default_language;
318
+ }
319
+
320
+ $language_open_tag = WPGlobus::LOCALE_TAG_OPEN . $language . WPGlobus::LOCALE_TAG_CLOSE;
321
+
322
+ /**
323
+ * This should detect majority of the strings with our delimiters without calling preg_match.
324
+ *
325
+ * @var int $pos_start
326
+ */
327
+ $pos_start = strpos( $string, $language_open_tag );
328
+ if ( false !== $pos_start ) {
329
+ // Found {:xx} where xx is the language code we were looking for.
330
+ return true;
331
+ } else {
332
+ // Try to extract the language portion.
333
+ $filtered = self::text_filter( $string, $language, WPGlobus::RETURN_EMPTY, $default_language );
334
+
335
+ // Non-empty `filtered` is OK.
336
+ return (bool) $filtered;
337
+ }
338
+ }
339
+
340
  /**
341
  * Keeps only one language in all textual fields of the `$post` object.
342
  *
languages/wpglobus.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2020 WPGlobus 2.5.5
2
- # This file is distributed under the same license as the WPGlobus 2.5.5 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WPGlobus 2.5.5\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
1
+ # Copyright (C) 2020 WPGlobus 2.5.6
2
+ # This file is distributed under the same license as the WPGlobus 2.5.6 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WPGlobus 2.5.6\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
readme.txt CHANGED
@@ -217,6 +217,10 @@ WPGlobus Version 2 supports WordPress 5.x, with Gutenberg.
217
 
218
  == Changelog ==
219
 
 
 
 
 
220
  = 2.5.5 =
221
 
222
  * (Builders/Elementor) Added support for the Elementor Kit loading CSS.
217
 
218
  == Changelog ==
219
 
220
+ = 2.5.6 =
221
+
222
+ * (Core) Added `has_translation` function.
223
+
224
  = 2.5.5 =
225
 
226
  * (Builders/Elementor) Added support for the Elementor Kit loading CSS.
wpglobus.php CHANGED
@@ -15,7 +15,7 @@
15
  * Description: A WordPress Globalization / Multilingual Plugin. Posts, pages, menus, widgets and even custom fields - in multiple languages!
16
  * Text Domain: wpglobus
17
  * Domain Path: /languages/
18
- * Version: 2.5.5
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
@@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) {
42
  exit;
43
  }
44
 
45
- define( 'WPGLOBUS_VERSION', '2.5.5' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
  define( 'WPGLOBUS_AJAX', 'wpglobus-ajax' );
48
 
15
  * Description: A WordPress Globalization / Multilingual Plugin. Posts, pages, menus, widgets and even custom fields - in multiple languages!
16
  * Text Domain: wpglobus
17
  * Domain Path: /languages/
18
+ * Version: 2.5.6
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
42
  exit;
43
  }
44
 
45
+ define( 'WPGLOBUS_VERSION', '2.5.6' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
  define( 'WPGLOBUS_AJAX', 'wpglobus-ajax' );
48