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-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
}
2013-09-11 08:14:17 +00:00
return new RedirectResponse ( url ( 'admin/reports/translations' , array ( 'absolute' => TRUE )));
2011-08-02 00:37:34 +00:00
}
2012-12-19 22:11:34 +00:00
/**
* Returns HTML for translation edit form .
*
* @ param array $variables
* An associative array containing :
* - form : The form that contains the language information .
*
* @ see locale_translate_edit_form ()
* @ ingroup themeable
2011-08-02 00:37:34 +00:00
*/
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
function theme_locale_translate_edit_form_strings ( $variables ) {
$output = '' ;
$form = $variables [ 'form' ];
$header = array (
t ( 'Source string' ),
t ( 'Translation for @language' , array ( '@language' => $form [ '#language' ])),
);
$rows = array ();
2014-03-31 17:37:55 +00:00
foreach ( Element :: children ( $form ) as $lid ) {
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
$string = $form [ $lid ];
if ( $string [ 'plural' ][ '#value' ]) {
$source = drupal_render ( $string [ 'original_singular' ]) . '<br />' . drupal_render ( $string [ 'original_plural' ]);
}
else {
$source = drupal_render ( $string [ 'original' ]);
}
$source .= empty ( $string [ 'context' ]) ? '' : '<br /><small>' . t ( 'In Context' ) . ': ' . $string [ 'context' ][ '#value' ] . '</small>' ;
$rows [] = array (
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
array ( 'data' => SafeMarkup :: set ( $source )),
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
array ( 'data' => $string [ 'translations' ]),
);
2011-08-02 00:37:34 +00:00
}
2013-08-23 01:36:59 +00:00
$table = array (
2014-03-12 15:46:33 +00:00
'#type' => 'table' ,
2013-08-23 01:36:59 +00:00
'#header' => $header ,
'#rows' => $rows ,
'#empty' => t ( 'No strings available.' ),
'#attributes' => array ( 'class' => array ( 'locale-translate-edit-table' )),
);
$output .= drupal_render ( $table );
$pager = array ( '#theme' => 'pager' );
$output .= drupal_render ( $pager );
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
return $output ;
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
*/
2013-06-16 23:54:01 +00:00
function template_preprocess_locale_translation_update_info ( & $variables ) {
$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' ];
$releases [] = t ( '@module (@date)' , array ( '@module' => $update [ 'name' ], '@date' => format_date ( $update [ 'timestamp' ], 'html_date' )));
}
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 ();
2013-06-16 23:54:01 +00:00
$variables [ 'missing_updates_status' ] = format_plural ( 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' );
$releases [] = t ( '@module (@version).' , array ( '@module' => $update [ 'name' ], '@version' => $version )) . ' ' . $update [ 'info' ];
}
}
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
*
* @ param $variables
* 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
*/
2013-06-16 23:54:01 +00:00
function template_preprocess_locale_translation_last_check ( & $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 );
2013-06-16 23:54:01 +00:00
$variables [ 'link' ] = l ( t ( 'Check manually' ), 'admin/reports/translations/check' , array ( 'query' => drupal_get_destination ()));
2012-12-19 22:11:34 +00:00
}