// Languages to test, with various number of plural forms.
$languages =
[ 'vi' =>
['plurals' => 1, 'expected' =>
[TRUE, FALSE, FALSE, FALSE
]],
'fr' =>
['plurals' => 2, 'expected' =>
[TRUE, TRUE, FALSE, FALSE
]],
'sl' =>
['plurals' => 4, 'expected' =>
[TRUE, TRUE, TRUE, TRUE
]],
];
foreach ($languages as $langcode =>
$data) { // Import a .po file to add a new language with a given number of plural forms
$name = \Drupal::
service('file_system'
)->
tempnam('temporary://',
$langcode . '_'
) . '.po';
file_put_contents($name,
$this->
getPoFile($data['plurals'
]));
$this->
drupalGet('admin/config/regional/translate/import'
);
$this->
submitForm([ 'langcode' =>
$langcode,
'files[file]' =>
$name,
], 'Import'
);
// Change the config langcode of the 'files' view.
$config = \Drupal::
service('config.factory'
)->
getEditable('views.view.files'
);
$config->
set('langcode',
$langcode);
$config->
save();