Lingotek Translation - Version 1.5.1

Version Description

(2021-08-19) = - Compatibility issues with PolyLang 3.1 - Add check for the Document Status - PHP Notice when actions don't include locale

Download this release

Release Info

Developer sowmiya2021
Plugin Icon 128x128 Lingotek Translation
Version 1.5.1
Comparing to
See all releases

Code changes from version 1.5.0 to 1.5.1

admin/filters-post.php CHANGED
@@ -167,7 +167,7 @@ class Lingotek_Filters_Post extends PLL_CRUD_Posts {
167
  }
168
  // Ensures languages are updated, even when no other element on the page has been changed.
169
  if ( isset( $_POST['post_tr_lang'] ) ) {
170
- PLL()->model->post->save_translations( $post_id, sanitize_text_field( wp_unslash( $_POST['post_tr_lang'] ) ) );
171
  }
172
  }
173
 
167
  }
168
  // Ensures languages are updated, even when no other element on the page has been changed.
169
  if ( isset( $_POST['post_tr_lang'] ) ) {
170
+ PLL()->model->post->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) );
171
  }
172
  }
173
 
admin/post-actions.php CHANGED
@@ -157,8 +157,9 @@ class Lingotek_Post_Actions extends Lingotek_Actions {
157
  $redirect = admin_url( "edit.php?post_type=$typenow" );
158
  }
159
 
160
- list($action, $locale) = explode( ':', $action, 2 );
161
-
 
162
  switch ( $action ) {
163
  case 'bulk-lingotek-upload':
164
  $type = empty( $typenow ) ? 'media' : 'post';
157
  $redirect = admin_url( "edit.php?post_type=$typenow" );
158
  }
159
 
