Lingotek Translation - Version 1.1.2

Version Description

(2015-09-18) =

  • Fix for copy feature
  • Fix for content status displays
  • Other minor fixes
Download this release

Release Info

Developer erichie
Plugin Icon 128x128 Lingotek Translation
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

admin/actions.php CHANGED
@@ -95,10 +95,11 @@ abstract class Lingotek_Actions {
95
  'icon' => 'edit'
96
  ),
97
 
98
- 'error' => array(
99
- 'title' => __('There was an error contacting Lingotek', 'wp-lingotek'),
100
- 'icon' => 'warning'
101
- ),
 
102
  );
103
 
104
  $this->type = $type;
@@ -186,18 +187,19 @@ abstract class Lingotek_Actions {
186
  self::$icons[$name]['icon'], self::$icons[$name]['title'], esc_url($link), $additional);
187
  }
188
 
189
- /*
190
- * outputs an API error icon
191
- *
192
- * @since 0.2
193
- *
194
- * @param string $name
195
- * @param string $additional parameters to add (js, target)
196
- */
197
- public static function display_error_icon($name, $api_error, $additional = '') {
198
- return sprintf('<span class="lingotek-error dashicons dashicons-%s" title="%s"></span>',
199
- self::$icons[$name]['icon'], self::$icons[$name]['title'] . "\n" . $api_error, $additional);
200
- }
 
201
 
202
  /*
203
  * outputs an upload icon
@@ -485,7 +487,7 @@ abstract class Lingotek_Actions {
485
  public function ajax_delete() {
486
  check_ajax_referer('lingotek_progress', '_lingotek_nonce');
487
  if ($document = $this->lgtm->get_group($this->type, $_POST['id'])) {
488
- $document->disassociate();
489
  }
490
  die();
491
  }
95
  'icon' => 'edit'
96
  ),
97
 
98
+ // Removed error reporting for release 1.1.2
99
+ // 'error' => array(
100
+ // 'title' => __('There was an error contacting Lingotek', 'wp-lingotek'),
101
+ // 'icon' => 'warning'
102
+ // ),
103
  );
104
 
105
  $this->type = $type;
187
  self::$icons[$name]['icon'], self::$icons[$name]['title'], esc_url($link), $additional);
188
  }
189
 
190
+ // Removed error reporting for release 1.1.2
191
+ // /*
192
+ // * outputs an API error icon
193
+ // *
194
+ // * @since 0.2
195
+ // *
196
+ // * @param string $name
197
+ // * @param string $additional parameters to add (js, target)
198
+ // */
199
+ // public static function display_error_icon($name, $api_error, $additional = '') {
200
+ // return sprintf('<span class="lingotek-error dashicons dashicons-%s" title="%s"></span>',
201
+ // self::$icons[$name]['icon'], self::$icons[$name]['title'] . "\n" . $api_error, $additional);
202
+ // }
203
 
204
  /*
205
  * outputs an upload icon
487
  public function ajax_delete() {
488
  check_ajax_referer('lingotek_progress', '_lingotek_nonce');
489
  if ($document = $this->lgtm->get_group($this->type, $_POST['id'])) {
490
+ $document->disassociate();
491
  }
492
  die();
493
  }
admin/admin.php CHANGED
@@ -95,11 +95,12 @@ class Lingotek_Admin {
95
  foreach ($languages as $language) {
96
  foreach ($content_metadata as $group => $status) {
97
  $language_obj = $pllm->get_language($source_language);
 
98
  $profile = Lingotek_Model::get_profile($taxonomy, $language_obj, $group);
99
  if ($profile['profile'] != 'disabled' && $status['source'] != false) {
100
  if (!isset($status[$language])) {
101
  $content_metadata[$group][$language]['status'] = "none";
102
- if ($document->is_disabled_target($pllm->get_language($source_language), $pllm->get_language($language))) {
103
  $content_metadata[$group][$language]['status'] = 'disabled';
104
  }
105
  }
95
  foreach ($languages as $language) {
96
  foreach ($content_metadata as $group => $status) {
97
  $language_obj = $pllm->get_language($source_language);
98
+ $target_lang_obj = $pllm->get_language($language);
99
  $profile = Lingotek_Model::get_profile($taxonomy, $language_obj, $group);
100
  if ($profile['profile'] != 'disabled' && $status['source'] != false) {
101
  if (!isset($status[$language])) {
102
  $content_metadata[$group][$language]['status'] = "none";
103
+ if ($document->is_disabled_target($pllm->get_language($source_language), $pllm->get_language($language)) || (isset($document->desc_array[$target_lang_obj->slug]) && !isset($document->source))) {
104
  $content_metadata[$group][$language]['status'] = 'disabled';
105
  }
106
  }
admin/filters-columns.php CHANGED
@@ -95,11 +95,18 @@ class Lingotek_Filters_Columns extends PLL_Admin_Filters_Columns {
95
  call_user_func(array($this->model, 'get_' . $type), $object_id, $language);
96
 
97
  $document = $this->lgtm->get_group($type, $object_id);
 
 
 
 
 
 
98
 
99
  // FIXME not very clean
100
  $actions = 'post' == $type ? $GLOBALS['wp_lingotek']->post_actions : $GLOBALS['wp_lingotek']->term_actions;
101
 
102
  $profile = Lingotek_Model::get_profile($this->content_type, $language, $object_id);
 
103
  $disabled = 'disabled' == $profile['profile'];
104
 
105
  // post ready for upload
@@ -111,7 +118,7 @@ class Lingotek_Filters_Columns extends PLL_Admin_Filters_Columns {
111
  }
112
 
113
  // translation disabled
114
- elseif (isset($document->source) && $document->is_disabled_target($lang, $language) && !isset($document->translations[$language->locale])) {
115
  return 'post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id);
116
  }
117
 
@@ -164,27 +171,29 @@ class Lingotek_Filters_Columns extends PLL_Admin_Filters_Columns {
164
  */
