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.
Drupal 9+
2.x is a Drupal 9+ successor of 8.x-1.x-dev. It's stability is currently alpha, so use with care!
API
Given a node id, and a selection mode, the function returns the entity translation.
Example:
<?php
use Drupal\node\Entity\Node;
/* @var \Drupal\node\Entity\Node $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
?>
Project information
- Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed. - Maintenance fixes only
Considered feature-complete by its maintainers. - Module categories: Multilingual
- 6,278 sites report using this module
- Created by Alice Heaton on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 2.x-dev updated 3 Jan 2023 at 14:56 UTC
First stable release of select_translation for Drupal 8
Development version: 8.x-1.x-dev updated 5 May 2021 at 20:20 UTC
Fix [#2876095]
Development version: 7.x-1.x-dev updated 15 Jun 2017 at 08:04 UTC