function ConfigTranslationUiTest::testPluralConfigStrings
Same name in other branches
- 8.9.x core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStrings()
- 10 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStrings()
- 11.x core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testPluralConfigStrings()
Tests translation of plural strings with multiple plural forms in config.
File
-
core/
modules/ config_translation/ tests/ src/ Functional/ ConfigTranslationUiTest.php, line 697
Class
- ConfigTranslationUiTest
- Translate settings and entities to various languages.
Namespace
Drupal\Tests\config_translation\FunctionalCode
public function testPluralConfigStrings() {
$this->drupalLogin($this->adminUser);
// First import a .po file with multiple plural forms.
// This will also automatically add the 'sl' language.
$name = \Drupal::service('file_system')->tempnam('temporary://', "sl_") . '.po';
file_put_contents($name, $this->getPoFile(4));
$this->drupalGet('admin/config/regional/translate/import');
$this->submitForm([
'langcode' => 'sl',
'files[file]' => $name,
], 'Import');
// Translate the files view, as this one uses numeric formatters.
$description = 'Singular form';
$field_value = '1 place';
$field_value_plural = '@count places';
$translation_url = 'admin/structure/views/view/files/translate/sl/add';
$this->drupalGet($translation_url);
// Make sure original text is present on this page, in addition to 2 new
// empty fields.
$this->assertSession()
->pageTextContains($description);
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', $field_value);
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', $field_value_plural);
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', '');
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', '');
// Then make sure it also works.
$edit = [
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]' => $field_value . ' SL',
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]' => $field_value_plural . ' 1 SL',
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]' => $field_value_plural . ' 2 SL',
'translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]' => $field_value_plural . ' 3 SL',
];
$this->drupalGet($translation_url);
$this->submitForm($edit, 'Save translation');
// Make sure the values have changed.
$this->drupalGet($translation_url);
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][0]', "{$field_value} SL");
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][1]', "{$field_value_plural} 1 SL");
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][2]', "{$field_value_plural} 2 SL");
$this->assertSession()
->fieldValueEquals('translation[config_names][views.view.files][display][default][display_options][fields][count][format_plural_string][3]', "{$field_value_plural} 3 SL");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.