February 17th, 2007WordPress Global Translator and FireStats
Update: For those of you interested in getting Global Translator 0.6 to work with FireStats, go here.
I’ve had several requests from people who use Omry Yadan’s FireStats and want to use Davide Pozza’s Global Translator Plugin, as the two plugins tend to behave poorly together. For anyone that hasn’t used these two together, what happens is the wrong source page is sent to the Google Translation service, and readers receive either a 404 or a white blank page. This appears to be a mod_rewrite issue that only affects Global Translator. Luckily, there is a very quick and dirty fix that will resolve the issue.
First off, I’d like to say that this fix has been tested on both WordPress 2.0.x and 2.1 with FireStats 1.1.0 through to the current 1.1.5 Stable and Global Translator 0.4.1. I have not updated to the most current version of Global Translator because this one suits my needs just fine.
Now the fun stuff.
There are only two lines that need to be changed in the translator.php file found in your /wp-content/plugins/global-translator/ directory, and in the translate function.
$url_to_translate = BLOG_HOME . ‘/’ . $url;
should be changed to:
$url_to_translate = preg_replace(’(it|ko|zh-CN|pt|en|de|fr|ja|es|ar|//)’, ”, $_SERVER['REQUEST_URI']);
And below that:
$resource = $translator_base_url . $language . ‘&u=’ . $url_to_translate;
should be changed to:
$resource = $translator_base_url . $language . ‘&u=’ . BLOG_HOME . $url_to_translate;
These changes eliminate the $url variable’s use from the translate($lang, $url) function, but the second variable should not be removed from the definition. This is not a complete solution to the matter, but it’s a quick solution that will work for the majority of sites.
Keep in mind that you need to use “Date and Name based” permalinks and your .htaccess file should be updated acccordingly (this is done by WordPress automatically if the appropriate permissions have been granted). All of this is outlined in the Global Translator instructions, but it’s a critical component that I’ve seen missed elsewhere.
For anyone that has not used these plugins, I highly recommend them. The Global Translator is a great way to help foreign visitors enjoy your site (despite the occasional inaccuracies in machine translation), and FireStats will give you a great idea of where your readers are coming from and what browsers they’re using. This last point is important if you are designing sites to be optimized for certain browsers.
If there are any questions with this change, just drop me a line. I’ll be sure to offer what help I can.
Update:
As requested, here is the modified translator.php file that I use on this site. Please note that this is from version 0.4.1 rather than the current release.
Before using this file, please make sure that your site has the “WordPress should compress articles (gzip) if browsers ask for them)” checkbox cleared. This can be found in the Options menu, under Reading, down at the very bottom. Several users have reported that after this is cleared out, Global Stats will work without fail on their site.
Enjoy,















































Hi Jason,
Would you mind explaining this bug to me and what you think should be changed in FireStats?
you can do it in this ticket:
http://firestats.cc/ticket/202
thanks.
Thanks! i will upgrade to 0.5 now that you have a way to get it to work!
Done and done.
I don’t think anything should be changed in FireStats, as this issue seems to only crop up with the Global Translator. That plugin’s use of $_SERVER[PHP_SELF] seems to be the problem.
That said, hopefully my quick fix will let people enjoy both plugins.
Thanks,
hi Jason
if i change it like you said then i get problem like:
Parse error: parse error, unexpected ‘;’ in /var/www/vhosts/travel-carrental.com/httpdocs/wp-content/plugins/global-translator/translator.php on line 139
i think copy make mistake.
can you me with xx.php send to mir bye mail?
thanks
Done and done.
Let me know if you have any problems.
Actually could you post that fix, pls? I don’t run FireStats but I did run into the white page issue. (I do run BAStats so maybe that’s causing it.) When I made the edits posted I got the same error martin got. If not, could you email that fix to me as well? Thankee.
Done.
Before using this file, please make sure that your site has the “WordPress should compress articles (gzip) if browsers ask for them)” checkbox cleared. This can be found in the Options menu, under Reading, down at the very bottom. Several users have reported that after this is cleared out, Global Stats will work without fail on their site.
[...] Yesterday Global Translator 0.6-beta was released, and I was interested to know how it would run. This version comes with support for both Google Translator and BabelFish, and will permit pages to be cached for faster loading. The only downside to this version was it’s inability to play nice with Omry Yadan’s FireStats. But since I really enjoy both of these plugins, I thought that I would make the effort and find a way to make these work together like I had for version 0.4.1. [...]