You are here

protected function LocaleUpdateBase::setCurrentTranslations in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/src/Tests/LocaleUpdateBase.php \Drupal\locale\Tests\LocaleUpdateBase::setCurrentTranslations()

Setup existing translations in the database and set up the status of existing translations.

4 calls to LocaleUpdateBase::setCurrentTranslations()
LocaleUpdateTest::testUpdateImportModeNonCustomized in core/modules/locale/src/Tests/LocaleUpdateTest.php
Tests translation import and only overwrite non-customized translations.
LocaleUpdateTest::testUpdateImportModeNone in core/modules/locale/src/Tests/LocaleUpdateTest.php
Tests translation import and don't overwrite any translation.
LocaleUpdateTest::testUpdateImportSourceLocal in core/modules/locale/src/Tests/LocaleUpdateTest.php
Tests translation import from local sources.
LocaleUpdateTest::testUpdateImportSourceRemote in core/modules/locale/src/Tests/LocaleUpdateTest.php
Tests translation import from remote sources.

File

core/modules/locale/src/Tests/LocaleUpdateBase.php, line 215
Contains \Drupal\locale\Tests\LocaleUpdateBase.

Class

LocaleUpdateBase
Base class for testing updates to string translations.

Namespace

Drupal\locale\Tests

Code

protected function setCurrentTranslations() {

  // Add non customized translations to the database.
  $langcode = 'de';
  $context = '';
  $non_customized_translations = array(
    'March' => 'Marz',
    'June' => 'Juni',
  );
  foreach ($non_customized_translations as $source => $translation) {
    $string = $this->container
      ->get('locale.storage')
      ->createString(array(
      'source' => $source,
      'context' => $context,
    ))
      ->save();
    $this->container
      ->get('locale.storage')
      ->createTranslation(array(
      'lid' => $string
        ->getId(),
      'language' => $langcode,
      'translation' => $translation,
      'customized' => LOCALE_NOT_CUSTOMIZED,
    ))
      ->save();
  }

  // Add customized translations to the database.
  $customized_translations = array(
    'January' => 'Januar_customized',
    'February' => 'Februar_customized',
    'May' => 'Mai_customized',
  );
  foreach ($customized_translations as $source => $translation) {
    $string = $this->container
      ->get('locale.storage')
      ->createString(array(
      'source' => $source,
      'context' => $context,
    ))
      ->save();
    $this->container
      ->get('locale.storage')
      ->createTranslation(array(
      'lid' => $string
        ->getId(),
      'language' => $langcode,
      'translation' => $translation,
      'customized' => LOCALE_CUSTOMIZED,
    ))
      ->save();
  }

  // Add a state of current translations in locale_files.
  $default = array(
    'langcode' => $langcode,
    'uri' => '',
    'timestamp' => $this->timestampMedium,
    'last_checked' => $this->timestampMedium,
  );
  $data[] = array(
    'project' => 'contrib_module_one',
    'filename' => 'contrib_module_one-8.x-1.1.de._po',
    'version' => '8.x-1.1',
  );
  $data[] = array(
    'project' => 'contrib_module_two',
    'filename' => 'contrib_module_two-8.x-2.0-beta4.de._po',
    'version' => '8.x-2.0-beta4',
  );
  $data[] = array(
    'project' => 'contrib_module_three',
    'filename' => 'contrib_module_three-8.x-1.0.de._po',
    'version' => '8.x-1.0',
  );
  $data[] = array(
    'project' => 'custom_module_one',
    'filename' => 'custom_module_one.de.po',
    'version' => '',
  );
  foreach ($data as $file) {
    $file = array_merge($default, $file);
    db_insert('locale_file')
      ->fields($file)
      ->execute();
  }
}