function LocaleUpdateBase::assertTranslation

Same name in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::assertTranslation()
  2. 8.9.x core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::assertTranslation()
  3. 10 core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::assertTranslation()

Checks the translation of a string.

Parameters

string $source: Translation source string.

string $translation: Translation to check. Use empty string to check for a non-existent translation.

string $langcode: Language code of the language to translate to.

string $message: (optional) A message to display with the assertion.

3 calls to LocaleUpdateBase::assertTranslation()
LocaleUpdateTest::testEnableLanguage in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests automatic translation import when a language is added.
LocaleUpdateTest::testEnableUninstallModule in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests automatic translation import when a module is enabled.
LocaleUpdateTest::testUpdateImportModeNone in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests translation import and don't overwrite any translation.

File

core/modules/locale/tests/src/Functional/LocaleUpdateBase.php, line 308

Class

LocaleUpdateBase
Base class for testing updates to string translations.

Namespace

Drupal\Tests\locale\Functional

Code

protected function assertTranslation($source, $translation, $langcode, $message = '') {
    $query = Database::getConnection()->select('locales_target', 'lt');
    $query->innerJoin('locales_source', 'ls', '[ls].[lid] = [lt].[lid]');
    $db_translation = $query->fields('lt', [
        'translation',
    ])
        ->condition('ls.source', $source)
        ->condition('lt.language', $langcode)
        ->execute()
        ->fetchField();
    $db_translation = $db_translation == FALSE ? '' : $db_translation;
    $this->assertEquals($translation, $db_translation, $message ?: "Correct translation of {$source} ({$langcode})");
}

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