165
  public function post_column($column, $post_id) {
166
  $this->content_type = get_post_type($post_id);
167
-
168
  echo $this->_column('post', $column, $post_id);
169
 
 
170
  // checking for api errors
171
- $column_language_only = substr($column, 0, 11);
172
- $group = $this->lgtm->get_group('post', $post_id);
173
-
174
- if ($group) {
175
- $source = $group->desc_array['lingotek']['source'];
176
- // remove the remnants of previous API errors if there aren't any current errors
177
- if (isset($group->desc_array['lingotek']['api_errors'])) {
178
- $api_errors = $group->desc_array['lingotek']['api_errors'];
179
- if (empty($api_errors)) {
180
- unset($group->desc_array['lingotek']['api_errors']);
181
- }
182
- }
183
- if ($column_language_only == $this->get_first_language_column() && $post_id === $source && isset($group->desc_array['lingotek']['api_errors'])) {
184
- $error = $this->retrieve_api_error($group);
185
- echo Lingotek_Actions::display_error_icon('error', $error);
186
- }
187
- }
 
188
  }
189
 
190
  /*
@@ -207,53 +216,53 @@ class Lingotek_Filters_Columns extends PLL_Admin_Filters_Columns {
207
  }
208
  }
209
 
 
 
 
 
 
 
 
 
 
 
210
 
211
- /*
212
- * collects and returns all API errors in the group object
213
- *
214
- * @since 1.1
215
- *
216
- * @param string $group
217
- */
218
- protected function retrieve_api_error($group) {
219
- $api_error = "\n";
220
-
221
- if (isset($group->desc_array['lingotek']['api_errors']['source_status'])){
222
- $source_status = $group->desc_array['lingotek']['api_errors']['source_status'];
223
- $api_error = $api_error . $source_status . "\n";
224
- }
225
- if (isset($group->desc_array['lingotek']['api_errors']['translations_status'])){
226
- $translations_status = $group->desc_array['lingotek']['api_errors']['translations_status'];
227
- $api_error = $api_error . $translations_status . "\n";
228
- }
229
- if (isset($group->desc_array['lingotek']['api_errors']['request_translation'])){
230
- $request_translation = $group->desc_array['lingotek']['api_errors']['request_translation'];
231
- $api_error = $api_error . $request_translation . "\n";
232
- }
233
- if (isset($group->desc_array['lingotek']['api_errors']['_request_translations'])) {
234
- $request_translations = $group->desc_array['lingotek']['api_errors']['_request_translations'];
235
- foreach ($request_translations as $lang => $error) {
236
- $api_error = $api_error . $error . "\n";
237
- }
238
- }
239
- if (isset($group->desc_array['lingotek']['api_errors']['create_translation'])) {
240
- $create_translation = $group->desc_array['lingotek']['api_errors']['create_translation'];
241
- foreach ($create_translation as $locale => $error) {
242
- $api_error = $api_error . $error . "\n";
243
- }
244
- }
245
- if (isset($group->desc_array['lingotek']['api_errors']['disassociate'])) {
246
- $disassociate = $group->desc_array['lingotek']['api_errors']['disassociate'];
247
- $api_error = $api_error . $disassociate . "\n";
248
- }
249
- if (isset($group->desc_array['lingotek']['api_errors']['patch'])) {
250
- $patch = $group->desc_array['lingotek']['api_errors']['patch'];
251
- $api_error = $api_error . $patch . "\n";
252
- }
253
- if (isset($group->desc_array['lingotek']['api_errors']['upload'])) {
254
- $upload = $group->desc_array['lingotek']['api_errors']['upload'];
255
- $api_error = $api_error . $upload . "\n";
256
- }
257
- return $api_error;
258
- }
259
  }
95
  call_user_func(array($this->model, 'get_' . $type), $object_id, $language);
96
 
97
  $document = $this->lgtm->get_group($type, $object_id);
98
+ if (isset($document->source)) {
99
+ $source_language = $type == 'post' ? $this->model->get_post_language($document->source) : $this->model->get_term_language($document->source);
100
+ }
101
+ else {
102
+ $source_language = $lang;
103
+ }
104
 
