protected function TwigTransTest::installLanguages in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::installLanguages()
- 10 core/modules/system/tests/src/Functional/Theme/TwigTransTest.php \Drupal\Tests\system\Functional\Theme\TwigTransTest::installLanguages()
Helper function: install languages.
1 call to TwigTransTest::installLanguages()
- TwigTransTest::setUp in core/
modules/ system/ tests/ src/ Functional/ Theme/ TwigTransTest.php
File
- core/
modules/ system/ tests/ src/ Functional/ Theme/ TwigTransTest.php, line 186
Class
- TwigTransTest
- Tests Twig "trans" tags.
Namespace
Drupal\Tests\system\Functional\ThemeCode
protected function installLanguages() {
$file_system = \Drupal::service('file_system');
foreach ($this->languages as $langcode => $name) {
// Generate custom .po contents for the language.
$contents = $this
->poFileContents($langcode);
if ($contents) {
// Add test language for translation testing.
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
// Install the language in Drupal.
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add custom language');
$this
->assertSession()
->responseContains('"edit-languages-' . $langcode . '-weight"');
// Import the custom .po contents for the language.
$filename = $file_system
->tempnam('temporary://', "po_") . '.po';
file_put_contents($filename, $contents);
$options = [
'files[file]' => $filename,
'langcode' => $langcode,
'customized' => TRUE,
];
$this
->drupalGet('admin/config/regional/translate/import');
$this
->submitForm($options, 'Import');
$file_system
->unlink($filename);
}
}
$this->container
->get('language_manager')
->reset();
}