protected function LocaleUpdateBase::setCurrentTranslations in Drupal 10
Same name and namespace in other branches
- 8 core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::setCurrentTranslations()
- 9 core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::setCurrentTranslations()
Setup existing translations in the database and set up the status of existing translations.
File
- core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateBase.php, line 215
Class
- LocaleUpdateBase
- Base class for testing updates to string translations.
Namespace
Drupal\Tests\locale\FunctionalCode
protected function setCurrentTranslations() {
// Add non customized translations to the database.
$langcode = 'de';
$context = '';
$non_customized_translations = [
'March' => 'Marz',
'June' => 'Juni',
];
foreach ($non_customized_translations as $source => $translation) {
$string = $this->container
->get('locale.storage')
->createString([
'source' => $source,
'context' => $context,
])
->save();
$this->container
->get('locale.storage')
->createTranslation([
'lid' => $string
->getId(),
'language' => $langcode,
'translation' => $translation,
'customized' => LOCALE_NOT_CUSTOMIZED,
])
->save();
}
// Add customized translations to the database.
$customized_translations = [
'January' => 'Januar_customized',
'February' => 'Februar_customized',
'May' => 'Mai_customized',
];
foreach ($customized_translations as $source => $translation) {
$string = $this->container
->get('locale.storage')
->createString([
'source' => $source,
'context' => $context,
])
->save();
$this->container
->get('locale.storage')
->createTranslation([
'lid' => $string
->getId(),
'language' => $langcode,
'translation' => $translation,
'customized' => LOCALE_CUSTOMIZED,
])
->save();
}
// Add a state of current translations in locale_files.
$default = [
'langcode' => $langcode,
'uri' => '',
'timestamp' => $this->timestampMedium,
'last_checked' => $this->timestampMedium,
];
$data[] = [
'project' => 'contrib_module_one',
'filename' => 'contrib_module_one-8.x-1.1.de._po',
'version' => '8.x-1.1',
];
$data[] = [
'project' => 'contrib_module_two',
'filename' => 'contrib_module_two-8.x-2.0-beta4.de._po',
'version' => '8.x-2.0-beta4',
];
$data[] = [
'project' => 'contrib_module_three',
'filename' => 'contrib_module_three-8.x-1.0.de._po',
'version' => '8.x-1.0',
];
$data[] = [
'project' => 'custom_module_one',
'filename' => 'custom_module_one.de.po',
'version' => '',
];
$connection = Database::getConnection();
foreach ($data as $file) {
$file = array_merge($default, $file);
$connection
->insert('locale_file')
->fields($file)
->execute();
}
}