105
  // FIXME not very clean
106
  $actions = 'post' == $type ? $GLOBALS['wp_lingotek']->post_actions : $GLOBALS['wp_lingotek']->term_actions;
107
 
108
  $profile = Lingotek_Model::get_profile($this->content_type, $language, $object_id);
109
+ $source_profile = Lingotek_Model::get_profile($this->content_type, $lang, $id);
110
  $disabled = 'disabled' == $profile['profile'];
111
 
112
  // post ready for upload
118
  }
119
 
120
  // translation disabled
121
+ elseif (isset($document->source) && $document->is_disabled_target($source_language, $language) && !isset($document->translations[$language->locale])) {
122
  return 'post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id);
123
  }
124
 
171
  */
172
  public function post_column($column, $post_id) {
173
  $this->content_type = get_post_type($post_id);
174
+
175
  echo $this->_column('post', $column, $post_id);
176
 
177
+ // Removed error reporting for release 1.1.2
178
  // checking for api errors
179
+ // $column_language_only = substr($column, 0, 11);
180
+ // $group = $this->lgtm->get_group('post', $post_id);
181
+
182
+ // if ($group) {
183
+ // $source = $group->desc_array['lingotek']['source'];
184
+ // // remove the remnants of previous API errors if there aren't any current errors
185
+ // if (isset($group->desc_array['lingotek']['api_errors'])) {
186
+ // $api_errors = $group->desc_array['lingotek']['api_errors'];
187
+ // if (empty($api_errors)) {
188
+ // unset($group->desc_array['lingotek']['api_errors']);
189
+ // $group->save();
190
+ // }
191
+ // }
192
+ // if ($column_language_only == $this->get_first_language_column() && $post_id === $source && isset($group->desc_array['lingotek']['api_errors'])) {
193
+ // $error = $this->retrieve_api_error($group);
194
+ // echo Lingotek_Actions::display_error_icon('error', $error);
195
+ // }
196
+ // }
197
  }
198
 
199
  /*
216
  }
217
  }
218
 
219
+ // Removed error reporting for release 1.1.2
220
+ // /*
221
+ // * collects and returns all API errors in the group object
222
+ // *
223
+ // * @since 1.1
224
+ // *
225
+ // * @param string $group
226
+ // */
227
+ // protected function retrieve_api_error($group) {
228
+ // $api_error = "\n";
229
 
230
+ // if (isset($group->desc_array['lingotek']['api_errors']['source_status'])){
231
+ // $source_status = $group->desc_array['lingotek']['api_errors']['source_status'];
232
+ // $api_error = $api_error . $source_status . "\n";
233
+ // }
234
+ // if (isset($group->desc_array['lingotek']['api_errors']['translations_status'])){
235
+ // $translations_status = $group->desc_array['lingotek']['api_errors']['translations_status'];
236
+ // $api_error = $api_error . $translations_status . "\n";
237
+ // }
238
+ // if (isset($group->desc_array['lingotek']['api_errors']['request_translation'])){
239
+ // $request_translation = $group->desc_array['lingotek']['api_errors']['request_translation'];
240
+ // $api_error = $api_error . $request_translation . "\n";
241
+ // }
242
+ // if (isset($group->desc_array['lingotek']['api_errors']['_request_translations'])) {
243
+ // $request_translations = $group->desc_array['lingotek']['api_errors']['_request_translations'];
244
+ // foreach ($request_translations as $lang => $error) {
245
+ // $api_error = $api_error . $error . "\n";
246
+ // }
247
+ // }
248
+ // if (isset($group->desc_array['lingotek']['api_errors']['create_translation'])) {
249
+ // $create_translation = $group->desc_array['lingotek']['api_errors']['create_translation'];
250
+ // foreach ($create_translation as $locale => $error) {
251
+ // $api_error = $api_error . $error . "\n";
252
+ // }
253
+ // }
254
+ // if (isset($group->desc_array['lingotek']['api_errors']['disassociate'])) {
255
+ // $disassociate = $group->desc_array['lingotek']['api_errors']['disassociate'];
256
+ // $api_error = $api_error . $disassociate . "\n";
257
+ // }
258
+ // if (isset($group->desc_array['lingotek']['api_errors']['patch'])) {
259
+ // $patch = $group->desc_array['lingotek']['api_errors']['patch'];
260
+ // $api_error = $api_error . $patch . "\n";
261
+ // }
262
+ // if (isset($group->desc_array['lingotek']['api_errors']['upload'])) {
263
+ // $upload = $group->desc_array['lingotek']['api_errors']['upload'];
264
+ // $api_error = $api_error . $upload . "\n";
265
+ // }
266
+ // return $api_error;
267
+ // }
 
 
 
 
 
 
 
 
 
 
268
  }
css/admin.css CHANGED
@@ -87,7 +87,7 @@ a.dashicons {
87
  }
88
 
89
  .lingotek-error {
90
- color: #FF0000;
91
  }
92
 
93
  /* utilities */
87
  }
88
 
89
  .lingotek-error {
90
+ color: #999999;
91
  }
