' . t('Supports translation for views strings: title, header, footer...') . '
'; $output .= '' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '
'; return $output; } } /** * Implementation of hook_locale(). */ function i18nviews_locale($op = 'groups', $group = NULL) { switch ($op) { case 'groups': return array('views' => t('Views')); case 'refresh': if ($group == 'views') { return i18nviews_locale_refresh(); } } } /** * Refresh views locales */ function i18nviews_locale_refresh() { // To be implemented } /** * Implementation of hook_views_pre_view(). * * Views are identified by $view->name * * @TODO This needs a lot of research and work * @TODO Ask Earl */ function i18nviews_views_pre_view(&$view, &$display_id, &$args) { // Translate all possible display strings, step by step // I.e. for a page, there seems to be a 'page' and a 'default' display $fields = array('title', 'header', 'footer', 'empty'); foreach (array($display_id, 'default') as $display) { if (!empty($view->display[$display])) { _i18nviews_localize_array($view->name, $display, $view->display[$display]->handler->options, $fields, TRUE); } } // Translate taxonomy fields // @todo I don think this works at all if (module_exists('i18ntaxonomy') && is_array($view->field)) { $translate = variable_get('i18ntaxonomy_vocabularies', array()); foreach ($view->field as $index => $data) { $matches = array(); if($data['id'] == 'term_node.name') { // That's a full taxonomy box $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; } elseif(preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { $vid = $matches[1]; if ($translate[$vid]) { // Set new handler for this field $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; } } } } } /** * Translate a group of fields * * We get the translated fields out of the array so they are not translated again. */ function _i18nviews_localize_array($name, $group, &$data, &$field_names, $trim = FALSE) { $translated = array(); foreach ($field_names as $field) { if (!empty($data[$field])) { $data[$field] = tt("views:$name:$group:$field", $data[$field]); $translated[] = $field; } } if ($trim && $translated) { $field_names = array_diff($field_names, $translated); } } /** * Translate a group of fields for an object. * * We cannot play with object 2 array conversion because some are real typed objects. */ function _i18nviews_localize_object($name, $group, &$data, &$field_names, $trim = FALSE) { $translated = array(); foreach ($field_names as $field) { if (!empty($data->$field)) { $data->$field = tt("views:$name:$group:$field", $data->$field); } } if ($trim && $translated) { $field_names = array_diff($field_names, $translated); } } /** * Field handler for taxonomy term fields * * Remake of views_handler_field_allterms with term name translation */ function i18ntaxonomy_views_handler_field_allterms($fieldinfo, $fielddata, $value, $data) { if ($fieldinfo['vocabulary']) { $terms = taxonomy_node_get_terms_by_vocabulary($data->nid, $fieldinfo['vocabulary']); } else { $terms = taxonomy_node_get_terms($data->nid); } // Translate all these terms _i18ntaxonomy_translate_terms($terms); if ($fielddata['options'] == 'nolink') { foreach ($terms as $term) { $links[] = check_plain($term->name); } $links = !empty($links) ? implode(' | ', $links) : ''; } else { $node = new stdClass(); $node->taxonomy = $terms; $links = theme('links', taxonomy_link('taxonomy terms', $node)); } return $links; }