Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#2 | i18n.module.patch | 2.79 KB | ablivio |
Comments
Comment #1
pkej CreditAttribution: pkej commented+1 I would like that functionality as well.
Could you provide it as a patch?
Comment #2
ablivio CreditAttribution: ablivio commentedHere is the patch.
Take this with caution: I tested it on a small set of data only.
-- Denis.
Comment #3
Jose Reyero CreditAttribution: Jose Reyero commentedSeems to work fine. Applied with small changes (5.x-3.x branch).
Thank you.
Comment #4
Jose Reyero CreditAttribution: Jose Reyero commentedComment #5
Jose Reyero CreditAttribution: Jose Reyero commentedPorted to Drupal 6
Comment #6
raska__ CreditAttribution: raska__ commentedHello,
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!
Comment #7
mr.j CreditAttribution: mr.j commentedThat 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.