Let's say you have a taxonomy called Animals and you have terms like Dog, Cat, Horse, etc. Every term has its translation, so for example for dogs you have Hund and Chien. Now you want to make a View which generates a page that lists content tagged with the Animals term reference, contextually filtering the tag based on the URL part.

And this is the part I'm having difficulties with. The contextual filter I made works perfectly with source language values and converts properly to term ID. So I'm getting correct listing (both in preview pane and generated page) for /animals/dog but incorrect for /tiere/hund.

The contextual filter is set to Content: Animal Genre (Translated) and validation to Localised term or synonym converted to term ID (actually I tried perhaps every possible combination of i18n and non-i18n options here, no joy).

I trie out another solution - with Content: Has taxonomy term ID + relationship (as described here).

Is it something I'm not setting up correctly or is there a bug around i18n, Views, i18nviews...? I'd be grateful for any guidance

  • It could be related to the capital letters in your taxonomy terms. Try /Tiere/Hund or /tiere/Hund.
    – bohemier
    Commented Apr 9, 2013 at 21:04

1 Answer 1


Implementing hook_language_switch_links_alter() is definitely the way to go. Here is the code along with two (2) helper functions, assuming there are display variants for each language.

 * Implements hook_language_switch_links_alter().
 * This is a workaround for Path Translation not supporting Views' contextual filters.
 * Alter the language switcher to switch between path/to/[term] and different
 * paths for different languages.
function mymodule_language_switch_links_alter(array &$links, $type, $path) {

  // Load the current view if there is one.
  $view = views_get_page_view();

  // Act only if we're looking at the view in question.
  if (($type == "language_content") && isset($view) && ($view->name == 'myview')) {

    // Skip situations where there's no argument.  This is handled by Path Translatoon.
    if (isset($view->args[0]) && ($view->args[0] != mymodule_get_myview_view_all_term($view))) {

      // Iterate across all language links.
      $language_active = $GLOBALS['language']->language;
      $displays = mymodule_get_myview_view_language_displays();
      foreach ($links as $language_current => &$link) {

        // Skip the active language.
        if ($language_current == $language_active) {

        // Set the path for the current language.
        $path = $view->display[$displays[$language_current]]->display_options['path'];
        $link['href'] = strtok($path, '/') . '/' . $view->args[0];
      // Break the foreach reference.

 * Returns the list of displays for the view in question, keyed by language.
 * @return array
 *   The list of displays.
function mymodule_get_myview_view_language_displays() {
  return array(
    'en' => 'page_myview_en',
    'fr' => 'page_myview_fr',

 * Get the language-specific term representing all items.
 * @param view $view
 *   The previously loaded view in question.  Optional.
 * @return string
 *   The term.  If there's no translation in the current language, "all" is used.
function mymodule_get_myview_view_all_term($view = NULL) {

  // Load the view if it wasn't provided.
  $view = (is_null($view) ? views_get_view('myview') : $view);

  // Get the current language and the display names for each defined language.
  $language = $GLOBALS['language']->language;
  $displays = mymodule_get_myview_view_language_displays();

  // Return the language's "all" term, or the default if there isn't one.
  if (isset($view->display[$displays[$language]]->display_options['arguments']['tid']['exception']['value'])) {
    return $view->display[$displays[$language]]->display_options['arguments']['tid']['exception']['value'];
  else {
    return 'all';

Note that this doesn't handle the translation of the term itself within the path, only the part of the path leading up to it. For now, that will always be in the default language. This is the separate issue Views contextual filter validation: Support ET-translated taxonomy term name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.