1
smart2
xlanguage url based language detection
  • 2007/10/6 17:23

  • smart2

  • Not too shy to talk

  • Posts: 129

  • Since: 2007/1/19


I was wondering if xlanguage could detect which langage it has to serve based on base url used.

Example:

One user is browsing XOOPS site with the base url :http://www.example.com, xlanguage serves english language.

One user is browsing the same website but with the base url:
http://www.example.fr and xlanguage serves french.

To make this works, it would be needed to dinamicaly define XOOPS_URL based on the url asked.

For example if someone is browsing http://www.example.com/news, XOOPS_URL should be defined this way:
define(XOOPS_URL,'http://www.ewample.com');

And if someone is browsing http://www.example.fr/news, XOOPS_URL should be defined that way:
define(XOOPS_URL,'http://www.ewample.fr');

I don't know if what I'm asking here is possible.

Thank you for your answers.

2
smart2
Re: xlanguage url based language detection
  • 2007/10/8 2:06

  • smart2

  • Not too shy to talk

  • Posts: 129

  • Since: 2007/1/19


First part can be made like this:

// XOOPS Virtual Path (URL)
// Virtual path to your main XOOPS directory WITHOUT trailing slash
// Example: define('XOOPS_URL', 'http://www.example.com');
$user_headers apache_request_headers();
define('XOOPS_URL''http://'.$user_headers[Host]);


Needs PHP installed as apache module.
Tested and works fine

Need some help to modify xlanguage to detect language with XOOPS_URL now instead of how it's working right now.

3
smart2
Re: xlanguage url based language detection
  • 2007/10/8 10:39

  • smart2

  • Not too shy to talk

  • Posts: 129

  • Since: 2007/1/19


It works fine thanks to Phppp and Dugris for help

This is a rapid hack to make your multinlingual website serve language base on the url asked by the user (with xlanguage).

In this example, if the user is browsing http://www.example.fr, the site will be showing in french and if he's browsing http://www.example.com the site will be showing in english.
This is much better if you care about search engine indexing.
Note that both wwww.example.com and http://www.example.fr should be pointing to the same directory.

I will try to make those changes part of the xlanguage module and submit it to phppp as soon as I find the time.

Modify mainfile.php:

Line 40:
// XOOPS Virtual Path (URL)
// Virtual path to your main XOOPS directory WITHOUT trailing slash
// Example: define('XOOPS_URL', 'http://www.example.com');
$http_host getenv("HTTP_HOST");
define('XOOPS_URL''http://'.$http_host);


Modify /modules/xlanguage/inclule/functions.php:

Line 109:
function xlanguage_detectLang()
{
    global 
$available_languages,$_SERVER;

    
// if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        // $HTTP_ACCEPT_LANGUAGE = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    // }

    // if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        // $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
    // }

    
$lang '';
    
$xoops_lang ='';
    
// 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
    // variable
    // if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
        // $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
        // $acceptedCnt = count($accepted);
        // reset($accepted);
        // for ($i = 0; $i < $acceptedCnt; $i++) {
            // $lang = xlanguage_lang_detect($accepted[$i], 1);
            // if(strncasecmp($lang,'en',2)){
                // break;
            // }
        // }
    // }
    // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
    // if (empty($lang) && !empty($HTTP_USER_AGENT)) {
        // $lang = xlanguage_lang_detect($HTTP_USER_AGENT, 2);
    // }
    // 3. If we catch a valid language, configure it
    // if (!empty($lang)) {
        // $xoops_lang = $available_languages[$lang][1];
    // }

    //Hack by smart
    
$http_host getenv("HTTP_HOST");
    if (
$http_host=='www.example.com'){ //your english url
    
$xoops_lang 'english';
    }
    elseif (
$http_host=='www.example.fr'){  //your french url
    
$xoops_lang 'french';
    }
    else {
    
$xoops_lang 'english';
    }


    return 
$xoops_lang;
}


Hope this helps

Login

Who's Online

326 user(s) are online (256 user(s) are browsing Support Forums)


Members: 0


Guests: 326


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits