function LocaleImportFunctionalTest::testLanguageContext

Same name and namespace in other branches
  1. 7.x modules/locale/locale.test \LocaleImportFunctionalTest::testLanguageContext()
  2. 9 core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php \Drupal\Tests\locale\Functional\LocaleImportFunctionalTest::testLanguageContext()
  3. 8.9.x core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php \Drupal\Tests\locale\Functional\LocaleImportFunctionalTest::testLanguageContext()
  4. 11.x 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 257

Class

LocaleImportFunctionalTest
Tests the import of locale files.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLanguageContext() : void {
  // 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.');
}

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