Changeset 9293 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/wp-i18n-teams.php
- Timestamp:
- 11/24/2019 03:04:38 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/wp-i18n-teams.php
r8879 r9293 317 317 } 318 318 319 $projects = array( 'wp/dev', 'wp/dev/ admin', 'wp/dev/admin/network' );319 $projects = array( 'wp/dev', 'wp/dev/cc', 'wp/dev/admin', 'wp/dev/admin/network' ); 320 320 $counts = $percentages = array(); 321 321 foreach ( $projects as $project ) { 322 322 $results = json_decode( file_get_contents( 'https://translate.wordpress.org/api/projects/' . $project ) ); 323 323 foreach ( $results->translation_sets as $set ) { 324 if ( $set->slug !== 'default' ) { 325 continue; 326 } 324 327 325 if ( ! isset( $set->wp_locale ) ) { 328 326 continue; 329 327 } 328 329 $wp_locale = $set->wp_locale; 330 if ( $set->slug !== 'default' ) { 331 $wp_locale = $wp_locale . '_' . $set->slug; 332 } 333 330 334 if ( ! isset( $counts[ $set->wp_locale ] ) ) { 331 $counts[ $ set->wp_locale ] = array( 'current' => 0, 'total' => 0 );335 $counts[ $wp_locale ] = 0; 332 336 } 333 $counts[ $set->wp_locale ]['total'] += (int) $set->current_count + (int) $set->untranslated_count; 334 $counts[ $set->wp_locale ]['current'] += (int) $set->current_count; 335 } 336 } 337 foreach ( $counts as $locale => $count ) { 338 $percentages[ $locale ] = ( $count['total'] > 0 ) ? floor( $count['current'] / $count['total'] * 100 ) : 0; 339 } 337 $counts[ $wp_locale ] += (int) $set->percent_translated; 338 } 339 } 340 341 foreach ( $counts as $locale => $percent_translated ) { 342 // English locales don't have wp/dev/cc. 343 $projects_count = 0 === strpos( $locale, 'en_' ) ? 3 : 4; 344 345 /* 346 * > 50% round down, so that a project with all strings except 1 translated shows 99%, instead of 100%. 347 * < 50% round up, so that a project with just a few strings shows 1%, instead of 0%. 348 */ 349 $percent_complete = 100 / ( 100 * $projects_count ) * $percent_translated; 350 $percent_complete = ( $percent_complete > 50 ) ? floor( $percent_complete ) : ceil( $percent_complete ); 351 352 $percentages[ $locale ] = $percent_complete; 353 } 354 340 355 set_transient( 'core_translation_data', $percentages, 900 ); 356 341 357 return $percentages; 342 358 }
Note: See TracChangeset
for help on using the changeset viewer.