Language setting based on ccTLD

Any suggestions on how to improve qTranslate? Post here!

Re: Language setting based on ccTLD

Postby nedercraft » Tue Mar 13, 2012 6:56 pm

I myself have been trying to setup qTranslate for two TLD's: .com and .nl

Website regarding this: nedercraft.nl - nedercraft.com

QianQin could you help us out on having translation by TLD?

------------------------------------------------------------------------
Update: One step further, problem now.
As you can see on Nedercraft.com and Nedercraft.nl , headers and sidebars / widgets are translated perfectly as well as the other hardcoded translations in theme files.
But the content is not switched.

Code: Select all
$x1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$x2  = str_replace("www.", "", $x1); 
$x3  = str_replace("/", "", $x2);

if ($x3 == "nedercraft.com" ) {
define('WP_SITEURL', 'http://www.nedercraft.com');
define('WP_HOME', 'http://www.nedercraft.com');
define('WPLANG', 'en_EN');

} else {
define('WP_SITEURL', 'http://www.nedercraft.nl');
define('WP_HOME', 'http://www.nedercraft.nl');
define('WPLANG', 'nl_NL');
}

define('WP_SITEURL', 'http://www.' . $x3);
define('WP_HOME', 'http://www.' . $x3);

Added this code into wp-config.php


Code: Select all
<?php
$x4  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);

$x5  = str_replace("www.", "", $x4); 
$x6  = str_replace("/", "", $x5);

if ($x6 == "nedercraft.com" ) {
$q_config['language'] = "en";
$q_config['default_language'] = "en";
} else {
$q_config['language'] = "nl";
$q_config['default_language'] = "nl";
}
?>

<?php get_header(); ?>

EDIT 2: Found the problem, add this code into functions.php in your theme file to set the language before anything else is loaded.


I now have to re do some part of my website to get this all working neatly. Ill report back with my used end codes.
nedercraft
 
Posts: 3
Joined: Tue Mar 13, 2012 6:51 pm

Re: Language setting based on ccTLD

Postby Sundark » Wed Aug 15, 2012 1:34 pm

bjourne wrote:Step 2: Add something like this to the end of qtrans_extractURL
function in qtranslate_core.php:

Code: Select all
        $ccTLD = end(explode('.', $host));
   if ($ccTLD == 'com')
      $result['language'] = 'en';
   else
      $result['language'] = $ccTLD;
   return $result;


Hello, first of all, THANKS, your hack works very great.

By the way, I found an error, if I can call it like that, it can happend that a user add a "." at the end of the domain name.

=> www.domainname.com.
The domain should works, but your $ccTLD parameter in the second step will be string(0) ""

should be
Code: Select all
   $ccTLD = end(explode('.', $host));
    if($ccTLD == 'com' || $ccTLD == '')
        $result['language'] = 'en';
    else   
        $result['language'] = $ccTLD;
   return $result;
Sundark
 
Posts: 1
Joined: Wed Aug 15, 2012 1:32 pm

Re: Language setting based on ccTLD

Postby kasperh » Mon Sep 10, 2012 9:08 am

I think this is a highly needed feature in qTranslate and should be pretty easy to implement.

Qian: Maybe you should put the plugin on github, so other people can contribute to it. :)
kasperh
 
Posts: 1
Joined: Mon Sep 10, 2012 9:01 am

Previous

Return to qTranslate Suggestions Forum

Who is online

Users browsing this forum: No registered users and 1 guest