private function LocaleUpdateTest::setCurrentTranslations

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

5 calls to LocaleUpdateTest::setCurrentTranslations()
LocaleUpdateTest::testUpdateImportModeNonCustomized in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
Tests translation import with a translations directory and only overwrite non-customized translations.
LocaleUpdateTest::testUpdateImportModeNone in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
Tests translation import with a translations directory and don't overwrite any translation.
LocaleUpdateTest::testUpdateImportSourceLocal in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
Tests translation import from local sources.
LocaleUpdateTest::testUpdateImportSourceRemote in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
Tests translation import from remote sources.
LocaleUpdateTest::testUpdateImportWithoutDirectory in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
Tests translation import without a translations directory.

File

drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php, line 220
Contains Drupal\locale\Tests\LocaleUpdateTest.

Class

LocaleUpdateTest
Tests for update translations.

Namespace

Drupal\locale\Tests

Code

private 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();
    $target = $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();
    $target = $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->timestamp_medium,
    'last_checked' => $this->timestamp_medium,
  );
  $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 = (object) array_merge($default, $file);
    drupal_write_record('locale_file', $file);
  }
}