92
 
93
  /* utilities */
include/api.php CHANGED
@@ -187,11 +187,12 @@ class Lingotek_API extends Lingotek_HTTP {
187
  $translations[$e->properties->locale_code] = $e->properties->percent_complete;
188
  }
189
  }
190
- else {
191
- if (wp_remote_retrieve_response_code($response) != 404) {
192
- return false;
193
- }
194
- }
 
195
 
196
  return empty($translations) ? array() : $translations;
197
  }
187
  $translations[$e->properties->locale_code] = $e->properties->percent_complete;
188
  }
189
  }
190
+ // Removed error reporting for release 1.1.2
191
+ // else {
192
+ // if (empty(wp_remote_retrieve_response_code($response))) {
193
+ // return false;
194
+ // }
195
+ // }
196
 
197
  return empty($translations) ? array() : $translations;
198
  }
include/group-post.php CHANGED
@@ -55,8 +55,8 @@ class Lingotek_Group_Post extends Lingotek_Group {
55
  'post_excerpt' => __('Excerpt', 'wp-lingotek')
56
  );
57
 
58
- // if the user hasn't visited the custom fields tab, and hasn't saved actions for custom
59
- // fields, and uploaded a post, check the wpml file for settings
60
  if ($post_ID) {
61
  self::get_updated_meta_values($post_ID);
62
  }
@@ -107,7 +107,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
107
  */
108
  static public function get_custom_fields_from_wp_postmeta($post_ID = NULL) {
109
  $custom_fields = get_option('lingotek_custom_fields', array());
110
- $meta_black_list = array('_encloseme', '_edit_last', '_edit_lock', '_wp_trash_meta_status', '_wp_trash_meta_time');
111
  $arr = array();
112
  $keys = array();
113
 
@@ -153,7 +153,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
153
  }
154
 
155
  /*
156
- * updates meta (custom) fields values in the lingotek_custom_fields option
157
  *
158
  * @since 0.2
159
  *
@@ -197,7 +197,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
197
  }
198
 
199
  /*
200
- * returns cached meta (custom) fields values in the lingotek_custom_fields option
201
  *
202
  * @since 0.2
203
  *
@@ -254,7 +254,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
254
  $arr['post'][$key] = $post->$key;
255
  }
256
  }
257
-
258
  return json_encode($arr);
259
  }
260
 
@@ -293,15 +293,18 @@ class Lingotek_Group_Post extends Lingotek_Group {
293
  $client = new Lingotek_API();
294
 
295
  if (false === ($translation = $client->get_translation($this->document_id, $locale))) {
296
- // Error reporting here causes problems. FIXME
297
  // $this->desc_array['lingotek']['api_errors']['create_translation'][$locale] = __('Error downloading ', 'wp-lingotek') . $locale . __(' translation for post ', 'wp-lingotek') . $this->source;
298
  // $this->save();
299
  return;
300
  }
301
- // else {
302
- // unset($this->desc_array['lingotek']['api_errors']['create_translation'][$locale]);
303
- // $this->save();
304
- // }
 
 
 
305
 
306
  self::$creating_translation = true;
307
  $prefs = Lingotek_Model::get_prefs(); // need an array by default
55
  'post_excerpt' => __('Excerpt', 'wp-lingotek')
56
  );
57
 
58
+ // if the user hasn't visited the custom fields tab, and hasn't saved actions for custom
59
+ // fields, and uploaded a post, check the wpml file for settings
60
  if ($post_ID) {
61
  self::get_updated_meta_values($post_ID);
62
  }
107
  */
108
  static public function get_custom_fields_from_wp_postmeta($post_ID = NULL) {
109
  $custom_fields = get_option('lingotek_custom_fields', array());
110
+ $meta_black_list = array('_encloseme', '_edit_last', '_edit_lock', '_wp_trash_meta_status', '_wp_trash_meta_time');
111
  $arr = array();
112
  $keys = array();
113
 
153
  }
154
 
