You are here

public function LocaleImportFunctionalTest::importPoFile in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php \Drupal\Tests\locale\Functional\LocaleImportFunctionalTest::importPoFile()
  2. 9 core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php \Drupal\Tests\locale\Functional\LocaleImportFunctionalTest::importPoFile()

Helper function: import a standalone .po file in a given language.

Parameters

string $contents: Contents of the .po file to import.

array $options: (optional) Additional options to pass to the translation import form.

File

core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php, line 404

Class

LocaleImportFunctionalTest
Tests the import of locale files.

Namespace

Drupal\Tests\locale\Functional

Code

public function importPoFile($contents, array $options = []) {
  $file_system = \Drupal::service('file_system');
  $name = $file_system
    ->tempnam('temporary://', "po_") . '.po';
  file_put_contents($name, $contents);
  $options['files[file]'] = $name;
  $this
    ->drupalGet('admin/config/regional/translate/import');
  $this
    ->submitForm($options, 'Import');
  $file_system
    ->unlink($name);
}