5 Replies - 600 Views - Last Post: 05 October 2012 - 11:14 AM Rate Topic: -----

#1 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

Set default lang as English

Posted 05 October 2012 - 04:41 AM

I'm using this script:

    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    switch ($lang){
        case "nl":
            //echo "PAGE FR";
            include("talen/nl.php");//include check session FR
            break;
        case "es":
            //echo "PAGE IT";
            include("talen/es.php");
            break;
        case "en":
            //echo "PAGE EN";
            include("talen/en.php");
            break;        
        default:
            //echo "PAGE EN - Setting Default";
            include("talen/en.php");//include EN in all other cases of different lang detection
            break;
    }


But when I set browser language to "af" it doesnt get the default english language...

How can I make that happen?

I have no case "af" so it doesnt show anything...

When there is no case like "af" I want the default to be "en" but that doesnt work

This is another solution I tried but no luck either:

<?
    $accept_lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $accept_lang = str_replace(' ', '', $accept_lang);
    
    $arr = explode(',', $accept_lang);
    
    $lang = "en";
    $q = 0;
    
    if (count($arr) > 0) {
        foreach ($arr as $a) {
        $l = explode(';', $a);
    
        if (count($l) == 1) {
            $l[1] = 'q=1';  
        }
    
        $l[1] = str_replace('q=', '', $l[1]);
    
        if ($l[1] > $q) {
            $q = $l[1];
        $lang = $l[0];  
        }
    }
    }
    
    $lang = preg_replace('/-(.*)/', '', $lang);
    
    switch ($lang){
        case "nl":
            //echo "PAGE FR";
            include("talen/nl.php");//include check session FR
            break;
        case "es":
            //echo "PAGE IT";
            include("talen/es.php");
            break;
        case "en":
            //echo "PAGE EN";
            include("talen/en.php");
            break;        
        default:
            //echo "PAGE EN - Setting Default";
            include("talen/en.php");//include EN in all other cases of different lang detection
    }
    ?>


My $lang is still set to "af" and not the default "en"

Is This A Good Question/Topic? 0
  • +

Replies To: Set default lang as English

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3520
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Set default lang as English

Posted 05 October 2012 - 04:53 AM

Quote

But when I set browser language to "af" it doesnt get the default english language...

if it doesnít which language does it get? note that you donít re-set $lang anywhere.


Quote

My $lang is still set to "af" and not the default "en"

why should it be set to anything else? "af" is a valid value for this code, so "en" gets replaced.
Was This Post Helpful? 0
  • +
  • -

#3 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

Re: Set default lang as English

Posted 05 October 2012 - 05:09 AM

View PostDormilich, on 05 October 2012 - 04:53 AM, said:

Quote

But when I set browser language to "af" it doesnt get the default english language...

if it doesnít which language does it get? note that you donít re-set $lang anywhere.


Quote

My $lang is still set to "af" and not the default "en"

why should it be set to anything else? "af" is a valid value for this code, so "en" gets replaced.


Thanks for your answer:)

How can I edit my code that when browser language is set to "af" and I dont have a case for "af" it is set by default "en"?
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3520
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Set default lang as English

Posted 05 October 2012 - 05:28 AM

you canít set a browser property (like HTTP-ACCEPT-LANGUAGE) through the server. you can however set your language variable in PHP to your default.

for a switch() statement, everything that is not matched beforehand is covered by the default: section.
Was This Post Helpful? 0
  • +
  • -

#5 Joepiooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-February 10

Re: Set default lang as English

Posted 05 October 2012 - 05:39 AM

View PostDormilich, on 05 October 2012 - 05:28 AM, said:

you canít set a browser property (like HTTP-ACCEPT-LANGUAGE) through the server. you can however set your language variable in PHP to your default.

for a switch() statement, everything that is not matched beforehand is covered by the default: section.


Yes and that is working fine but what I want to realise is that somebody from for example Africa is set to the english text version of the website...

How can I realise that without using HTTP-ACCEPT-LANGUAGE?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3520
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Set default lang as English

Posted 05 October 2012 - 11:14 AM

set your language variable to English. just like the first code block.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1