diff --git a/core/modules/config_translation/src/FormElement/PluralVariants.php b/core/modules/config_translation/src/FormElement/PluralVariants.php index e2989ea..0735a59 100644 --- a/core/modules/config_translation/src/FormElement/PluralVariants.php +++ b/core/modules/config_translation/src/FormElement/PluralVariants.php @@ -23,28 +23,28 @@ class PluralVariants extends FormElementBase { protected function getSourceElement(LanguageInterface $source_language, $source_config) { $plurals = $this->getNumberOfPlurals($source_language->getId()); $values = explode(LOCALE_PLURAL_DELIMITER, $source_config); - $environment = \Drupal::service('twig'); - $title_template = '{{ label }} {{ source_language }}'; - $title_context = array( - 'label' => $this->t($this->definition->getLabel()), - 'source_language' => $this->t('Source string (@language)', array('@language' => $source_language->getName())), - ); $element = array( '#type' => 'fieldset', - '#title' => $environment->renderInline($title_template, $title_context), + '#title' => $this->t($this->definition->getLabel()), '#tree' => TRUE, ); + $element['source_language'] = array( + '#type' => 'inline_template', + '#template' => '{{ source_language }}', + '#context' => array( + 'source_language' => $this->t('Source string (@language)', array('@language' => $source_language->getName())), + ), + ); for ($i = 0; $i < $plurals; $i++) { - $template = '{{ value }}'; - $context = array( - 'langcode' => $source_language->getId(), - 'value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'), - ); $element[$i] = array( - '#type' => 'item', - // @todo Should use better labels https://www.drupal.org/node/2499639 - '#title' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'), - '#markup' => $environment->renderInline($template, $context), + '#type' => 'inline_template', + '#template' => '
{{ value }}
', + '#context' => array( + // @todo Should use better labels https://www.drupal.org/node/2499639 + 'label' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'), + 'langcode' => $source_language->getId(), + 'value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'), + ), ); } return $element; @@ -56,17 +56,18 @@ protected function getSourceElement(LanguageInterface $source_language, $source_ protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) { $plurals = $this->getNumberOfPlurals($translation_language->getId()); $values = explode(LOCALE_PLURAL_DELIMITER, $translation_config); - $environment = \Drupal::service('twig'); - $title_template = '{{ label }} {{ translation_language }}'; - $title_context = array( - 'label' => $this->t($this->definition->getLabel()), - 'translation_language' => $this->t('Translated string (@language)', array('@language' => $translation_language->getName())), - ); $element = array( '#type' => 'fieldset', - '#title' => $environment->renderInline($title_template, $title_context), + '#title' => $this->t($this->definition->getLabel()), '#tree' => TRUE, ); + $element['translation_language'] = array( + '#type' => 'inline_template', + '#template' => '{{ translation_language }}', + '#context' => array( + 'translation_language' => $this->t('Translated string (@language)', array('@language' => $translation_language->getName())), + ), + ); for ($i = 0; $i < $plurals; $i++) { $element[$i] = array( '#type' => 'textfield', diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php index 5504cc0..8a437f0 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -35,8 +35,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { $langname = isset($langcode) ? $languages[$langcode]->getName() : "- None -"; - $environment = \Drupal::service('twig'); - $form['#attached']['library'][] = 'locale/drupal.locale.admin'; $form['langcode'] = array( @@ -61,8 +59,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { $plurals = $this->getNumberOfPlurals($langcode); - $value_template = '{{ value }}'; - foreach ($strings as $string) { // Cast into source string, will do for our purposes. $source = new SourceString($string); @@ -73,32 +69,26 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Add original string value and mark as non-plural. $plural = FALSE; $form['strings'][$string->lid]['original'] = array( - '#type' => 'item', - '#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), - '#title_display' => 'invisible', - '#markup' => $environment->renderInline($value_template, array('value' => $source_array[0])), + '#type' => 'inline_template', + '#template' => '{{ source_language }}{{ source_value }}', + '#context' => array( + 'source_language' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), + 'source_value' => $source_array[0], + ), ); } else { // Add original string value and mark as plural. $plural = TRUE; - $original_singular = [ - '#type' => 'item', - '#title' => $this->t('Singular form'), - '#markup' => $environment->renderInline($value_template, array('value' => $source_array[0])), - ]; - $original_plural = [ - '#type' => 'item', - '#title' => $this->t('Plural form'), - '#markup' => $environment->renderInline($value_template, array('value' => $source_array[1])), - ]; $form['strings'][$string->lid]['original'] = [ '#type' => 'inline_template', - '#template' => '{{ source_language }}{{ original_singular }}
{{ original_plural }}', + '#template' => '{{ source_language }}
{{ original_singular }}

{{ original_plural }}
', '#context' => array( 'source_language' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), - 'original_singular' => $original_singular, - 'original_plural' => $original_plural, + 'singular_label' => $this->t('Singular form'), + 'plural_label' => $this->t('Plural form'), + 'original_singular' => $source_array[0], + 'original_plural' => $source_array[1], ), ]; } @@ -112,13 +102,20 @@ public function buildForm(array $form, FormStateInterface $form_state) { ], ]; } + + $form['strings'][$string->lid]['translations'] = array( + '#type' => 'inline_template', + '#template' => '{{ translation_language }}', + '#context' => array( + 'translation_language' => $this->t('Translated string (@language)', array('@language' => $langname)), + ), + ); + // Approximate the number of rows to use in the default textarea. $rows = min(ceil(str_word_count($source_array[0]) / 12), 10); if (!$plural) { $form['strings'][$string->lid]['translations'][0] = array( '#type' => 'textarea', - '#title' => $this->t('Translated string (@language)', array('@language' => $langname)), - '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode), @@ -127,10 +124,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { else { // Add a textarea for each plural variant. for ($i = 0; $i < $plurals; $i++) { - $prefix_template = '{{ translation_language }}'; - $prefix_context = array( - 'translation_language' => $this->t('Translated string (@language)', array('@language' => $langname)), - ); $form['strings'][$string->lid]['translations'][$i] = array( '#type' => 'textarea', // @todo Should use better labels https://www.drupal.org/node/2499639 @@ -138,7 +131,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', '#attributes' => array('lang' => $langcode), - '#prefix' => $i == 0 ? $environment->renderInline($prefix_template, $prefix_context) : '', ); } if ($plurals == 2) {