WordPress 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.


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.