Language setting based on ccTLD

Any suggestions on how to improve qTranslate? Post here!

Language setting based on ccTLD

Postby bjourne » Wed Oct 07, 2009 3:43 pm

Hello everybody,

I like this plugin very much, but it seem to lack the ability to
select language based on the ccTLD of the request. So I added some
hacks to qTranslate to enable it, maybe it can be useful for someone
else with the same problem too.

Step 1: Add define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); to
wp-config.php. This is needed for wp serve the same blog on multiple
domains. Obviously, you must also have configured your DNS to point
these domains to the same wordpress instance. :)

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;


This overrides the existing way qTranslate determines which language
to serve. The default language is set to English if the request came
to a .com domain otherwise, use the country code top level domain
name. Modify this to your liking and add more if-clauses for .biz,
.org and .edu domains etc.

Step 3: Replace all code in qtrans_convertURL in qtranslate_core.php
so that it looks like:

Code: Select all
        function qtrans_convertURL($url='', $lang='', $forceadmin = false) {
            return $url;
        }


URL:s doesn't have to be translated anymore because each language is
kept on its separate domain.

Step 3: This is needed if you are using the language selector
widget. Because different languages are on different domains, some
stuff has to be coded differently to get it to work. First add this
function to qtranslate_widget.php:

Code: Select all
        function qtrans_domainURL($ignore, $language) {
            $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);

                 $hostParts = explode(".", $_SERVER['SERVER_NAME']);
                 $ccTLD = "com";
                 if ($language != 'en')
                         $ccTLD = $language;
                 $hostParts[count($hostParts) - 1] = $ccTLD;
                 $host = implode(".", $hostParts);
   
                 // REQUEST_URI only works for Apache.
                 $domainURL = "http://" . $host . $port . $_SERVER['REQUEST_URI'];
                 return $domainURL;
        }


Then in qtrans_generateLanguageSelectCode in the same file, replace
all calls to qtrans_convertURL with calls to qtrans_domainURL.

That's all it takes. I'm a newbie to both qTranslate and WordPress to
Caveat Emptor, but it appear to work fine for me and I haven't noticed
any problems yet.
bjourne
 
Posts: 1
Joined: Wed Oct 07, 2009 3:40 pm

Re: Language setting based on ccTLD

Postby digitaldonkey » Wed Mar 31, 2010 7:19 pm

Anyone can confirm it working? :?

:idea: For SEO reasons I need to set up WP with multiple languages and corresponding domains.


Is a feature like the planed in a core release?
:roll:
digitaldonkey
 
Posts: 6
Joined: Mon Feb 22, 2010 12:54 pm

Re: Language setting based on ccTLD

Postby Qian Qin » Tue Apr 20, 2010 1:15 pm

sounds great, but that will need some more testing i can't do right now. but i think i'll include that in a future release.
Qian Qin
Site Admin
 
Posts: 964
Joined: Thu Jun 19, 2008 12:14 pm
Location: Germany

Re: Language setting based on ccTLD

Postby keb » Fri Sep 03, 2010 12:42 am

i also have a single wordpress site sitting on two different language domain names. are these modifications working for qTranslate 2.5.7 or later?
keb
 
Posts: 1
Joined: Fri Sep 03, 2010 12:40 am

Re: Language setting based on ccTLD

Postby grio » Thu May 05, 2011 5:28 pm

Thank you, good fairyman! :D

Patch works on WP 3.1.2 + qTranslate 2.5.20

2 qTranslate developers:
ccTLD must be added as option to Advanced Settings of qTranslate Configuration.
Please!!! :D

P.S.
This solution have a problem with a stay logged in then domains (languages) are switching.

P.P.S.
About stay signed, I have found this plugin: http://wordpress.org/extend/plugins/domain-theme/
There is no problem with authoring on the other domain, but this is a different authoring for each domain.

br,
grio.
grio
 
Posts: 2
Joined: Thu May 05, 2011 5:18 pm

Re: Language setting based on ccTLD

Postby grio » Thu May 05, 2011 10:59 pm

small additional code needed in wp-config.php for some plugins, to help works it properly.

Code: Select all
$ccTLD = end(explode('.', $_SERVER['HTTP_HOST']));
   if ($ccTLD == 'com')
define('WPLANG', 'en_US');
   else
define('WPLANG', 'ru_RU'); //or other language


br,
grio.
grio
 
Posts: 2
Joined: Thu May 05, 2011 5:18 pm

different domain names

Postby eiland » Fri Jul 08, 2011 7:20 pm

Two issues I see;

For if the different language domains don't have the samen domain name, I modified the code up here to read

Code: Select all
function qtrans_domainURL($ignore, $language) {
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
$hostParts = explode(".", $_SERVER['SERVER_NAME']);
$ccTLD = "com";
if ($language != 'en')
$ccTLD = $language;
count($hostParts) - 1] = $ccTLD;
$host = implode(".", $hostParts);
// REQUEST_URI only works for Apache.
$domainURL = "http://" . $host . $port . $_SERVER['REQUEST_URI'];
$domainURL=str_replace("DomainNameDutch.de", "DomainNameGerman.de",  $domainURL);
$domainURL=str_replace("DomainNameGerman.nl", "DomainNameDutch.nl",  $domainURL);
return $domainURL;
}


Another issue is that if a post is not translated, qtranslate replies "Leider ist der Eintrag nur auf Nederlands verfügbar." with Nederlands being a link to the German domain. Haven't gotten around to fix that.
eiland
 
Posts: 7
Joined: Mon Jun 27, 2011 1:41 pm

Re: Language setting based on ccTLD

Postby Meow » Thu Feb 09, 2012 9:34 am

I think this should really be added to qTranslate.
+1
Meow
 
Posts: 10
Joined: Wed Dec 21, 2011 2:27 am

Re: Language setting based on ccTLD

Postby fyllhund » Thu Mar 01, 2012 1:31 pm

Can anyone confirm if this still works?

Cheers!
fyllhund
 
Posts: 4
Joined: Fri Jan 13, 2012 12:28 pm

Re: Language setting based on ccTLD

Postby sandries » Sun Mar 04, 2012 10:21 pm

bump. same question; does this still work?
sandries
 
Posts: 4
Joined: Tue Feb 14, 2012 12:19 pm

Next

Return to qTranslate Suggestions Forum

Who is online

Users browsing this forum: No registered users and 3 guests