Core produces a filter per taxonomy term field.

All should have its corresponding translated variant by i18n.

Comments

webflo’s picture

Status: Active » Needs review
StatusFileSize
new6.53 KB

A first version.

miro_dietiker’s picture

Ahhh great to see someone contributing here! :-)

I'll review this next week.

webflo’s picture

Rerolled.

webflo’s picture

Status: Needs review » Fixed
Issue tags: +dvcs11

Commit e201085 on 7.x-3.x,

fietserwin’s picture

Status: Fixed » Needs work

This patch is not correct. We may assume that i18n_taxonomy is enabled. Otherwise taxonomies are not translated at all and this whole functionality is void. However, i18n_taxonomy "takes over" ownership of taxonomy term reference fields by setting the 'module' property to 'i18n_taxonomy'. So the function i18nviews_field_views_data_alter() will miss the fields it want to alter.

In issue #1281704: Taxonomy terms are not translated in content create/edit form, I proposed a patch for the issue at hand (#14) and for translating taxonomies in Views exposed filters as well (#15). The part from #14 was accepted, but the additions in #15 were not, referring to this module.

Proposal:
If we can assume that i18n_taxonomy is indeed enabled, than the not incorporated part of #15 can be used to solve this issue. To do so we need to "complete" i18n_taxonomy in taking over the taxonomy term reference fields by implementing the Views hooks below as well.

The code to add:

/**
 * Implements hook_field_views_data().
 *
 * Take over Views handling for taxonomy as well,
 * @see views/modules/taxonomy.views.inc.
 */
function i18n_taxonomy_field_views_data($field) {
  return taxonomy_field_views_data($field);
}

/**
 * Implements hook_field_views_data_views_data_alter().
 *
 * Take over Views handling for taxonomy as well,
 * @see views/modules/taxonomy.views.inc.
 */
function i18n_taxonomy_field_views_data_views_data_alter(&$data, $field) {
  return taxonomy_field_views_data_views_data_alter($data, $field);
}

What to change in this patch:

@@ -162,6 +162,16 @@ function i18nviews_views_data_alter(&$data) {
  */
 function i18nviews_field_views_data_alter(&$data, &$field, $module) {
   if ($module == 'taxonomy') {
+    foreach ($data as $table_name => $table_data) {
+      foreach ($table_data as $field_name => $field_data) {
+        if (isset($field_data['filter'])) {
+          $data[$table_name][$field_name . '_i18n'] = $data[$table_name][$field_name];
+          $data[$table_name][$field_name . '_i18n']['real field'] = $field_name;
+          $data[$table_name][$field_name . '_i18n']['title'] .= ' (translated)';
+          $data[$table_name][$field_name . '_i18n']['filter']['handler'] = 'i18nviews_handler_filter_term_node_tid';
+        }
+      }
+    }

- change the line just above the addition, from its current version

  if ($module == 'taxonomy' && module_exists('i18n_taxonomy')) {

to

  if ($module === 'i18n_txonomy) {

- Remove the added handler altogether? Without looking in depth at what the filter does, my first impression is that the handler is not needed anymore, but I am not sure about that.

webflo’s picture

Assigned: Unassigned » webflo

@fietserwin: You are right.

webflo’s picture

Status: Needs work » Fixed

Fixed in commit 3cd6224 on 7.x-3.x.

Automatically closed -- issue fixed for 2 weeks with no activity.