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.

 

Set language based on default browser language on landing page

Set language based on default browser language on landing page

I have a J2.5 site with a single domain. When people browse directly to the root URL (http://www.example.com/) only, I want to set the default language based on their browser's default language.

I have a rule set up to say if browser language is English, and Page URL equals http://www.example.com/, set default language to English. And then I have FAIL rule to set language to French.

But then if user browses to any other page on the site, and clicks language toggle, they still see the site in their browser's default language (that is, they cannot toggle between English and French).

Here's a screen movie showing my Chameleon settings: http://screencast.com/t/YRfw9zkcac

What am I doing wrong?

smallbiz
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi smallbiz,

Thanks for the info and screencast - it's great to be able to see all the settings like that!

One thing that I see is that the rule effectively says "If the browser is in English AND the URL is exactly www.example.com, then switch to English. In all other cases (FAIL action), switch to French".

Therefore, you're forcing a switch to French not only when the browser is in French, but also when the person is viewing a page other than the front page.

My guess is that's not what you want. You probably want 2 separate rules:

1 - if page is on front page AND browser is in English, force to English (SUCCEED action only)
2 - if page is on front page AND browser is in French, force to French (SUCCEED action only)

I think that's likely to do what you want.

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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi, thanks for your suggestion. I made those changes, and I still seem to be pointed to only the English version of the page.

Here's a screen movie of my new rules, and my test scenario: http://screencast.com/t/C5uL1O0gNf

smallbiz
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi smallbiz, thanks again for the screencast.

I have a couple of thoughts:
1 - I wonder if your browsers are caching the redirect? You can examine the "conversation" using a tool in Firefox called LiveHeaders and possibly in Firebug and its Chrome equivalent. If this is the case, it's a pain and I think I'd want to change the mechanism used in Chameleon for doing the redirects.

2 - can you please turn on debugging mode in the Chameleon Options panel, then do the same testing you are doing. This should display info in the front end about what rules are being executed, and which actions run. This may also shed light on why the redirection to English is taking place.

Hope that helps,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi, I've cleared browser cache, and tried a number of different web browsers -- all exhibit the same behaviour.

I'm not too sure what to do with the Live Headers, but I did enable the debug mode, and browsed to the home page with English set as FireFox's default language, and then changed default language to French, and tried again.

I see the URL doesn't match correctly (looks like before the rule is checked, Joomla has already redirected to the English url /index.php/en/ ....

Here's the output:

ENGLISH AS BROWSER DEFAULT LANG
        CHAMELEON DEBUG ON
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-10 14:44:46pm" in timezone "America/Toronto"
        Processing rule id 4 ("English Browsers")
        - Language: "en" is in the include list - succeeding
        - URL: "http://www.friends-amis.org/index.php/en/" equals "http://www.friends-amis.org/" ? - failing
        Started FAIL action for rule id 4
        Finished FAIL action: default template style not changed
        Exiting rule system as result of rule FAIL at rule id 4 (English Browsers)
        Final template style unchanged


FRENCH AS BROWSER DEFAULT LANG
        CHAMELEON DEBUG ON
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-10 14:45:36pm" in timezone "America/Toronto"
        Processing rule id 4 ("English Browsers")
        - Language: "fr" is not in the include list - failing
        Started FAIL action for rule id 4
        Finished FAIL action: default template style not changed
        Exiting rule system as result of rule FAIL at rule id 4 (English Browsers)
        Final template style unchanged

smallbiz
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

What I think I see there is that in the FAIL action in rule id #4, the rule chain is being exited. If you have another rule after that one, to check for French browsers, Chameleon is not getting to it. This is likely because in the FAIL action in rule #4 you may have "stop processing" selected. Instead, try having it set to "process next rule in chain".

Hope that may be the issue,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Ah yes, I could see that being an issue. I've changed that so that the FAIL rule on the first rule will continue (http://screencast.com/t/AxSbpVtFl)

But still, after changing browser default language, both rules fail -- and it appears it is because of the URL checking. I am browsing directly to https://www.friends-amis.org/ ensuring I'm not including the index.php/en part that appears in the URL check below:

English:
        CHAMELEON DEBUG ON
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-10 18:00:26pm" in timezone "America/Toronto"
        Processing rule id 4 ("English Browsers")
        - Language: "en" is in the include list - succeeding
        - URL: "https://www.friends-amis.org/index.php/en/" equals "https://www.friends-amis.org/" ? - failing
        Started FAIL action for rule id 4
        Finished FAIL action: default template style not changed
        Processing rule id 6 ("French Browsers")
        - Language: "en" is not in the include list - failing
        Started FAIL action for rule id 6
        Finished FAIL action: default template style not changed
        Exiting rule system as result of rule FAIL at rule id 6 (French Browsers)
        Final template style unchanged

French:
        CHAMELEON DEBUG ON
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-10 17:59:31pm" in timezone "America/Toronto"
        Processing rule id 4 ("English Browsers")
        - Language: "fr" is not in the include list - failing
        Started FAIL action for rule id 4
        Finished FAIL action: default template style not changed
        Processing rule id 6 ("French Browsers")
        - Language: "fr" is in the include list - succeeding
        - URL: "https://www.friends-amis.org/index.php/en/" equals "https://www.friends-amis.org/" ? - failing
        Started FAIL action for rule id 6
        Finished FAIL action: default template style not changed
        Exiting rule system as result of rule FAIL at rule id 6 (French Browsers)
        Final template style unchanged

smallbiz
Beginner Modder
ranks
useravatar
Offline
12 Posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi,

I'm just investigating why this is happening, and it's quite complicated. However I have to ask: if you simply want automatic language detection according to browser language, then why not just use the facilities in the standard Joomla "System - language filter" plugin? There's an option in there for "Language Selection for new Visitors: Browser settings" which I think does what you are trying to do.

Or, is it important that the browser language detection ONLY happens on the front page, and not on other pages?

I'm still looking at why you are seeing the Chameleon behaviour you're seeing.

Cheers,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Ok, I have done some more experimenting with this in J2.5.

Here's my setup:
- EN and FR language packs installed
- system language filter plugin enabled
- in system language filter, the following settings:

Language Selection for new Visitors: Site Language
Automatic language change: Yes
Menu associations: Yes
Remove URL Language Code: Yes
Add alternate meta tags: No (probably doesn't matter)

- a French menu set up, with a default home menu item for French
- another item in the French menu set up as FR language and with an associated menu item on the English menu (just so there's at least 1 of these)

- delete site cookies
- set up Chameleon to check for home page by URL (http://localhost/j256/) AND fr browser language, then change language to FR.

Testing: this MOSTLY works but not quite:

Visit the page http://localhost/j256/ with browser set to FR:

        CHAMELEON DEBUG ON
        Current date and time: "2014-03-16 22:40:37pm" in timezone "UTC"
        Processing rule id 14 ("language change only on certain page")
        - Language: "fr" is in the include list - succeeding
        - URL: "http://localhost/j256/" equals "http://localhost/j256/" ? - succeeding
        Started SUCCEED action for rule id 14
        - Language: redirecting to /j256/fr/
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-16 22:40:38pm" in timezone "UTC"
        Processing rule id 14 ("language change only on certain page")
        - Language: "fr" is in the include list - succeeding
        - URL: "http://localhost/j256/fr/" equals "http://localhost/j256/" ? - failing
        Started FAIL action for rule id 14
        Finished FAIL action: default template style not changed
        Finished all rules
        Final template style unchanged

Now visiting any other page keeps me in FR.

The problem is when trying to visit localhost/j256/en to try to force it to English:

        CHAMELEON DEBUG ON
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-16 22:46:06pm" in timezone "UTC"
        Processing rule id 14 ("language change only on certain page")
        - Language: "fr" is in the include list - succeeding
        - URL: "http://localhost/j256/" equals "http://localhost/j256/" ? - succeeding
        Started SUCCEED action for rule id 14
        - Language: redirecting to /j256/fr/
        CHAMELEON DEBUG ON
        Current date and time: "2014-03-16 22:46:06pm" in timezone "UTC"
        Processing rule id 14 ("language change only on certain page")
        - Language: "fr" is in the include list - succeeding
        - URL: "http://localhost/j256/fr/" equals "http://localhost/j256/" ? - failing
        Started FAIL action for rule id 14
        Finished FAIL action: default template style not changed
        Finished all rules
        Final template style unchanged

The problem is that the system language filter plugin detects /en as being one where it should remove the URL language code (that was one of the settings). So it immediately redirects to "/", which then gets picked up by Chameleon and redirected. This happens even when using the language switcher module is used to go to the EN version of a FR page: it gets sent to /en/ which gets redirected to / which Chameleon redirects to /fr/

Next test: set Remove URL Language Code: NO in the system langauge filter plugin.

Now we have a related problem...

Go to /, and the system language filter sends you immediately to /en as the default language, before Chameleon gets to look at it. So Chameleon cannot detect that you went to /

There are several approaches that could be taken here:

1 - When Remove URL Language Code: YES is set, we need to find a way to allow links that SHOULD allow the page to be set to EN to be able to do so.

e.g.1 when you are on an EN page like /foo the language switcher module links the associated EN page as /
e.g.2 when you are on an FR page like /fr/foo the language switcher module links the associated EN page as /en

In both these cases you would expect the user to remain in English when clicking on that icon. However in both cases the url is switched to / which Chameleon is then going to pick up and redirect to the FR version.

I would suggest some modifications be made to the system language filter plugin:
a - in both cases (eg1, eg2) set the EN version of the home page as /en so that it's unambiguous, EVEN THOUGH "remove URL language code" is set.
b - then change the plugin behaviour so that /en is not redirected back to /. This could be a switchable behaviour. The advantage is that Chameleon can then detect whether you really did want /en or /.

Now I am not sure if this issue only affects the front page or if it can affect other translatable pages too.

2 - Find a way to let Chameleon get at the URL *before* it gets redirected by the system language filter plugin.
- the main reason it doesn't, is that in Chameleon it does a "route()" call before the rules are executed. This allows the system to route the URL which does things like working out which component is going to be used. The system language filter plugin uses the routing system to detect language-based URLs then does redirects for them.
- it's mostly very desirable for Chameleon to be able to operate based on parsed URLs, so I'm not actually all that keen to drop that. Another option might be for Chameleon to add a parse rule that simply records the original URL into the session. Then in a Chameleon rule you could choose to compare to this original URL instead of the "current" URL (which may be the result of redirections).
Challenges to this method might be things like AJAX requests (which also invoke Chameleon) and times when Chameleon itself does redirects. How do you determine what is the "first" request, or which requests/URLs should be considered as redirections of a previous one?

Thoughts?

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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Set language based on default browser language on landing page

Hi Smallbiz,

I've just done a new build of Chameleon that addresses the redirection problem via solution (2) above. That is, it detects if the url parsing results in a redirection, and if so it remembers the previous URL. Then after the redirection it uses this remembered URL instead of the redirected one, if you detect using the URL matching in Chameleon.

Can you please PM me with your e-mail address so I can send this to you to see if it addresses the problem? It seems to work well for me in testing.

Thanks,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1680
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10831
Newest User:
bluesky1
Members Online:
0
Guests Online:
185

Online: 
There are no members online

Forum Legend:

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