Select translation

Categories

Component ID

271451

Component name

Select translation

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

9309

Component created

Component changed

Component body

Description

Select translation implements a Views filter to select which translation of a node should be displayed in a list of nodes.

Several modes are available to select a translation:

  • Use the current interface language; if not available use the original node language.
  • Use the current interface language; if not available use the default site language; if not available use the original node language.
  • Specify a list of languages, and use the most appropriate language.

    Some special values are recognized in the languages list:
    • "current" will be replaced with the current interface language;
    • "default" will be replaced with the default site language;
    • "original" will be replaced with the original node language.

Select translation also provides an API following the same selection algorithm as the Views filter.

Drupal 6 Compatibility

Select translation works with Content translations (not Entity translations).

If you have i18n, you should set 'Content selection mode' to 'All content' in i18nsettings (admin/settings/i18n).

API

Given a node id, and a selection mode, the function returns the node id to display.

Example:

  <?php
  $my_nid = select_translation_of_node($nid); // Uses 'default' mode
  $my_nid = select_translation_of_node($nid, 'original'); // Uses 'original' mode
  $my_nid = select_translation_of_node($nid, array('en', 'fr', 'current')); // Returns the best match
  ?>

Similar project : Active translation performs a similar function but it is not a Views filter - it acts on all queries of the whole site.

Drupal 7

Select translation starts using an optimized query for the Views filter plugin.

Drupal 8

Select translation works on Entity translations.

Since in Drupal 8 any node always have at least one "translation" (the original one), the include_content_without_translation option has been removed.

API

Given a node id, and a selection mode, the function returns the entity translation.

Example:

  <?php
  use Drupal
odeEntityNode;

  /* @var Drupal
odeEntityNode $my_node */
  $my_node = select_translation_of_node($nid); // Uses 'default' mode
  $my_node = select_translation_of_node($nid, 'original'); // Uses 'original' mode
  $my_node = select_translation_of_node($nid, 'en,fr,current'); // Returns the best match
  ?>