function TwigTransTest::installLanguages
Same name in other branches
- 9 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()
- 11.x 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 199
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->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');
// 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->drupalPostForm('admin/config/regional/translate/import', $options, t('Import'));
$file_system->unlink($filename);
}
}
$this->container
->get('language_manager')
->reset();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.