protected function TMGMTLocaleSourcePluginController::getLocaleObject in Translation Management Tool 7
Helper function to obtain a locale object for given job item.
Parameters
TMGMTJobItem $job_item:
Return value
locale object
2 calls to TMGMTLocaleSourcePluginController::getLocaleObject()
- TMGMTLocaleSourcePluginController::getData in sources/
locale/ tmgmt_locale.plugin.inc - Returns an array with the data structured for translation.
- TMGMTLocaleSourcePluginController::getLabel in sources/
locale/ tmgmt_locale.plugin.inc - Return a title for this job item.
File
- sources/
locale/ tmgmt_locale.plugin.inc, line 77 - Provides the locale source controller.
Class
- TMGMTLocaleSourcePluginController
- Translation plugin controller for locale strings.
Code
protected function getLocaleObject(TMGMTJobItem $job_item) {
$locale_lid = $job_item->item_id;
// Check existence of assigned lid.
$exists = db_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->item_id,
)));
}
// 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 (!empty($job_item->tjid)) {
$source_language = $job_item
->getJob()->source_language;
}
else {
$source_language = $job_item
->getSourceLangCode();
}
if ($source_language == 'en') {
$query = db_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 = db_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;
}