locale_translate_batch_refresh(&$context)
Implements callback_batch_operation().
Refreshes translations after importing strings.
Parameters
array|\ArrayAccess $context.: Contains a list of strings updated and information about the progress.
File
- core/modules/locale/locale.bulk.inc, line 299
- Mass import-export and batch import functionality for Gettext .po files.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | function locale_translate_batch_refresh(& $context ) { if (!isset( $context [ 'sandbox' ][ 'refresh' ])) { $strings = $langcodes = array (); if (isset( $context [ 'results' ][ 'stats' ])) { // Get list of unique string identifiers and language codes updated. $langcodes = array_unique ( array_values ( $context [ 'results' ][ 'languages' ])); foreach ( $context [ 'results' ][ 'stats' ] as $report ) { $strings = array_merge ( $strings , $report [ 'strings' ]); } } if ( $strings ) { // Initialize multi-step string refresh. $context [ 'message' ] = t( 'Updating translations for JavaScript and default configuration.' ); $context [ 'sandbox' ][ 'refresh' ][ 'strings' ] = array_unique ( $strings ); $context [ 'sandbox' ][ 'refresh' ][ 'languages' ] = $langcodes ; $context [ 'sandbox' ][ 'refresh' ][ 'names' ] = array (); $context [ 'results' ][ 'stats' ][ 'config' ] = 0; $context [ 'sandbox' ][ 'refresh' ][ 'count' ] = count ( $strings ); // We will update strings on later steps. $context [ 'finished' ] = 0; } else { $context [ 'finished' ] = 1; } } elseif ( $name = array_shift ( $context [ 'sandbox' ][ 'refresh' ][ 'names' ])) { // Refresh all languages for one object at a time. $count = Locale::config()->updateConfigTranslations( array ( $name ), $context [ 'sandbox' ][ 'refresh' ][ 'languages' ]); $context [ 'results' ][ 'stats' ][ 'config' ] += $count ; // Inherit finished information from the "parent" string lookup step so // visual display of status will make sense. $context [ 'finished' ] = $context [ 'sandbox' ][ 'refresh' ][ 'names_finished' ]; $context [ 'message' ] = t( 'Updating default configuration (@percent%).' , array ( '@percent' => (int) ( $context [ 'finished' ] * 100))); } elseif (! empty ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ])) { // Not perfect but will give some indication of progress. $context [ 'finished' ] = 1 - count ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ]) / $context [ 'sandbox' ][ 'refresh' ][ 'count' ]; // Pending strings, refresh 100 at a time, get next pack. $next = array_slice ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ], 0, 100); array_splice ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ], 0, count ( $next )); // Clear cache and force refresh of JavaScript translations. _locale_refresh_translations( $context [ 'sandbox' ][ 'refresh' ][ 'languages' ], $next ); // Check whether we need to refresh configuration objects. if ( $names = Locale::config()->getStringNames( $next )) { $context [ 'sandbox' ][ 'refresh' ][ 'names_finished' ] = $context [ 'finished' ]; $context [ 'sandbox' ][ 'refresh' ][ 'names' ] = $names ; } } else { $context [ 'message' ] = t( 'Updated default configuration.' ); $context [ 'finished' ] = 1; } } |
Please login to continue.