I would like to add another language selection mode, which I called "preferred".

Here is how selection behaves:
- if the node has no language, display it
- if the node is available in current language, display it
- or else, if the node is available in default language, display it
- otherwise, don't display it
I hacked i18n.module to do so. The number of changes is quite limited:

611a612
>  *      preferred = Current language or else (if available) default language, and no language
641a643
>     'preferred' => t('Current language or else (if available) default language, and no language'),
743,744c745,750
<       
<       $result['join'] = "LEFT JOIN {i18n_node} i18n ON $primary_table.nid = i18n.nid";
---
>       if ($mode == 'preferred') {
>         $result['join'] = "LEFT JOIN {i18n_node} i18n ON $primary_table.nid = i18n.nid LEFT JOIN {i18n_node} i18n2 ON i18n.trid = i18n2.trid and i18n2.language = '".i18n_get_lang()."'";
>       }
>       else {
>         $result['join'] = "LEFT JOIN {i18n_node} i18n ON $primary_table.nid = i18n.nid";
>       }
773a780,786
>     case 'preferred':
>       if ($alias == "i18n"){
>         return "$alias.nid IS NULL OR $alias.language ='".i18n_get_lang()."' OR ($alias.language ='".i18n_default_language()."' AND $alias"."2.nid IS NULL)" ;
>       }
>       else {
>         return "$alias.language ='".i18n_get_lang()."' OR $alias.language ='".i18n_default_language()."' OR $alias.language ='' OR $alias.language IS NULL" ;
>       }

Do you think that such a hack is OK?

I am quite concerned by the SQL request. I am not a specialist and don't know how heavy it can be on a large site.

Thanks for your comments.

-- Denis.

CommentFileSizeAuthor
#2 i18n.module.patch2.79 KBablivio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pkej’s picture

+1 I would like that functionality as well.

Could you provide it as a patch?

ablivio’s picture

FileSize
2.79 KB

Here is the patch.

Take this with caution: I tested it on a small set of data only.

-- Denis.

Jose Reyero’s picture

Status: Active » Fixed

Seems to work fine. Applied with small changes (5.x-3.x branch).

Thank you.

Jose Reyero’s picture

Status: Fixed » Patch (to be ported)
Jose Reyero’s picture

Status: Patch (to be ported) » Closed (fixed)

Ported to Drupal 6

raska__’s picture

Hello,
patch works fine, but when I change language, I only see comments in one language!
For example, I post one story in english and I make a traslation for this node in spanish. When I write a comment I only see in language that I write and when I change the language, comments not show.
Can you help me?

thanks!

mr.j’s picture

That is because translating a node creates an entirely new node. When you create a comment, it is attached to the node you were viewing at the time. If you don't want that to happen then you can include all your translated text on a single node (with no language) using the language sections module, but then you cannot have translations with a separate page title, path alias, meta tags etc.