160
+ if ( false !== strpos( $action, ':' ) ) {
161
+ list( $action, $locale ) = explode( ':', $action, 2 );
162
+ }
163
  switch ( $action ) {
164
  case 'bulk-lingotek-upload':
165
  $type = empty( $typenow ) ? 'media' : 'post';
here ADDED
File without changes
include/api.php CHANGED
@@ -446,7 +446,13 @@ class Lingotek_API extends Lingotek_HTTP {
446
  $response = $this->get( $this->api_url . '/document/' . $doc_id . '/status' );
447
 
448
  if ( ! is_wp_error( $response ) && 200 == wp_remote_retrieve_response_code( $response ) ) {
449
- $imported = true;
 
 
 
 
 
 
450
  }
451
 
452
  $this->log_error_on_response_failure( $response, 'GetDocumentStatus: Error occured', array( 'document_id' => $doc_id ) );
446
  $response = $this->get( $this->api_url . '/document/' . $doc_id . '/status' );
447
 
448
  if ( ! is_wp_error( $response ) && 200 == wp_remote_retrieve_response_code( $response ) ) {
449
+ $body = json_decode( wp_remote_retrieve_body( $response ) );
450
+ // Cancelled docs return with a 200 status code,
451
+ $imported = 'cancelled' !== strtolower( $body->properties->status ) ? 'current' : 'cancelled';
452
+ } elseif ( 410 == wp_remote_retrieve_response_code( $response ) ) {
453
+ $imported = 'archived';
454
+ } elseif ( 404 == wp_remote_retrieve_response_code( $response ) ) {
455
+ $imported = 'deleted';
456
  }
457
 
458
  $this->log_error_on_response_failure( $response, 'GetDocumentStatus: Error occured', array( 'document_id' => $doc_id ) );
include/dashboard.php CHANGED
@@ -29,7 +29,7 @@ class Lingotek_Dashboard {
29
 
30
  switch ( $request_method ) {
31
  case 'POST':
32
- if ( isset( $_REQUEST['code'], $_REQUEST['native'], $_REQUEST['direction'] ) ) {
33
  $name = $_REQUEST['native'];
34
  // 3rd parameter of strstr needs PHP 5.3.
35
  $slug = substr( $_REQUEST['code'], 0, strpos( $_REQUEST['code'], '_' ) );
@@ -72,7 +72,7 @@ class Lingotek_Dashboard {
72
  $response = array(
73
  'request' => 'POST: add target language to CMS and and Lingotek Project Language',
74
  'success' => false,
75
- 'message' => __( "Missing locale, direction, or name. Locale: $code, Name: $native, Direction: $direction", 'lingotek-translation' ),
76
  );
77
 
78
  status_header( 400 );
29
 
30
  switch ( $request_method ) {
31
  case 'POST':
32
+ if ( isset( $_REQUEST['code'], $_REQUEST['native'], $_REQUEST['direction'] ) && in_array( str_replace( '_', '-', $_REQUEST['code'] ), Lingotek::$lingotek_locales) ) {
33
  $name = $_REQUEST['native'];
34
  // 3rd parameter of strstr needs PHP 5.3.
35
  $slug = substr( $_REQUEST['code'], 0, strpos( $_REQUEST['code'], '_' ) );
72
  $response = array(
73
  'request' => 'POST: add target language to CMS and and Lingotek Project Language',
74
  'success' => false,
75
+ 'message' => __( "Missing or unsupported locale, direction, or name. Locale: $code, Name: $native, Direction: $direction", 'lingotek-translation' ),
76
  );
77
 
78
  status_header( 400 );
include/group.php CHANGED
@@ -221,9 +221,9 @@ abstract class Lingotek_Group {
221
  */
222
  public function source_status() {
223
  $client = new Lingotek_API();
224
-
225
- if ( 'importing' == $this->status && $client->get_document_status( $this->document_id ) ) {
226
- $this->status = 'current';
227
  $this->save();
228
  }
229
  }
@@ -344,43 +344,48 @@ abstract class Lingotek_Group {
344
  }
345
 
346
  public function translation_status_hard_refresh() {
347
- $client = new Lingotek_API();
348
- // Keys are Lingotek locales.
349
- $translations = $client->get_translations_status( $this->document_id, $this->source );
350
- $lingotek_locale_to_pll_locale = array();
351
- foreach ( PLL()->model->get_languages_list() as $pll_language ) {
352
- $lingotek_locale_to_pll_locale[ $pll_language->lingotek_locale ] = $pll_language->locale;
353
- }
354
- foreach ( $translations as $lingotek_locale => $locale_status ) {
355
- if ( ! isset( $lingotek_locale_to_pll_locale[ $lingotek_locale ] ) ) {
356
- continue;
 
357
  }
358
- $wp_locale = $lingotek_locale_to_pll_locale[ $lingotek_locale ];
 
 
 
 
359
 
360
- if ( $locale_status['percent_complete'] < 100 && $this->translations[ $wp_locale ] !== 'interim' ) {
361
- if ( strtolower( $locale_status['progress'] ) === 'in_progress' ) {
 
 
 
 
 
 
 
362
  $this->translations[ $wp_locale ] = 'ready';
363
- } else {
364
- $this->translations[ $wp_locale ] = 'pending';
365
  }
366
- } elseif ( $this->translations[ $wp_locale ] === 'interim' && $locale_status['percent_complete'] === 100 ) {
367
- $this->translations[ $wp_locale ] = 'ready';
368
- } elseif ( ( ! isset( $this->translations[ $wp_locale ] ) ) || ( $this->translations[ $wp_locale ] !== 'current' ) && $this->translations[ $wp_locale ] !== 'interim' ) {
369
- $this->translations[ $wp_locale ] = 'ready';
370
  }
371
- }
372
- // If there were any cancelled or deleted targets that we didn't update properly,
373
- // we didn't get anything, but locally they would keep that status, let's update those here.
374
- $pll_locale_to_lingotek_locale = array_flip( $lingotek_locale_to_pll_locale );
375
- foreach ( $this->translations as $target_locale => $target_status ) {
376
- if ( ! isset( $translations[ $pll_locale_to_lingotek_locale[ $target_locale ] ] ) ) {
377
- if ( ! in_array( $this->translations[ $target_locale ], array( 'deleted', 'cancelled' ) ) ) {
378
- // Mark is a deleted.
379
- $this->translations[ $target_locale ] = 'deleted';
380
  }
381
  }
382
- }
383
-
384
  $this->save();
385
  }
386
 
221
  */
222
  public function source_status() {
223
  $client = new Lingotek_API();
224
+ $status = $client->get_document_status( $this->document_id );
225
+ if ( $status ) {
226
+ $this->status = $status;
227
  $this->save();
228
  }
229
  }
344
  }
345
 
346
  public function translation_status_hard_refresh() {
347
+ $client = new Lingotek_API();
348
+ $source_status = $client->get_document_status( $this->document_id );
349
+ if ( 'current' !== $source_status ) {
350
+ $locales = array_keys( $this->translations );
351
+ $this->translations = array_fill_keys( $locales, $source_status );
352
+ } else {
353
+ // Keys are Lingotek locales.
354
+ $translations = $client->get_translations_status( $this->document_id, $this->source );
355
+ $lingotek_locale_to_pll_locale = array();
356
+ foreach ( PLL()->model->get_languages_list() as $pll_language ) {
357
+ $lingotek_locale_to_pll_locale[ $pll_language->lingotek_locale ] = $pll_language->locale;
358
  }
359
+ foreach ( $translations as $lingotek_locale => $locale_status ) {
360
+ if ( ! isset( $lingotek_locale_to_pll_locale[ $lingotek_locale ] ) ) {
361
+ continue;
362
+ }
363
+ $wp_locale = $lingotek_locale_to_pll_locale[ $lingotek_locale ];
364
 
365
+ if ( $locale_status['percent_complete'] < 100 && $this->translations[ $wp_locale ] !== 'interim' ) {
366
+ if ( strtolower( $locale_status['progress'] ) === 'in_progress' ) {
367
+ $this->translations[ $wp_locale ] = 'ready';
368
+ } else {
369
+ $this->translations[ $wp_locale ] = 'pending';
370
+ }
371
+ } elseif ( $this->translations[ $wp_locale ] === 'interim' && $locale_status['percent_complete'] === 100 ) {
372
+ $this->translations[ $wp_locale ] = 'ready';
373
+ } elseif ( ( ! isset( $this->translations[ $wp_locale ] ) ) || ( $this->translations[ $wp_locale ] !== 'current' ) && $this->translations[ $wp_locale ] !== 'interim' ) {
374
  $this->translations[ $wp_locale ] = 'ready';
 
 
375
  }
 
 
 
 
376
  }
377
+ // If there were any cancelled or deleted targets that we didn't update properly,
378
+ // we didn't get anything, but locally they would keep that status, let's update those here.
379
+ $pll_locale_to_lingotek_locale = array_flip( $lingotek_locale_to_pll_locale );
380
+ foreach ( $this->translations as $target_locale => $target_status ) {
381
+ if ( ! isset( $translations[ $pll_locale_to_lingotek_locale[ $target_locale ] ] ) ) {
382
+ if ( ! in_array( $this->translations[ $target_locale ], array( 'deleted', 'cancelled' ) ) ) {
383
+ // Mark is a deleted.
384
+ $this->translations[ $target_locale ] = 'deleted';
385
+ }
386
  }
387
  }
388
+ }//end if
 
389
  $this->save();
390
  }
391
 
include/model.php CHANGED
@@ -404,7 +404,8 @@ class Lingotek_Model {
404
  $new_hash = md5( $content );
405
  if ( ! empty( $hash_term ) ) {
406
  // If the document hasn't changed and it exists in TMS, don't upload
407
- if ( $hash_term->description == $new_hash && $client->get_document_status( $document_id ) ) {
 
408
  return;
409
  }
410
  }
404
  $new_hash = md5( $content );
405
  if ( ! empty( $hash_term ) ) {
406
  // If the document hasn't changed and it exists in TMS, don't upload
407
+ $status = $client->get_document_status( $document_id );
408
+ if ( $hash_term->description === $new_hash && 'current' === $status ) {
409
  return;
410
  }
411
  }
lingotek.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
- Version: 1.5.0
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
@@ -19,7 +19,7 @@ if ( ! function_exists( 'add_action' ) ) {
19
  }
20
 
21
  // Plugin version (should match above meta).
22
- define( 'LINGOTEK_VERSION', '1.5.0' );
23
  define( 'LINGOTEK_MIN_PLL_VERSION', '1.8' );
24
  // Plugin name as known by WordPress.
25
  define( 'LINGOTEK_BASENAME', plugin_basename( __FILE__ ) );
2
  /**
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
+ Version: 1.5.1
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
19
  }
20
 
21
  // Plugin version (should match above meta).
22
+ define( 'LINGOTEK_VERSION', '1.5.1' );
23
  define( 'LINGOTEK_MIN_PLL_VERSION', '1.8' );
24
  // Plugin name as known by WordPress.
25
  define( 'LINGOTEK_BASENAME', plugin_basename( __FILE__ ) );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://lingotek.com/
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
  Tested up to: 5.8
7
- Stable tag: 1.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -122,6 +122,11 @@ For more, visit the [Lingotek documentation site](https://lingotek.atlassian.net
122
  5. The Lingotek Translation plugin provides the ability to Copy, Translate, and Ignore each specific custom field. Our plugin supports Wordpress custom fields and advanced custom fields.
123
 
124
  == Changelog ==
 
 
 
 
 
125
  = 1.5.0 (2021-08-05) =
126
  * New UI
127
  - The source and translation icons have been replaced with chips. This makes it easier to view which stage the translations are in.
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
  Tested up to: 5.8
7
+ Stable tag: 1.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
122
  5. The Lingotek Translation plugin provides the ability to Copy, Translate, and Ignore each specific custom field. Our plugin supports Wordpress custom fields and advanced custom fields.
123
 
124
  == Changelog ==
125
+ = 1.5.1 (2021-08-19) =
126
+ - Compatibility issues with PolyLang 3.1
127
+ - Add check for the Document Status
128
+ - PHP Notice when actions don't include locale
129
+
130
  = 1.5.0 (2021-08-05) =
131
  * New UI
132
  - The source and translation icons have been replaced with chips. This makes it easier to view which stage the translations are in.