155
  /*
156
+ * updates meta (custom) fields values in the lingotek_custom_fields option
157
  *
158
  * @since 0.2
159
  *
197
  }
198
 
199
  /*
200
+ * returns cached meta (custom) fields values in the lingotek_custom_fields option
201
  *
202
  * @since 0.2
203
  *
254
  $arr['post'][$key] = $post->$key;
255
  }
256
  }
257
+
258
  return json_encode($arr);
259
  }
260
 
293
  $client = new Lingotek_API();
294
 
295
  if (false === ($translation = $client->get_translation($this->document_id, $locale))) {
296
+ // Error reporting removed for release 1.1.2
297
  // $this->desc_array['lingotek']['api_errors']['create_translation'][$locale] = __('Error downloading ', 'wp-lingotek') . $locale . __(' translation for post ', 'wp-lingotek') . $this->source;
298
  // $this->save();
299
  return;
300
  }
301
+ //else {
302
+ // unset($this->desc_array['lingotek']['api_errors']['create_translation'][$locale]);
303
+ // if (empty($this->desc_array['lingotek']['api_errors']['create_translation'])) {
304
+ // unset($this->desc_array['lingotek']['api_errors']['create_translation']);
305
+ // }
306
+ // $this->save();
307
+ //}
308
 
309
  self::$creating_translation = true;
310
  $prefs = Lingotek_Model::get_prefs(); // need an array by default
include/group.php CHANGED
@@ -139,12 +139,13 @@ abstract class Lingotek_Group {
139
  if ($res) {
140
  $this->status = 'importing';
141
  $this->translations = array_fill_keys(array_keys($this->translations), 'pending');
142
- unset($this->desc_array['lingotek']['api_errors']['patch']);
143
- $this->save();
144
- }
145
- else {
146
- $this->desc_array['lingotek']['api_errors']['patch'] = __('Error uploading updated post ', 'wp-lingotek') . $this->source;
147
- $this->save();
 
148
  }
149
  }
150
 
@@ -156,18 +157,25 @@ abstract class Lingotek_Group {
156
  public function source_status() {
157
  $client = new Lingotek_API();
158
 
159
- if ($client->document_exists($this->document_id)) {
160
- unset($this->desc_array['lingotek']['api_errors']['source_status']);
161
- if ('importing' == $this->status) {
162
- $this->status = 'current';
163
- }
164
- }
165
- // note api errors
166
- else {
167
- $this->desc_array['lingotek']['api_errors']['source_status'] = __('Error updating translation status of post ', 'wp-lingotek') . $this->source;
168
  }
169
 
170
- $this->save();
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  }
172
 
173
  /*
@@ -194,15 +202,20 @@ abstract class Lingotek_Group {
194
  $args = $workflow ? array('workflow_id' => $workflow) : array();
195
 
196
  if (!$this->is_disabled_target($language) && empty($this->translations[$language->locale])) {
197
- if ($client->request_translation($this->document_id, $language->locale, $args)) {
198
- $this->status = 'current';
199
- $this->translations[$language->locale] = 'pending';
200
- unset($this->desc_array['lingotek']['api_errors']['request_translation']);
201
- }
202
- else {
203
- $this->desc_array['lingotek']['api_errors']['request_translation'] = __('Error requesting translations for post ', 'wp-lingotek') . $this->source;
204
- }
205
-
 
 
 
 
 
206
  $this->save();
207
  }
208
  }
@@ -221,14 +234,24 @@ abstract class Lingotek_Group {
221
  if ($source_language->slug != $lang->slug && !$this->is_disabled_target($source_language, $lang) && empty($this->translations[$lang->locale])) {
222
  $workflow = Lingotek_Model::get_profile_option('workflow_id', $this->type, $source_language, $lang, $this->source);
223
  $args = $workflow ? array('workflow_id' => $workflow) : array();
224
- if ($client->request_translation($this->document_id, $lang->lingotek_locale, $args)) {
225
- $this->status = 'current';
226
- $this->translations[$lang->locale] = 'pending';
227
- unset($this->desc_array['lingotek']['api_errors']['_request_translations'][$lang->name]);
228
- }
229
- else {
230
- $this->desc_array['lingotek']['api_errors']['_request_translations'][$lang->name] = __('Error requesting translation for ', 'wp-lingotek') . $lang->name . __(' for post ', 'wp-lingotek') . $this->source;
231
- }
 
 
 
 
 
 
 
 
 
 
232
  }
233
  }
234
 
@@ -243,20 +266,26 @@ abstract class Lingotek_Group {
243
  public function translations_status() {
244
  $client = new Lingotek_API();
245
  $translations = $client->get_translations_status($this->document_id); // key are Lingotek locales
246
- if ($translations !== false) {
247
- foreach($this->translations as $locale => $status) {
248
- $lingotek_locale = $this->pllm->get_language($locale)->lingotek_locale;
249
- if ('current' != $status && isset($translations[$lingotek_locale]) && 100 == $translations[$lingotek_locale])
250
- $this->translations[$locale] = 'ready';
251
- }
252
- unset($this->desc_array['lingotek']['api_errors']['translations_status']);
253
- $this->save();
254
- }
255
- // take note of api errors
256
- else {
257
- $this->desc_array['lingotek']['api_errors']['translations_status'] = __('Error checking translations status of post ', 'wp-lingotek') . $this->source;
258
- $this->save();
 
 
 
 
 
259
  }
 
260
  }
261
 
262
  /*
139
  if ($res) {
140
  $this->status = 'importing';
141
  $this->translations = array_fill_keys(array_keys($this->translations), 'pending');
142
+ // Removed error reporting for release 1.1.2
143
+ // unset($this->desc_array['lingotek']['api_errors']['patch']);
144
+ // $this->save();
145
+ // }
146
+ // else {
147
+ // $this->desc_array['lingotek']['api_errors']['patch'] = __('Error uploading updated post ', 'wp-lingotek') . $this->source;
148
+ $this->save();
149
  }
150
  }
151
 
157
  public function source_status() {
158
  $client = new Lingotek_API();
159
 
160
+ if ('importing' == $this->status && $client->document_exists($this->document_id)) {
161
+ $this->status = 'current';
162
+ $this->save();
 
 
 
 
 
 
163
  }
164
 
165
+ // Removed error reporting for release 1.1.2
166
+ // $response = $client->document_exists($this->document_id);
167
+
168
+ // if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
169
+ // unset($this->desc_array['lingotek']['api_errors']['source_status']);
170
+ // if ('importing' == $this->status) {
171
+ // $this->status = 'current';
172
+ // }
173
+ // }
174
+ // elseif (400 == wp_remote_retrieve_response_code($response) || empty(wp_remote_retrieve_response_code($response))) {
175
+ // $this->desc_array['lingotek']['api_errors']['source_status'] = __('Error updating source status of post ', 'wp-lingotek') . $this->source;
176
+ // }
177
+
178
+ // $this->save();
179
  }
180
 
181
  /*
202
  $args = $workflow ? array('workflow_id' => $workflow) : array();
203
 
204
  if (!$this->is_disabled_target($language) && empty($this->translations[$language->locale])) {
205
+ $client->request_translation($this->document_id, $language->locale, $args);
206
+ $this->status = 'current';
207
+ $this->translations[$language->locale] = 'pending';
208
+ // Removed error reporting for release 1.1.2
209
+ // if ($client->request_translation($this->document_id, $language->locale, $args)) {
210
+ // $this->status = 'current';
211
+ // $this->translations[$language->locale] = 'pending';
212
+ // unset($this->desc_array['lingotek']['api_errors']['request_translation']);
213
+ // unset($this->desc_array['lingotek']['api_errors']['_request_translations']);
214
+ // }
215
+ // else {
216
+ // $this->desc_array['lingotek']['api_errors']['request_translation'] = __('Error requesting translation for ' . $language->name . ' for post ', 'wp-lingotek') . $this->source;
217
+ // }
218
+
219
  $this->save();
220
  }
221
  }
234
  if ($source_language->slug != $lang->slug && !$this->is_disabled_target($source_language, $lang) && empty($this->translations[$lang->locale])) {
235
  $workflow = Lingotek_Model::get_profile_option('workflow_id', $this->type, $source_language, $lang, $this->source);
236
  $args = $workflow ? array('workflow_id' => $workflow) : array();
237
+ $client->request_translation($this->document_id, $lang->lingotek_locale, $args);
238
+ $this->status = 'current';
239
+ $this->translations[$lang->locale] = 'pending';
240
+ // Removed error reporting for release 1.1.2
241
+ // if ($client->request_translation($this->document_id, $lang->lingotek_locale, $args)) {
242
+ // $this->status = 'current';
243
+ // $this->translations[$lang->locale] = 'pending';
244
+ // unset($this->desc_array['lingotek']['api_errors']['_request_translations'][$lang->name]);
245
+ // unset($this->desc_array['lingotek']['api_errors']['request_translation']);
246
+ // if (empty($this->desc_array['lingotek']['api_errors']['_request_translations'])) {
247
+ // unset($this->desc_array['lingotek']['api_errors']['_request_translations']);
248
+ // }
249
+ // }
250
+ // else {
251
+ // if (!isset($this->desc_array['lingotek']['api_errors']['_request_translations'][$lang->name])) {
252
+ // $this->desc_array['lingotek']['api_errors']['_request_translations'][$lang->name] = __('Error requesting translation for ', 'wp-lingotek') . $lang->name . __(' for post ', 'wp-lingotek') . $this->source;
253
+ // }
254
+ // }
255
  }
256
  }
257
 
266
  public function translations_status() {
267
  $client = new Lingotek_API();
268
  $translations = $client->get_translations_status($this->document_id); // key are Lingotek locales
269
+ foreach($this->translations as $locale => $status) {
270
+ $lingotek_locale = $this->pllm->get_language($locale)->lingotek_locale;
271
+ if ('current' != $status && isset($translations[$lingotek_locale]) && 100 == $translations[$lingotek_locale])
272
+ $this->translations[$locale] = 'ready';
273
+ // Removed error reporting for release 1.1.2
274
+ // if ($translations !== false) {
275
+ // foreach($this->translations as $locale => $status) {
276
+ // $lingotek_locale = $this->pllm->get_language($locale)->lingotek_locale;
277
+ // if ('current' != $status && isset($translations[$lingotek_locale]) && 100 == $translations[$lingotek_locale])
278
+ // $this->translations[$locale] = 'ready';
279
+ // }
280
+ // unset($this->desc_array['lingotek']['api_errors']['translations_status']);
281
+ // $this->save();
282
+ // }
283
+ // // take note of api errors
284
+ // else {
285
+ // $this->desc_array['lingotek']['api_errors']['translations_status'] = __('Error checking translations status of post ', 'wp-lingotek') . $this->source;
286
+ // $this->save();
287
  }
288
+ $this->save();
289
  }
290
 
291
  /*
include/model.php CHANGED
@@ -8,6 +8,8 @@
8
  */
