You are here

protected function WebTestBase::addCustomTranslations in Drupal 8

Queues custom translations to be written to settings.php.

Use WebTestBase::writeCustomTranslations() to apply and write the queued translations.

Parameters

string $langcode: The langcode to add translations for.

array $values: Array of values containing the untranslated string and its translation. For example:

array(
  '' => array(
    'Sunday' => 'domingo',
  ),
  'Long month name' => array(
    'March' => 'marzo',
  ),
);

Pass an empty array to remove all existing custom translations for the given $langcode.

File

core/modules/simpletest/src/WebTestBase.php, line 454

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function addCustomTranslations($langcode, array $values) {

  // If $values is empty, then the test expects all custom translations to be
  // cleared.
  if (empty($values)) {
    $this->customTranslations[$langcode] = [];
  }
  else {
    foreach ($values as $context => $translations) {
      foreach ($translations as $original => $translation) {
        $this->customTranslations[$langcode][$context][$original] = $translation;
      }
    }
  }
}