Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Change language in J1.7 as result of a rule

Change language in J1.7 as result of a rule

Just making a note of this cool usage here. This allows you to set the language as the result of any rule. E.g. you can use en.example.com as your english domain, and fr.example.com as your French domain.

Note: this will NOT redirect people to the "other" domain if they use the language switcher module. It simply forces the system to be in a certain language if the guest is on a certain domain. If you want to send people to the other domain, you'll need to set up separate links on the page that explicitly send them to that domain.

1 - set up Joomla 1.7 as a multi-lingual site. (this is pretty horrible to do, but it's possible!)
2 - in Chameleon, make a rule that will detect anyone on the French site who is not viewing in French. We'll tell it to change the language to French.

- name the rule
- in the Environment section, enter "fr" in the "Exclude these languages" box
- also in the Environment section, enter "fr.example.com" into the domains box.

(this will detect anyone on fr.example.com who is not viewing in French)

- now in the SUCCEED action, enter the following into the PHP box:

$app = JFactory::getApplication();
$app->initialise(array("lang"=>"fr"));

- save the rule.

3 - create a 2nd rule to do the same thing for English:

- name the rule
- in the Environment section, enter "en" in the "Exclude these languages" box
- also in the Environment section, enter "en.example.com" into the domains box.

(this will detect anyone on en.example.com who is not viewing in English)

- now in the SUCCEED action, enter the following into the PHP box:

$app = JFactory::getApplication();
$app->initialise(array("lang"=>"en"));

- save the rule.

Now view some pages on en.example.com and fr.example.com

You should see that all the URLs on en.example.com start with en.example.com/en, and all the ones on fr.example.com start with fr.example.com/fr.

If you try to change the language prefix, it will redirect back to the correct one for that domain again.

Yeah, it would be nice to not have the additional language code at the start of the URI, but hopefully that's not a big deal.

Hope this is useful to people. I think this could be extremely useful. You don't have to restrict this to different domains - you could use other factors like landing page / referrer detection to switch the language - the sky's the limit!

Stephen

Edited By: metamodguy
06-Oct-11 00:15:20

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Change language in J1.7 as result of a rule

Update: the approach above doesn't work with sh404SEF, because with sh404SEF you have to turn off the Language Filter plugin.

So here's an alternative piece of code to put into the PHP box in the SUCCEED action. I'll probably incorporate this into the interface if I get good feedback about how it works for people.

Code:

// set these two codes to the FULL language string

// of the language you want to force ($lang_code),
// and the sef short code for that language ($lang_sef).
// I've just used these ones as an example on my system.

$lang_code = 'cs-CZ';
$lang_sef = 'cs';

$link = '';

$db            = JFactory::getDBO();
$app        = JFactory::getApplication();
$query        = $db->getQuery(true);
$query->select('id');
$query->select('language');
$query->from($db->nameQuote('#__menu'));
$query->where('home=1');
$db->setQuery($query);
$homes = $db->loadObjectList('language');

if ($app->get('menu_associations', 0)) {
    $menu = $app->getMenu();
    $active = $menu->getActive();
    if ($active) {
        $associations = MenusHelper::getAssociations($active->id);
    }
}

if ($app->getLanguageFilter()) {
    if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
        $itemid = $associations[$lang_code];
        if ($app->getCfg('sef')=='1') {
            $link = JRoute::_('index.php?lang='.$lang_sef.'&Itemid='.$itemid);
        }
        else {
            $link = 'index.php?lang='.$lang_sef.'&Itemid='.$itemid;
        }
    }
    else {
        if ($app->getCfg('sef')=='1') {
            $itemid = isset($homes[$lang_code]) ? $homes[$lang_code]->id : $homes['*']->id;
            $link = JRoute::_('index.php?lang='.$lang_sef.'&Itemid='.$itemid);
        }
        else {
            $link = 'index.php?lang='.$lang_sef;
        }
    }
}
else {
    $link = 'index.php';
}
if ($link) $app->redirect( $link );

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Change language in J1.7 as result of a rule

its not work and go to redirecting loop with joomla 2.5.1 and metamode current version

please help me

jacob.arlington
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Change language in J1.7 as result of a rule

Hi Jacob,

As yet I have not certified Chameleon to work on Joomla 2.5. The code above was tested on Joomla 1.7, and is actually based on code inside Joomla 1.7.  I'm afraid it's going to be next month before I have time to work through this and other issues (I'm going overseas for the rest of the month and won't be able to work on it over this time).

So I apologise for this. If I do get a spare hour I'll try to look at it sooner, but sorry I can't promise that.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Change language in J1.7 as result of a rule

IMPORTANT: All advice given above is out of date! Please don't try any of that at home!

As of May 2012, there's a new version of Chameleon for Joomla 2.5 (Chameleon v2.26) which has a GUI control for setting the language of the current page via a redirect. See here for details:

http://www.metamodpro.com/blog/automati … la-25.html

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1689
Total Polls:
6
Total Posts:
5941
Posts this week:
1
User Info:
 
Total Users:
5361
Newest User:
scotti64d
Members Online:
1
Guests Online:
140

Online: 
scotti64d

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked