protected function LocaleSource::getLocaleObject in Translation Management Tool 8
Helper function to obtain a locale object for given job item.
Parameters
\Drupal\tmgmt\JobItemInterface $job_item:
Return value
locale object
2 calls to LocaleSource::getLocaleObject()
- LocaleSource::getData in sources/
locale/ src/ Plugin/ tmgmt/ Source/ LocaleSource.php - Returns an array with the data structured for translation.
- LocaleSource::getLabel in sources/
locale/ src/ Plugin/ tmgmt/ Source/ LocaleSource.php - Return a title for this job item.
File
- sources/
locale/ src/ Plugin/ tmgmt/ Source/ LocaleSource.php, line 93
Class
- LocaleSource
- Translation Source plugin for locale strings.
Namespace
Drupal\tmgmt_locale\Plugin\tmgmt\SourceCode
protected function getLocaleObject(JobItemInterface $job_item) {
$locale_lid = $job_item
->getItemId();
// Check existence of assigned lid.
$exists = \Drupal::database()
->query("SELECT COUNT(lid) FROM {locales_source} WHERE lid = :lid", array(
':lid' => $locale_lid,
))
->fetchField();
if (!$exists) {
throw new TMGMTException(t('Unable to load locale with id %id', array(
'%id' => $job_item
->getItemId(),
)));
}
// This is necessary as the method is also used in the getLabel() callback
// and for that case the job is not available in the cart.
if ($job_item
->getJobId()) {
$source_language = $job_item
->getJob()
->getSourceLangcode();
}
else {
$source_language = $job_item
->getSourceLangCode();
}
if ($source_language == 'en') {
$query = \Drupal::database()
->select('locales_source', 'ls');
$query
->fields('ls')
->condition('ls.lid', $locale_lid);
$locale_object = $query
->execute()
->fetchObject();
$locale_object->language = 'en';
if (empty($locale_object)) {
return NULL;
}
$locale_object->origin = 'source';
}
else {
$query = \Drupal::database()
->select('locales_target', 'lt');
$query
->join('locales_source', 'ls', 'ls.lid = lt.lid');
$query
->fields('lt')
->fields('ls')
->condition('lt.lid', $locale_lid)
->condition('lt.language', $source_language);
$locale_object = $query
->execute()
->fetchObject();
if (empty($locale_object)) {
return NULL;
}
$locale_object->origin = 'target';
}
return $locale_object;
}