Preferred language option

ablivio - December 25, 2007 - 13:27
Project:Internationalization
Version:5.x-2.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

#1

pkej - December 31, 2007 - 13:50

+1 I would like that functionality as well.

Could you provide it as a patch?

#2

ablivio - January 1, 2008 - 20:00

Here is the patch.

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

-- Denis.

AttachmentSize
i18n.module.patch 2.79 KB

#3

Jose Reyero - August 8, 2008 - 11:25
Status:active» fixed

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

Thank you.

#4

Jose Reyero - August 8, 2008 - 11:30
Status:fixed» patch (to be ported)

#5

Jose Reyero - August 9, 2008 - 13:08
Status:patch (to be ported)» closed

Ported to Drupal 6

#6

raska__ - September 8, 2008 - 08:31

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!

#7

mr.j - November 18, 2008 - 05:02

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.

 
 

Drupal is a registered trademark of Dries Buytaert.