2011-08-02 00:37:34 +00:00
< ? php
/**
2011-08-07 13:10:57 +00:00
* @ file
* Interface translation summary , editing and deletion user interfaces .
2011-08-02 00:37:34 +00:00
*/
Issue #1825952 by Fabianx, joelpittet, bdragon, heddn, chx, xjm, pwolanin, mikey_p, ti2m, bfr, dags, cilefen, scor, mgifford: Turn on twig autoescape by default
2014-07-18 09:05:22 +00:00
use Drupal\Component\Utility\SafeMarkup ;
2014-09-29 13:41:29 +00:00
use Drupal\Core\Url ;
2014-03-31 17:37:55 +00:00
use Drupal\Core\Render\Element ;
2012-10-08 18:10:13 +00:00
use Drupal\locale\SourceString ;
use Drupal\locale\TranslationString ;
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
use Symfony\Component\HttpFoundation\RedirectResponse ;
2012-06-02 19:41:40 +00:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException ;
2011-08-02 00:37:34 +00:00
/**
2013-09-11 08:14:17 +00:00
* Page callback : Checks for translation updates and displays the status .
2012-10-05 15:42:46 +00:00
*
2013-09-11 08:14:17 +00:00
* Manually checks the translation status without the use of cron .
2012-10-05 15:42:46 +00:00
*
* @ see locale_menu ()
2011-08-02 00:37:34 +00:00
*/
2013-09-11 08:14:17 +00:00
function locale_translation_manual_status () {
module_load_include ( 'compare.inc' , 'locale' );
2011-08-02 00:37:34 +00:00
2013-09-11 08:14:17 +00:00
// Check the translation status of all translatable projects in all languages.
// First we clear the cached list of projects. Although not strictly
// necessary, this is helpful in case the project list is out of sync.
locale_translation_flush_projects ();
locale_translation_check_projects ();
Issue #1452188 by Schnitzel, droplet, Sutharsan, Bojhan, Kristen Pol, Gábor Hojtsy, ershov.andrey, perusio, nod_, rvilar, andypost: Added New UI for string translation.
2012-06-15 10:01:31 +00:00
2013-09-11 08:14:17 +00:00
// Execute a batch if required. A batch is only used when remote files
// are checked.
if ( batch_get ()) {
return batch_process ( 'admin/reports/translations' );
Issue #1452188 by Schnitzel, droplet, Sutharsan, Bojhan, Kristen Pol, Gábor Hojtsy, ershov.andrey, perusio, nod_, rvilar, andypost: Added New UI for string translation.
2012-06-15 10:01:31 +00:00
}
2014-09-27 07:03:46 +00:00
return new RedirectResponse ( \Drupal :: url ( 'locale.translate_status' , array (), array ( 'absolute' => TRUE )));
2011-08-02 00:37:34 +00:00
}
2012-12-19 22:11:34 +00:00
/**
2013-06-16 23:54:01 +00:00
* Prepares variables for translation status information templates .
*
* Translation status information is displayed per language .
*
* Default template : locale - translate - edit - form - strings . html . twig .
2012-12-19 22:11:34 +00:00
*
* @ param array $variables
* An associative array containing :
* - updates : The projects which have updates .
* - not_found : The projects which updates are not found .
*
2014-07-15 11:13:13 +00:00
* @ see \Drupal\locale\Form\TranslationStatusForm
2012-12-19 22:11:34 +00:00
*/
2014-10-22 09:58:00 +00:00
function template_preprocess_locale_translation_update_info ( array & $variables ) {
2013-06-16 23:54:01 +00:00
$details = array ();
2012-12-19 22:11:34 +00:00
// Build output for available updates.
if ( isset ( $variables [ 'updates' ])) {
2013-08-23 01:36:59 +00:00
$releases = array ();
2012-12-19 22:11:34 +00:00
if ( $variables [ 'updates' ]) {
foreach ( $variables [ 'updates' ] as $update ) {
$modules [] = $update [ 'name' ];
2015-03-29 22:13:25 +00:00
$releases [] = SafeMarkup :: format ( '@module (@date)' , array (
2015-01-15 11:09:59 +00:00
'@module' => $update [ 'name' ],
'@date' => format_date ( $update [ 'timestamp' ], 'html_date' ),
));
2012-12-19 22:11:34 +00:00
}
2013-06-16 23:54:01 +00:00
$variables [ 'modules' ] = $modules ;
2012-12-19 22:11:34 +00:00
}
2013-06-16 23:54:01 +00:00
$details [ 'available_updates_list' ] = array (
'#theme' => 'item_list' ,
'#items' => $releases ,
);
2012-12-19 22:11:34 +00:00
}
// Build output for updates not found.
if ( isset ( $variables [ 'not_found' ])) {
2013-08-23 01:36:59 +00:00
$releases = array ();
2015-01-10 13:56:47 +00:00
$variables [ 'missing_updates_status' ] = \Drupal :: translation () -> formatPlural ( count ( $variables [ 'not_found' ]), 'Missing translations for one project' , 'Missing translations for @count projects' );
2012-12-19 22:11:34 +00:00
if ( $variables [ 'not_found' ]) {
foreach ( $variables [ 'not_found' ] as $update ) {
$version = $update [ 'version' ] ? $update [ 'version' ] : t ( 'no version' );
2015-03-29 22:13:25 +00:00
$releases [] = SafeMarkup :: format ( '@module (@version). !info' , array (
2015-01-15 11:09:59 +00:00
'@module' => $update [ 'name' ],
'@version' => $version ,
'!info' => $update [ 'info' ],
));
2012-12-19 22:11:34 +00:00
}
}
2013-06-16 23:54:01 +00:00
$details [ 'missing_updates_list' ] = array (
'#theme' => 'item_list' ,
'#items' => $releases ,
);
// Prefix the missing updates list if there is an available updates lists
// before it.
if ( ! empty ( $details [ 'available_updates_list' ][ '#items' ])) {
$details [ 'missing_updates_list' ][ '#prefix' ] = t ( 'Missing translations for:' );
2012-12-19 22:11:34 +00:00
}
}
2013-06-16 23:54:01 +00:00
$variables [ 'details' ] = $details ;
2012-12-19 22:11:34 +00:00
}
/**
2013-06-16 23:54:01 +00:00
* Prepares variables for most recent translation update templates .
*
* Displays the last time we checked for locale update data . In addition to
* properly formatting the given timestamp , this function also provides a " Check
* manually " link that refreshes the available update and redirects back to the
* same page .
2012-12-19 22:11:34 +00:00
*
2013-06-16 23:54:01 +00:00
* Default template : locale - translation - last - check . html . twig .
2012-12-19 22:11:34 +00:00
*
2014-10-22 09:58:00 +00:00
* @ param array $variables
2012-12-19 22:11:34 +00:00
* An associative array containing :
* - last : The timestamp when the site last checked for available updates .
*
2014-07-15 11:13:13 +00:00
* @ see \Drupal\locale\Form\TranslationStatusForm
2012-12-19 22:11:34 +00:00
*/
2014-10-22 09:58:00 +00:00
function template_preprocess_locale_translation_last_check ( array & $variables ) {
2012-12-19 22:11:34 +00:00
$last = $variables [ 'last' ];
2013-06-16 23:54:01 +00:00
$variables [ 'last_checked' ] = ( $last != NULL );
2014-08-05 10:39:21 +00:00
$variables [ 'time' ] = \Drupal :: service ( 'date.formatter' ) -> formatInterval ( REQUEST_TIME - $last );
2015-04-09 14:56:37 +00:00
$variables [ 'link' ] = \Drupal :: l ( t ( 'Check manually' ), new Url ( 'locale.check_translation' , array (), array ( 'query' => \Drupal :: destination () -> getAsArray ())));
2012-12-19 22:11:34 +00:00
}