Loads translation data into the given entities.
array $entities: The entities keyed by entity ID.
string $entity_type: The type of the entities.
function translation_entity_load_translation_metadata(array $entities, $entity_type) {
$query = 'SELECT * FROM {translation_entity} te WHERE te.entity_type = :entity_type AND te.entity_id IN (:entity_id)';
$result = db_query($query, array(
':entity_type' => $entity_type,
':entity_id' => array_keys($entities),
));
$exclude = array(
'entity_type',
'entity_id',
'langcode',
);
foreach ($result as $record) {
$entity = $entities[$record->entity_id];
// @todo Declare these as entity (translation?) properties.
foreach ($record as $field_name => $value) {
if (!in_array($field_name, $exclude)) {
$entity->translation[$record->langcode][$field_name] = $value;
}
}
}
}