protected function LocaleSource::updateTranslation in Translation Management Tool 8
Updates translation associated to a specific locale source.
Parameters
string $lid: The Locale ID.
string $target_language: Target language to update translation.
string $translation: Translation value.
Return value
bool Success or not updating the locale translation.
1 call to LocaleSource::updateTranslation()
- LocaleSource::saveTranslation in sources/
locale/ src/ Plugin/ tmgmt/ Source/ LocaleSource.php - Saves a translation.
File
- sources/
locale/ src/ Plugin/ tmgmt/ Source/ LocaleSource.php, line 42
Class
- LocaleSource
- Translation Source plugin for locale strings.
Namespace
Drupal\tmgmt_locale\Plugin\tmgmt\SourceCode
protected function updateTranslation($lid, $target_language, $translation) {
$languages = locale_translatable_language_list('name', TRUE);
if (!$lid || !array_key_exists($target_language, $languages) || !$translation) {
return FALSE;
}
$exists = \Drupal::database()
->query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(
':lid' => $lid,
':language' => $target_language,
))
->fetchField();
// @todo Only singular strings are managed here, we should take care of
// plural information of processed string.
if (!$exists) {
$fields = array(
'lid' => $lid,
'language' => $target_language,
'translation' => $translation,
'customized' => LOCALE_CUSTOMIZED,
);
\Drupal::database()
->insert('locales_target')
->fields($fields)
->execute();
}
else {
$fields = array(
'translation' => $translation,
'customized' => LOCALE_CUSTOMIZED,
);
\Drupal::database()
->update('locales_target')
->fields($fields)
->condition('lid', $lid)
->condition('language', $target_language)
->execute();
}
// Clear locale caches.
_locale_invalidate_js($target_language);
\Drupal::cache()
->delete('locale:' . $target_language);
return TRUE;
}