Commit d4e8abd8 authored by alexpott's avatar alexpott

Issue #1938916 by joelpittet, akalata, a-fro, duellj, InternetDevels, lauriii:...

Issue #1938916 by joelpittet, akalata, a-fro, duellj, InternetDevels, lauriii: Convert locale theme tables to table #type
parent 23b70dfb
......@@ -180,11 +180,6 @@ function locale_help($route_name, RouteMatchInterface $route_match) {
*/
function locale_theme() {
return array(
'locale_translate_edit_form_strings' => array(
'render element' => 'form',
'file' => 'locale.pages.inc',
'function' => 'theme_locale_translate_edit_form_strings',
),
'locale_translation_last_check' => array(
'variables' => array('last' => NULL),
'file' => 'locale.pages.inc',
......
......@@ -37,54 +37,6 @@ function locale_translation_manual_status() {
return new RedirectResponse(\Drupal::url('locale.translate_status', array(), array('absolute' => TRUE)));
}
/**
* Returns HTML for translation edit form.
*
* @param array $variables
* An associative array containing:
* - form: The form that contains the language information.
*
* @return string
* The themed output.
*
* @see locale_translate_edit_form()
* @ingroup themeable
*/
function theme_locale_translate_edit_form_strings(array $variables) {
$output = '';
$form = $variables['form'];
$header = array(
t('Source string'),
t('Translation for @language', array('@language' => $form['#language'])),
);
$rows = array();
foreach (Element::children($form) as $lid) {
$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') . ':&nbsp;' . $string['context']['#value'] . '</small>';
$rows[] = array(
array('data' => SafeMarkup::set($source)),
array('data' => $string['translations']),
);
}
$table = array(
'#type' => 'table',
'#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);
return $output;
}
/**
* Prepares variables for translation status information templates.
*
......
......@@ -44,10 +44,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
$form['strings'] = array(
'#type' => 'item',
'#type' => 'table',
'#tree' => TRUE,
'#language' => $langname,
'#theme' => 'locale_translate_edit_form_strings',
'#header' => [
$this->t('Source string'),
$this->t('Translation for @language', ['@language' => $langname]),
],
'#empty' => $this->t('No strings available.'),
'#attributes' => ['class' => ['locale-translate-edit-table']],
);
if (isset($langcode)) {
......@@ -63,10 +68,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$translation_array = $string->getPlurals();
if (count($source_array) == 1) {
// Add original string value and mark as non-plural.
$form['strings'][$string->lid]['plural'] = array(
'#type' => 'value',
'#value' => 0,
);
$plural = FALSE;
$form['strings'][$string->lid]['original'] = array(
'#type' => 'item',
'#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))),
......@@ -76,31 +78,37 @@ public function buildForm(array $form, FormStateInterface $form_state) {
}
else {
// Add original string value and mark as plural.
$form['strings'][$string->lid]['plural'] = array(
'#type' => 'value',
'#value' => 1,
);
$form['strings'][$string->lid]['original_singular'] = array(
$plural = TRUE;
$original_singular = [
'#type' => 'item',
'#title' => $this->t('Singular form'),
'#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>',
'#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))) . '</span>',
);
$form['strings'][$string->lid]['original_plural'] = array(
];
$original_plural = [
'#type' => 'item',
'#title' => $this->t('Plural form'),
'#markup' => '<span lang="en">' . String::checkPlain($source_array[1]) . '</span>',
);
];
$form['strings'][$string->lid]['original'] = [
$original_singular,
['#markup' => '<br>'],
$original_plural,
];
}
if (!empty($string->context)) {
$form['strings'][$string->lid]['context'] = array(
'#type' => 'value',
'#value' => '<span lang="en">' . String::checkPlain($string->context) . '</span>',
);
$form['strings'][$string->lid]['original'][] = [
'#type' => 'inline_template',
'#template' => '<br><small>{{ context_title }}: <span lang="en">{{ context }}</span></small>',
'#context' => [
'context_title' => $this->t('In Context'),
'context' => $string->context,
],
];
}
// Approximate the number of rows to use in the default textarea.
$rows = min(ceil(str_word_count($source_array[0]) / 12), 10);
if (empty($form['strings'][$string->lid]['plural']['#value'])) {
if (!$plural) {
$form['strings'][$string->lid]['translations'][0] = array(
'#type' => 'textarea',
'#title' => $this->t('Translated string (@language)', array('@language' => $langname)),
......@@ -153,6 +161,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
}
}
$form['pager']['#theme'] = 'pager';
return $form;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment