Browser detection of language variants: How to have fr-CA display fr pages

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by Advocat on November 3, 2010 at 5:08pm

I am creating a Canadian national project site in English and French. Given that French Canadian (fr-CA) has had few translations done, we're going to use standard French (fr).

However, for those browsers who have languages set to fr-CA, we don't want to display the site default/fallback language of English, but the fr (French) version of the pages.

I'm sure there's must be a way to set Drupal so the fallback for fr-CA language is fr, while the site fallback remains English, but I've been unable to locate it in the documentation.

Any help would be appreciated.

Comments

Similar problem

Posted by frank ralf on November 3, 2010 at 7:40pm

Have a look at Language variations (en-GB, en-AU, etc.) for some pointers.

Unfortunately there seems to be no easy solution (yet).

hth
Frank

Apache redirect may be a solution

Posted by andy inman on November 22, 2010 at 6:43pm

My post that Frank refers to above is about how do offer specific content for language variants (e.g. British English, Australian English, etc. with fallback to "general" English.)

If all you want to do is redirect fr-CA to fr and so on, then redirect rules in Apache is one way of handling it. What can't be handled is displaying fr-CA content if it exists with fallback to plain fr content if not. However, I've got most of the functionality required already in Multilink just waiting for a reason (or client!) to make it worth adding support for language variants.



Currently part of the team at https://lastcallmedia.com in a senior Drupal specialist role.

Possible solution hacking core

Posted by brennino on November 25, 2014 at 4:49pm

Hi, I know this is an old thread but maybe a solution to this problem can be welcome.

I believe this issue is for drupal 6, due to the thread date. I have the same issue with browser with en-GB only locale set.

Under includes/language.inc there is the function that check the header sended by the browser for get the language. In that function due to the regexp problem a '-' has been forgotten in the lang string for comparision. I don't know if this is the correct behaviour but you can make this change in core for makes the thing work also for fr-CA language:

Look for this code in include/language.inc

if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$browser_accept = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
for ($i = 0; $i < count($browser_accept); $i++) {
// The language part is either a code or a code with a quality.
// We cannot do anything with a * code, so it is skipped.
// If the quality is missing, it is assumed to be 1 according to the RFC.
if (preg_match("!([a-z-]+)(;q=([0-9\.]+))?!", trim($browser_accept[$i]), $found)) {
$browser_langs[$found[1]] = (isset($found[3]) ? (float) $found[3] : 1.0);
}
}
}

Change this code:

$browser_langs[$found[1]] = (isset($found[3]) ....

with this code:

$browser_langs[trim($found[1],'-')] = (isset($found[3]) ....

Done.

Remember that this is a core hack so, when you update Drupal core to a new version, you have to write the hack again.

If this is the behaviour intended, please d6 core developer, update d6 with this code (also if it's nearly EOF).

Hope this help

Brennino

@brennino - I think you could

Posted by andy inman on November 25, 2014 at 4:54pm

@brennino - I think you could do this without a core patch in D7 at least. Also, I think MultiLink might do what you need in D6, but I'm not sure, it's a long time since I've worked on that module.

To get your change possibly implemented in D6, you would need to raise an issue in the issue queue - but with everybody now busy on D7 and D8, I doubt if it will get much attention.



Currently part of the team at https://lastcallmedia.com in a senior Drupal specialist role.

Internationalization

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /