60 |
60 |
61 /* |
61 /* |
62 * Avoid messing with VCS installations, at least for now. |
62 * Avoid messing with VCS installations, at least for now. |
63 * Noted: this is not the ideal way to accomplish this. |
63 * Noted: this is not the ideal way to accomplish this. |
64 */ |
64 */ |
65 $check_vcs = new WP_Automatic_Updater; |
65 $check_vcs = new WP_Automatic_Updater(); |
66 if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) { |
66 if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) { |
67 return; |
67 return; |
68 } |
68 } |
69 |
69 |
70 foreach ( $language_updates as $key => $language_update ) { |
70 foreach ( $language_updates as $key => $language_update ) { |
103 $lp_upgrader = new Language_Pack_Upgrader( $skin ); |
103 $lp_upgrader = new Language_Pack_Upgrader( $skin ); |
104 $lp_upgrader->bulk_upgrade( $language_updates ); |
104 $lp_upgrader->bulk_upgrade( $language_updates ); |
105 } |
105 } |
106 |
106 |
107 /** |
107 /** |
108 * Initialize the upgrade strings. |
108 * Initializes the upgrade strings. |
109 * |
109 * |
110 * @since 3.7.0 |
110 * @since 3.7.0 |
111 */ |
111 */ |
112 public function upgrade_strings() { |
112 public function upgrade_strings() { |
113 $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while they are updated as well.' ); |
113 $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while they are updated as well.' ); |
114 $this->strings['up_to_date'] = __( 'Your translations are all up to date.' ); |
114 $this->strings['up_to_date'] = __( 'Your translations are all up to date.' ); |
115 $this->strings['no_package'] = __( 'Update package not available.' ); |
115 $this->strings['no_package'] = __( 'Update package not available.' ); |
116 /* translators: %s: Package URL. */ |
116 /* translators: %s: Package URL. */ |
117 $this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…' ), '<span class="code">%s</span>' ); |
117 $this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…' ), '<span class="code pre">%s</span>' ); |
118 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); |
118 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); |
119 $this->strings['process_failed'] = __( 'Translation update failed.' ); |
119 $this->strings['process_failed'] = __( 'Translation update failed.' ); |
120 $this->strings['process_success'] = __( 'Translation updated successfully.' ); |
120 $this->strings['process_success'] = __( 'Translation updated successfully.' ); |
121 $this->strings['remove_old'] = __( 'Removing the old version of the translation…' ); |
121 $this->strings['remove_old'] = __( 'Removing the old version of the translation…' ); |
122 $this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' ); |
122 $this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' ); |
123 } |
123 } |
124 |
124 |
125 /** |
125 /** |
126 * Upgrade a language pack. |
126 * Upgrades a language pack. |
127 * |
127 * |
128 * @since 3.7.0 |
128 * @since 3.7.0 |
129 * |
129 * |
130 * @param string|false $update Optional. Whether an update offer is available. Default false. |
130 * @param string|false $update Optional. Whether an update offer is available. Default false. |
131 * @param array $args Optional. Other optional arguments, see |
131 * @param array $args Optional. Other optional arguments, see |
145 |
145 |
146 return $results[0]; |
146 return $results[0]; |
147 } |
147 } |
148 |
148 |
149 /** |
149 /** |
150 * Bulk upgrade language packs. |
150 * Upgrades several language packs at once. |
151 * |
151 * |
152 * @since 3.7.0 |
152 * @since 3.7.0 |
153 * |
153 * |
154 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
154 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
155 * |
155 * |
156 * @param object[] $language_updates Optional. Array of language packs to update. @see wp_get_translation_updates(). |
156 * @param object[] $language_updates Optional. Array of language packs to update. See {@see wp_get_translation_updates()}. |
157 * Default empty array. |
157 * Default empty array. |
158 * @param array $args { |
158 * @param array $args { |
159 * Other arguments for upgrading multiple language packs. Default empty array. |
159 * Other arguments for upgrading multiple language packs. Default empty array. |
160 * |
160 * |
161 * @type bool $clear_update_cache Whether to clear the update cache when done. |
161 * @type bool $clear_update_cache Whether to clear the update cache when done. |
236 $destination .= '/plugins'; |
236 $destination .= '/plugins'; |
237 } elseif ( 'theme' === $language_update->type ) { |
237 } elseif ( 'theme' === $language_update->type ) { |
238 $destination .= '/themes'; |
238 $destination .= '/themes'; |
239 } |
239 } |
240 |
240 |
241 $this->update_current++; |
241 ++$this->update_current; |
242 |
242 |
243 $options = array( |
243 $options = array( |
244 'package' => $language_update->package, |
244 'package' => $language_update->package, |
245 'destination' => $destination, |
245 'destination' => $destination, |
246 'clear_destination' => true, |
246 'clear_destination' => true, |
330 } |
330 } |
331 |
331 |
332 // Check that the folder contains a valid language. |
332 // Check that the folder contains a valid language. |
333 $files = $wp_filesystem->dirlist( $remote_source ); |
333 $files = $wp_filesystem->dirlist( $remote_source ); |
334 |
334 |
335 // Check to see if a .po and .mo exist in the folder. |
335 // Check to see if the expected files exist in the folder. |
336 $po = false; |
336 $po = false; |
337 $mo = false; |
337 $mo = false; |
|
338 $php = false; |
338 foreach ( (array) $files as $file => $filedata ) { |
339 foreach ( (array) $files as $file => $filedata ) { |
339 if ( '.po' === substr( $file, -3 ) ) { |
340 if ( str_ends_with( $file, '.po' ) ) { |
340 $po = true; |
341 $po = true; |
341 } elseif ( '.mo' === substr( $file, -3 ) ) { |
342 } elseif ( str_ends_with( $file, '.mo' ) ) { |
342 $mo = true; |
343 $mo = true; |
343 } |
344 } elseif ( str_ends_with( $file, '.l10n.php' ) ) { |
|
345 $php = true; |
|
346 } |
|
347 } |
|
348 |
|
349 if ( $php ) { |
|
350 return $source; |
344 } |
351 } |
345 |
352 |
346 if ( ! $mo || ! $po ) { |
353 if ( ! $mo || ! $po ) { |
347 return new WP_Error( |
354 return new WP_Error( |
348 'incompatible_archive_pomo', |
355 'incompatible_archive_pomo', |
349 $this->strings['incompatible_archive'], |
356 $this->strings['incompatible_archive'], |
350 sprintf( |
357 sprintf( |
351 /* translators: 1: .po, 2: .mo */ |
358 /* translators: 1: .po, 2: .mo, 3: .l10n.php */ |
352 __( 'The language pack is missing either the %1$s or %2$s files.' ), |
359 __( 'The language pack is missing either the %1$s, %2$s, or %3$s files.' ), |
353 '<code>.po</code>', |
360 '<code>.po</code>', |
354 '<code>.mo</code>' |
361 '<code>.mo</code>', |
|
362 '<code>.l10n.php</code>' |
355 ) |
363 ) |
356 ); |
364 ); |
357 } |
365 } |
358 |
366 |
359 return $source; |
367 return $source; |
360 } |
368 } |
361 |
369 |
362 /** |
370 /** |
363 * Get the name of an item being updated. |
371 * Gets the name of an item being updated. |
364 * |
372 * |
365 * @since 3.7.0 |
373 * @since 3.7.0 |
366 * |
374 * |
367 * @param object $update The data for an update. |
375 * @param object $update The data for an update. |
368 * @return string The name of the item being updated. |
376 * @return string The name of the item being updated. |
407 |
415 |
408 if ( 'core' === $language_update->type ) { |
416 if ( 'core' === $language_update->type ) { |
409 $files = array( |
417 $files = array( |
410 $remote_destination . $language_update->language . '.po', |
418 $remote_destination . $language_update->language . '.po', |
411 $remote_destination . $language_update->language . '.mo', |
419 $remote_destination . $language_update->language . '.mo', |
|
420 $remote_destination . $language_update->language . '.l10n.php', |
412 $remote_destination . 'admin-' . $language_update->language . '.po', |
421 $remote_destination . 'admin-' . $language_update->language . '.po', |
413 $remote_destination . 'admin-' . $language_update->language . '.mo', |
422 $remote_destination . 'admin-' . $language_update->language . '.mo', |
|
423 $remote_destination . 'admin-' . $language_update->language . '.l10n.php', |
414 $remote_destination . 'admin-network-' . $language_update->language . '.po', |
424 $remote_destination . 'admin-network-' . $language_update->language . '.po', |
415 $remote_destination . 'admin-network-' . $language_update->language . '.mo', |
425 $remote_destination . 'admin-network-' . $language_update->language . '.mo', |
|
426 $remote_destination . 'admin-network-' . $language_update->language . '.l10n.php', |
416 $remote_destination . 'continents-cities-' . $language_update->language . '.po', |
427 $remote_destination . 'continents-cities-' . $language_update->language . '.po', |
417 $remote_destination . 'continents-cities-' . $language_update->language . '.mo', |
428 $remote_destination . 'continents-cities-' . $language_update->language . '.mo', |
|
429 $remote_destination . 'continents-cities-' . $language_update->language . '.l10n.php', |
418 ); |
430 ); |
419 |
431 |
420 $json_translation_files = glob( $language_directory . $language_update->language . '-*.json' ); |
432 $json_translation_files = glob( $language_directory . $language_update->language . '-*.json' ); |
421 if ( $json_translation_files ) { |
433 if ( $json_translation_files ) { |
422 foreach ( $json_translation_files as $json_translation_file ) { |
434 foreach ( $json_translation_files as $json_translation_file ) { |
425 } |
437 } |
426 } else { |
438 } else { |
427 $files = array( |
439 $files = array( |
428 $remote_destination . $language_update->slug . '-' . $language_update->language . '.po', |
440 $remote_destination . $language_update->slug . '-' . $language_update->language . '.po', |
429 $remote_destination . $language_update->slug . '-' . $language_update->language . '.mo', |
441 $remote_destination . $language_update->slug . '-' . $language_update->language . '.mo', |
|
442 $remote_destination . $language_update->slug . '-' . $language_update->language . '.l10n.php', |
430 ); |
443 ); |
431 |
444 |
432 $language_directory = $language_directory . $language_update->type . 's/'; |
445 $language_directory = $language_directory . $language_update->type . 's/'; |
433 $json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' ); |
446 $json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' ); |
434 if ( $json_translation_files ) { |
447 if ( $json_translation_files ) { |