You are here

public function LocaleImportFunctionalTest::testLanguageContext in Drupal 9

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

Tests msgctxt context support.

File

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

Class

LocaleImportFunctionalTest
Tests the import of locale files.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLanguageContext() {

  // Try importing a .po file.
  $this
    ->importPoFile($this
    ->getPoFileWithContext(), [
    'langcode' => 'hr',
  ]);

  // We cast the return value of t() to string so as to retrieve the
  // translated value, rendered as a string.
  $this
    ->assertSame('Svibanj', (string) t('May', [], [
    'langcode' => 'hr',
    'context' => 'Long month name',
  ]), 'Long month name context is working.');
  $this
    ->assertSame('Svi.', (string) t('May', [], [
    'langcode' => 'hr',
  ]), 'Default context is working.');
}