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.
