diff --git a/core/modules/config_translation/src/FormElement/PluralVariants.php b/core/modules/config_translation/src/FormElement/PluralVariants.php index ec6b977..9a2b32f 100644 --- a/core/modules/config_translation/src/FormElement/PluralVariants.php +++ b/core/modules/config_translation/src/FormElement/PluralVariants.php @@ -23,6 +23,7 @@ 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); + $labels = locale_get_plural_form_labels($source_language->getId()); $element = array( '#type' => 'fieldset', '#title' => SafeMarkup::format('@label (@source_language)', array( @@ -35,7 +36,7 @@ protected function getSourceElement(LanguageInterface $source_language, $source_ $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'), + '#title' => $labels[$i], '#markup' => SafeMarkup::format('@value', array( '@langcode' => $source_language->getId(), '@value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'), @@ -51,6 +52,7 @@ 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); + $labels = locale_get_plural_form_labels($translation_language->getId()); $element = array( '#type' => 'fieldset', '#title' => SafeMarkup::format('@label (@translation_language)', array( @@ -63,7 +65,7 @@ protected function getTranslationElement(LanguageInterface $translation_language $element[$i] = array( '#type' => 'textfield', // @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'), + '#title' => $labels[$i], '#default_value' => isset($values[$i]) ? $values[$i] : '', '#attributes' => array('lang' => $translation_language->getId()), ); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 99b7e34..7413928 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -1378,3 +1378,149 @@ function locale_translation_language_table($form_element) { } return $form_element; } + +function locale_get_plural_form_labels($langcode) { + switch ($langcode) { + // One plural form + case 'bo': + case 'kk': + case 'ky': + case 'lo': + case 'rhg': + case 'tr': + case 'ug': + case 'vi': + return array( + t('Singular and plural form'), + ); + break; + + // Two plural forms (exceptions) + case 'jv': + return array( + t('Form for 0'), + t('Form for other numbers'), + ); + break; + case 'mk': + return array( + t('Form for numbers ending with 1'), + t('Form for other numbers'), + ); + break; + + // Three plural forms + case 'be': + case 'bs': + case 'cs': + case 'hr': + case 'ru': + case 'sr': + case 'uk': + return array( + t('Form for numbers ending with 1 (except 11, 111, 211, etc.)'), + t('Form for numbers ending with 2-4 (except 12-14, 112-114, 212-214, etc.)'), + t('Form for numbers ending with 5-9 (and 0, 10-20, 110-120, 210-220, etc.)'), + ); + break; + case 'lt': + return array( + t('Form for numbers ending with 1 (except 11, 111, 211, etc.)'), + t('Form for numbers ending with 2-9 (except 12-19, 112-119, 212-219, etc.)'), + t('Form for 10-20, 110-120, 210-220, etc.'), + ); + break; + case 'lv': + return array( + t('Form for numbers ending with 1 (except 11, 111, 211, etc.)'), + t('Form for other numbers (except 0)'), + t('Form for 0'), + ); + break; + case 'pl': + return array( + t('Singular form'), + t('Form for numbers ending with 2-4 (except 12-14, 112-114, 212-214, etc.)'), + t('Form for other numbers'), + ); + break; + case 'ro': + return array( + t('Singular form'), + t('Form for 0, 2-19, 101-119, 201-219, etc.'), + t('Form for other numbers'), + ); + break; + case 'sk': + return array( + t('Singular form'), + t('Form for 2-4'), + t('Form for 5 and more'), + ); + break; + + // Four plural forms + case 'cy': + return array( + t('Singular form'), + t('Form for 2'), + t('Form for 3 and more (except 8 and 11)'), + t('Form for 8 and 11'), + ); + break; + case 'gd': + return array( + t('Form for 1 and 11'), + t('Form for 2 and 12'), + t('Form for 3-19 (except 11 and 12)'), + t('Form for 20 and more'), + ); + break; + case 'mt': + return array( + t('Singular form'), + t('Form for 0, 2-10, 102-110, 202-210, etc.'), + t('Form for 11-19, 111-119, 211-219, etc.'), + t('Form for 20-101, 120-201, 220-301, etc.'), + ); + break; + case 'sl': + return array( + t('Form for 1, 101, 201, etc.'), + t('Form for 2, 102, 202, etc.'), + t('Form for 3, 4, 103, 104, 203, 204, etc.'), + t('Form for other numbers'), + ); + break; + + // Five plural forms + case 'ga': + return array( + t('Singular form'), + t('Form for 2'), + t('Form for 3-6'), + t('Form for 7-10'), + t('Form for 11 and more'), + ); + break; + + // Six plural forms + case 'ar': + return array( + t('Singular form'), + t('Form for 0'), + t('Form for 2'), + t('Form for 3-10, 103-110, 203-210, etc.'), + t('Form for 11-99, 111-199, 211-299, etc.'), + t('Form for 100-102, 200-202, etc.'), + ); + break; + + // Two plural forms (default) + default: + return array( + t('Singular form'), + t('Plural form'), + ); + } +} diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php index bac65c7..440198f 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -60,6 +60,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { $plurals = $this->getNumberOfPlurals($langcode); + $labels = locale_get_plural_form_labels($langcode); + foreach ($strings as $string) { // Cast into source string, will do for our purposes. $source = new SourceString($string); @@ -124,7 +126,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['strings'][$string->lid]['translations'][$i] = array( '#type' => 'textarea', // @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')), + '#title' => $labels[$i], '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', '#attributes' => array('lang' => $langcode), diff --git a/core/modules/views/src/Plugin/views/field/NumericField.php b/core/modules/views/src/Plugin/views/field/NumericField.php index 999a648..b7b2362 100644 --- a/core/modules/views/src/Plugin/views/field/NumericField.php +++ b/core/modules/views/src/Plugin/views/field/NumericField.php @@ -99,11 +99,12 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $plural_array = explode(LOCALE_PLURAL_DELIMITER, $this->options['format_plural_string']); $plurals = $this->getNumberOfPlurals($this->view->storage->get('langcode')); + $labels = locale_get_plural_form_labels($this->view->storage->get('langcode')); for ($i = 0; $i < $plurals; $i++) { $form['format_plural_values'][$i] = array( '#type' => 'textfield', // @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')), + '#title' => $labels[$i], '#default_value' => isset($plural_array[$i]) ? $plural_array[$i] : '', '#description' => $this->t('Text to use for this variant, @count will be replaced with the value.'), '#states' => array(