9
  class Lingotek_Model {
10
  public $pllm; // Polylang model
 
 
11
 
12
  /*
13
  * constructor
@@ -209,6 +211,7 @@ class Lingotek_Model {
209
  * @return $new_post_id if copy of post is successful, false otherwise
210
  */
211
  public function copy_post($post, $target) {
 
212
  $document = $this->get_group('post', $post->ID);
213
  $prefs = self::get_prefs();
214
  $cp_lang = $this->pllm->get_language($target);
@@ -225,18 +228,13 @@ class Lingotek_Model {
225
  Lingotek_Group_Post::copy_or_ignore_metas($post->ID, $new_post_id);
226
  $document->desc_array[$target] = $new_post_id;
227
  $document->save();
228
- return $new_post_id;
229
  }
230
- else {
231
- return false;
232
- }
233
- }
234
- else {
235
- return false;
236
  }
 
237
  }
238
 
239
  public function copy_term($term, $target, $taxonomy) {
 
240
  $document = $this->get_group('term', $term->term_id);
241
  $cp_lang = $this->pllm->get_language($target);
242
  $cp_term = (array) $term;
@@ -253,6 +251,7 @@ class Lingotek_Model {
253
  $document->desc_array[$target] = $new_term['term_id'];
254
  $document->save();
255
  }
 
256
  }
