function LocalePluralFormatTest::importPoFile

Same name and namespace in other branches
  1. 7.x modules/locale/locale.test \LocalePluralFormatTest::importPoFile()
  2. 9 core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php \Drupal\Tests\locale\Functional\LocalePluralFormatTest::importPoFile()
  3. 8.9.x core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php \Drupal\Tests\locale\Functional\LocalePluralFormatTest::importPoFile()
  4. 10 core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php \Drupal\Tests\locale\Functional\LocalePluralFormatTest::importPoFile()

Imports a standalone .po file in a given language.

Parameters

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

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

3 calls to LocalePluralFormatTest::importPoFile()
LocalePluralFormatTest::testGetPluralFormat in core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php
Tests locale_get_plural() and \Drupal::translation()->formatPlural().
LocalePluralFormatTest::testPluralEditDateFormatter in core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php
Tests plural editing of DateFormatter strings.
LocalePluralFormatTest::testPluralEditExport in core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php
Tests plural editing and export functionality.

File

core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php, line 390

Class

LocalePluralFormatTest
Tests plural handling for various languages.

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.