| 7 |
function select_translation_help($section, $arg) { |
function select_translation_help($section, $arg) { |
| 8 |
switch ($section) { |
switch ($section) { |
| 9 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 10 |
return t('A views filter, allowing users to display only one of the nodes of a group of nodes representing a translation'); |
return t('Select translation provides a views filter and a module API, allowing users to display only one of the nodes of a group of nodes representing a translation'); |
| 11 |
} |
} |
| 12 |
} |
} |
| 13 |
|
|
| 14 |
|
/** |
| 15 |
|
* Returns the node_id representing the preferred translation of the given node. |
| 16 |
|
* |
| 17 |
|
* $mode can be : |
| 18 |
|
* - default ; in which case the function will return the node in the current |
| 19 |
|
* language if available ; if not that in the default languauge ; |
| 20 |
|
* if that is not available then the one in the original language. |
| 21 |
|
* |
| 22 |
|
* - original ; in which case the function will return the node in the current |
| 23 |
|
* language if available ; if not that in the original language. |
| 24 |
|
* |
| 25 |
|
*/ |
| 26 |
|
function select_translation_of_node($nid, $mode = 'default') { |
| 27 |
|
global $language; |
| 28 |
|
|
| 29 |
|
$node = node_load($nid); |
| 30 |
|
if (!$node || $node->tnid == 0 || $node->language == $language->language) { |
| 31 |
|
return $nid; |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
$translations = translation_node_get_translations($node->tnid); |
| 35 |
|
if (isset($translations[$language->language])) { |
| 36 |
|
return $translations[$language->language]->nid; |
| 37 |
|
} else if ($mode == 'default' && isset($translations[language_default('language')])) { |
| 38 |
|
return $translations[language_default('language')]->nid; |
| 39 |
|
} else { |
| 40 |
|
return $node->tnid; |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
|
|