257
 
258
  /*
@@ -297,28 +296,29 @@ class Lingotek_Model {
297
  $document->patch($post->post_title, $post, $external_url, $filter_ids);
298
  }
299
 
300
- elseif (!Lingotek_Group::$creating_translation) {
301
  $document_id = $client->upload_document($params);
302
 
303
  if ($document_id) {
304
  Lingotek_Group_Post::create($post->ID , $language, $document_id);
305
- $group = $this->get_group('post', $post_id);
306
- unset($group->desc_array['lingotek']['api_errors']['upload']);
307
- $group->save();
308
- }
309
- else {
310
- $group = $this->get_group('post', $post_id);
311
- $group->desc_array['lingotek']['api_errors']['upload'] = __('Error uploading post ', 'wp-lingotek') . $group->source;
312
- $group->save();
313
- }
314
- }
315
 
316
- // If a translation profile has targets set to copy then copy them
317
- $targets_to_copy = $this->targets_to_be_copied($profile);
318
- if (!empty($targets_to_copy)) {
319
- foreach ($targets_to_copy as $target) {
320
- $this->copy_post($post, $target);
 
 
 
 
 
 
321
  }
 
 
 
 
 
322
  }
323
  }
324
 
@@ -363,19 +363,19 @@ class Lingotek_Model {
363
  $document->patch($term->name, $term, '', $filter_ids);
364
  }
365
 
366
- elseif (!Lingotek_Group::$creating_translation) {
367
  $document_id = $client->upload_document($params);
368
 
369
  if ($document_id) {
370
  Lingotek_Group_Term::create($term_id, $taxonomy , $language, $document_id);
371
- }
372
- }
373
 
374
- // If a translation profile has targets set to copy then copy them
375
- $targets_to_copy = $this->targets_to_be_copied($profile);
376
- if (!empty($targets_to_copy)) {
377
- foreach ($targets_to_copy as $target) {
378
- $this->copy_term($term, $target, $taxonomy);
 
 
379
  }
380
  }
381
  }
@@ -472,7 +472,7 @@ class Lingotek_Model {
472
  // FIXME how to get profile to check if disabled?
473
 
474
  return !empty($language) && (empty($document) ||
475
- (1 == count($this->pllm->get_translations($type, $object_id)) && empty($document->source)) || // specific for terms as document is never empty
476
  (isset($document) && 'edited' == $document->status && $document->source == $object_id));
477
  }
478
  }
8
  */
9
  class Lingotek_Model {
10
  public $pllm; // Polylang model
11
+ static public $copying_post;
12
+ static public $copying_term;
13
 
14
  /*
15
  * constructor
211
  * @return $new_post_id if copy of post is successful, false otherwise
212
  */
213
  public function copy_post($post, $target) {
214
+ self::$copying_post = true;
215
  $document = $this->get_group('post', $post->ID);
216
  $prefs = self::get_prefs();
217
  $cp_lang = $this->pllm->get_language($target);
228
  Lingotek_Group_Post::copy_or_ignore_metas($post->ID, $new_post_id);
229
  $document->desc_array[$target] = $new_post_id;
230
  $document->save();
 
231
  }
 
 
 
 
 
 
232
  }
233
+ self::$copying_post = false;
234
  }
235
 
236
  public function copy_term($term, $target, $taxonomy) {
237
+ self::$copying_term = true;
238
  $document = $this->get_group('term', $term->term_id);
239
  $cp_lang = $this->pllm->get_language($target);
240
  $cp_term = (array) $term;
251
  $document->desc_array[$target] = $new_term['term_id'];
252
  $document->save();
253
  }
254
+ self::$copying_term = false;
255
  }
256
 
