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:

>  *      preferred = Current language or else (if available) default language, and no language
>     'preferred' => t('Current language or else (if available) default language, and no language'),
<       $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";
>       }
>     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.

#2 i18n.module.patch2.79 KBablivio


pkej’s picture

+1 I would like that functionality as well.

Could you provide it as a patch?

ablivio’s picture

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

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?


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.