Screen Shot 2012-01-06 at 2.21.17 PM.png

Overview

This functionality is best illustrated with a use case: you have multilingual content in your site, in the form of nodes that are full translations of each other. Let's say they are news articles. You have a View that shows all news articles, filtered by the user's language.

Now you want to provide a language switcher that will list all languages, but is also content aware, i.e. it only provides the option to switch to a language if there is content in that language for this View. Views summary view can get close, but does not produce native labels for the languages, and it only prints links that have results.

This module closes the gap. It provides a block that appears only on Views pages and outputs a list of languages. Although all languages will always be listed, each item will only be linked if clicking on it actually provides a non-empty page.

Theming and performance

Output can be overridden via theme layer, and the module provides both a wrapper and individual link template.

The module is written to be high-performance, so the heavy computation is only performed by one request (locking) and cached for 3 hours. While it's being rebuilt, other requests will either serve the stale info if it's available or show all language choices as links (the sensible fallback option).

Dependencies

Drupal 7 and Views 3.

Usage

  • Your View needs to provide an exposed filter of "Content translation: Language". This needs to be exposed, but you can suppress it using hook_views_post_build(), or CSS as a last resort. Set the default value to current user's language.
  • Make a 'page' display in your view.
  • If you want to modify the list of languages from the site's default installed languages, implement hook_vls_languages_list_alter().
  • Enable module, place the block.

Sponsors

Initial development of this module was supported by ICANN.org during their Drupal 7 migration.

Supporting organizations: 
maintenance of module.

Project information

Releases