257
  /*
296
  $document->patch($post->post_title, $post, $external_url, $filter_ids);
297
  }
298
 
299
+ elseif (!Lingotek_Group::$creating_translation && !self::$copying_post) {
300
  $document_id = $client->upload_document($params);
301
 
302
  if ($document_id) {
303
  Lingotek_Group_Post::create($post->ID , $language, $document_id);
 
 
 
 
 
 
 
 
 
 
304
 
305
+ // If a translation profile has targets set to copy then copy them
306
+ $targets_to_copy = $this->targets_to_be_copied($profile);
307
+ if (!empty($targets_to_copy)) {
308
+ foreach ($targets_to_copy as $target) {
309
+ $this->copy_post($post, $target);
310
+ }
311
+ }
312
+ // Error reporting commented out for release 1.1.2
313
+ // $group = $this->get_group('post', $post_id);
314
+ // unset($group->desc_array['lingotek']['api_errors']['upload']);
315
+ // $group->save();
316
  }
317
+ // else {
318
+ // $group = $this->get_group('post', $post_id);
319
+ // $group->desc_array['lingotek']['api_errors']['upload'] = __('Error uploading post ', 'wp-lingotek') . $group->source;
320
+ // $group->save();
321
+ // }
322
  }
323
  }
324
 
363
  $document->patch($term->name, $term, '', $filter_ids);
364
  }
365
 
366
+ elseif (!Lingotek_Group::$creating_translation && !self::$copying_term) {
367
  $document_id = $client->upload_document($params);
368
 
369
  if ($document_id) {
370
  Lingotek_Group_Term::create($term_id, $taxonomy , $language, $document_id);
 
 
371
 
372
+ // If a translation profile has targets set to copy then copy them
373
+ $targets_to_copy = $this->targets_to_be_copied($profile);
374
+ if (!empty($targets_to_copy)) {
375
+ foreach ($targets_to_copy as $target) {
376
+ $this->copy_term($term, $target, $taxonomy);
377
+ }
378
+ }
379
  }
380
  }
381
  }
472
  // FIXME how to get profile to check if disabled?
473
 
474
  return !empty($language) && (empty($document) ||
475
+ (empty($document->translations) && empty($document->source)) || // specific for terms as document is never empty
476
  (isset($document) && 'edited' == $document->status && $document->source == $object_id));
477
  }
478
  }
js/defaults.js CHANGED
@@ -17,16 +17,18 @@ function toggleTextbox () {
17
  }
18
  }
19
 
20
-
21
  jQuery(document).ready(function($) {
22
- if ($('#lingotek_profile_meta').val() == 'default') {
 
 
 
 
 
 
 
23
  $('#post_lang_choice').change(function(){
24
- var pl_choice = $('#post_lang_choice').val();
25
- var content_profiles = $('#lingotek-language-profiles').text();
26
- var content_json = $.parseJSON(content_profiles);
27
- var profile_name = content_json[pl_choice] ? content_json[pl_choice] : content_json.defaults.content_default;
28
-
29
- $('#lingotek_profile_meta option:first').text(content_json.defaults.title + ' (' + profile_name + ')');
30
- }).change();
31
  }
32
  });
17
  }
18
  }
19
 
 
20
  jQuery(document).ready(function($) {
21
+ function init_profiles() {
22
+ var pl_choice = $('#post_lang_choice').val();
23
+ var content_profiles = $('#lingotek-language-profiles').text();
24
+ var content_json = $.parseJSON(content_profiles);
25
+ var profile_name = content_json[pl_choice] ? content_json[pl_choice] : content_json.defaults.content_default;
26
+ $('#lingotek_profile_meta option:first').text(content_json.defaults.title + ' (' + profile_name + ')');
27
+ }
28
+ if ($('#lingotek_profile_meta').val() == 'default') {
29
  $('#post_lang_choice').change(function(){
30
+ init_profiles();
31
+ });
32
+ init_profiles();
 
 
 
 
33
  }
34
  });
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.1.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.
@@ -15,7 +15,7 @@ GitHub Plugin URI: https://github.com/lingotek/wp-lingotek
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
- define('LINGOTEK_VERSION', '1.1.1'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.7.4.2');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'wp-lingotek');// plugin slug (should match above meta: Text Domain)
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.1.2
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
+ define('LINGOTEK_VERSION', '1.1.2'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.7.4.2');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'wp-lingotek');// plugin slug (should match above meta: Text Domain)
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: 4.3
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -118,6 +118,12 @@ For more, visit the [Lingotek documentation site](https://lingotek.atlassian.net
118
 
119
  == Changelog ==
120
 
 
 
 
 
 
 
121
  = 1.1.1 (2015-09-11) =
122
 
123
  * Added better logging and display of Lingotek API errors
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
  Tested up to: 4.3
7
+ Stable tag: 1.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
118
 
119
  == Changelog ==
120
 
121
+ = 1.1.2 (2015-09-18) =
122
+
123
+ * Fix for copy feature
124
+ * Fix for content status displays
125
+ * Other minor fixes
126
+
127
  = 1.1.1 (2015-09-11) =
128
 
129
  * Added better logging and display of Lingotek API errors