function tmgmt_i18n_string_get_wrapper in Translation Management Tool 7
Returns the i18n wrapper object.
I18N objects with one or two keys are supported.
Parameters
string $type: I18n object type.
object $i18n_string: Object with type and objectid properties.
Return value
i18n_string_object_wrapper
2 calls to tmgmt_i18n_string_get_wrapper()
- TMGMTI18nStringDefaultSourceUIController::getTranslationData in sources/
i18n_string/ tmgmt_i18n_string.ui.inc - Helper function to create translation data list for the sources page list.
- TMGMTI18nStringSourcePluginController::getI18nObjectWrapper in sources/
i18n_string/ tmgmt_i18n_string.plugin.inc - Helper function to get i18n_object_wrapper for given job item.
File
- sources/
i18n_string/ tmgmt_i18n_string.module, line 236 - Source plugin for the Translation Management system that handles i18n strings.
Code
function tmgmt_i18n_string_get_wrapper($type, $i18n_string) {
$object_key = i18n_object_info($type, 'key');
// Special handling for i18nviews.
if ($type == 'views') {
// The construct method needs the full view object.
$view = views_get_view($i18n_string->objectid);
$wrapper = i18n_get_object($type, $i18n_string->objectid, $view);
return $wrapper;
}
// Special handling for i18n_panels.
$panels_objects = array(
'pane_configuration' => 'panels_pane',
'display_configuration' => 'panels_display',
);
if (in_array($type, array_keys($panels_objects))) {
ctools_include('export');
$wrapper = FALSE;
switch ($type) {
case 'display_configuration':
$object_array = ctools_export_load_object($panels_objects[$type], 'conditions', array(
'uuid' => $i18n_string->objectid,
));
$wrapper = i18n_get_object($type, $i18n_string->objectid, $object_array[$i18n_string->objectid]);
break;
case 'pane_configuration':
$obj = db_query("SELECT * FROM {panels_pane} WHERE uuid = :uuid", array(
':uuid' => $i18n_string->objectid,
))
->fetchObject();
if ($obj) {
$pane = ctools_export_unpack_object($panels_objects[$type], $obj);
$translation = i18n_panels_get_i18n_translation_object($pane);
$translation->uuid = $pane->uuid;
$wrapper = i18n_get_object($type, $i18n_string->objectid, $translation);
}
break;
default:
break;
}
return $wrapper;
}
// Special handling if the object has two keys. Assume that they
// mean type and object id.
if ($type == 'field') {
// Special case for fields which expect the type to be the identifier.
$wrapper = i18n_get_object($type, $i18n_string->type);
return $wrapper;
}
elseif ($type == 'field_instance') {
// Special case for field instances, which use the field name as type and
// bundle as object id. We don't know the entity_type, so we loop over all
// entity_types to search for the bundle. This will clash if different
// entity types have bundles with the same names.
foreach (entity_get_info() as $entity_type => $entity_info) {
if (isset($entity_info['bundles'][$i18n_string->objectid])) {
list($type_key, $objectid_key) = $object_key;
$wrapper = i18n_get_object($type, array(
$type_key => $i18n_string->type,
$objectid_key => $i18n_string->objectid,
), field_info_instance($entity_type, $i18n_string->type, $i18n_string->objectid));
return $wrapper;
}
}
}
elseif (count($object_key) == 2) {
list($type_key, $objectid_key) = $object_key;
$wrapper = i18n_get_object($type, array(
$type_key => $i18n_string->type,
$objectid_key => $i18n_string->objectid,
));
return $wrapper;
}
else {
// Otherwise, use the object id.
$wrapper = i18n_get_object($type, $i18n_string->objectid);
return $wrapper;
}
}