WordPress and problem with language files (.mo)

While testing the upcoming WordPress 2.3 I noticed that I had a problem with he localization. Defining the language with WPLANG had no effects and all the text were in English as they should have been in Finnish. I installed another instance of WordPress 2.2.3 and the problem was still there. Somewhat confusing because I had a working WordPress instance with the same PHP-version (php-5.2.4_pre200708051230-r2). The only difference was that the other box was 32-bit system and the other 64-bit. Although at that time I didn’t know what to look for.

After some googling I found a Spanish-blog which explained the “bug” and provided a solution. Unfortunately I don’t speak Spanish but the solution was clear with pieces of code to show the way. After I knew what to look for I found some discussions about this topic on WordPress Trac and an entry 2 weeks ago with a patch gettext-64-without-bitwise-ops.diff seems to get the thing fixed.

The problem is in the PHP-gettext which is used for translating strings. The file is located at wp-includes/gettext.php and in that file the problem is created by fixing a bug in PHP 5.0.2 on 64-bit systems. The counterfix is luckily an easy one and you just have to remove some bitwise operators.

The solution with problematic line on red and the fix on green:

wp-includes/gettext.php
$this->STREAM = $Reader;
$magic = $this->readint();
117c117
< if ($magic == ($MAGIC1 & 0xFFFFFFFF) || $magic == ($MAGIC3 & 0xFFFFFFFF)) { // to make sure it works for 64-bit platforms
---
> if ($magic == $MAGIC1 || $magic == $MAGIC3) { // to make sure it works for 64-bit platforms
>	$this->BYTEORDER = 0;
> } elseif ($magic == ($MAGIC2 & 0xFFFFFFFF)) {
>	$this->BYTEORDER = 1;

The search engines <3

Update, 2008-02-05:
With WordPress 2.3.3 this bug is finally closed with some other minor bug fixes and security fix for xmlrpc.php.


Posted

in

by

Tags:

Comments

20 responses to “WordPress and problem with language files (.mo)”

  1. Christian J Avatar
    Christian J

    You saved my day! Been looking at this problem for hours!

  2. […] are probably either missing, have the wrong names, or are in the wrong places. Or, it could be this bug in WordPress’s "gettext" functionality, which has to do with whether your web site is running on a computer with a 64-bit processor, or a […]

  3. Marko Avatar
    Marko

    It’s nice to see that this post has helped so many.

  4. xbmw Avatar

    I`ve resolved the problem! Thanks a lot!

  5. […] are probably either missing, have the wrong names, or are in the wrong places. Or, it could be this bug in WordPress’s “gettext” functionality, which has to do with whether your web site is running on a computer with a 64-bit processor, or a […]

  6. Manuel Avatar
    Manuel

    Thank you very much!!!!!

  7. […] Auf 64bit-Servern kam es bei älteren WordPress-Versionen gelegentlich vor, dass das Datum statt in der gewählten Sprache immer noch in Englisch angezeigt wurde. Das Problem ging auf einen Bug in PHP 5 zurück und betraf gettext.php. […]

  8. lpktk Avatar

    Thank you! :)

  9. Tommi Avatar
    Tommi

    Thank you for this advice. I was so lost with this same problem and the fix was such an easy one when knowing where to hack.

  10. thekraken Avatar
    thekraken

    Never mind. My mistake. (’WPLANG’, ‘FI_fi’) did the trick. evo.

  11. thekraken Avatar
    thekraken

    Not working for me! I have define (‘WPLANG’, ‘fi’); in wp-config.php and I fixed the line on gettext.php. Nothing changes. Still in english.

  12. Marko Avatar
    Marko

    This issue seems to be continuing without a proper resolution (gettext.php fixed in WP) although it has been marked as closed in WordPress Trac. The fix is easy but they haven’t from some reasons added it to the release versions of WordPress.

    In the mean time it’s nice to see that this post helps to get things fixed.

  13. Lars-G. Paulsen Avatar

    Problem is still there after Versjon 2.3.2….

    This post was a life saver… :P thnx a bunch!

  14. Nicole Avatar
    Nicole

    thanks so much!! this happened to me randomly in wp 2.3 and this post was a lifesaver.

  15. Matt Avatar

    I can confirm that this bug still exists with WP 2.3.1 and PHP 5.2.3 man, this was aggravating. thanks for the tip!

  16. Marko Avatar
    Marko

    I haven’t tested the new version of WP in 64-bit environment with the newest PHP but if I recall correctly, the gettext.php is same as before.

  17. DesignLinks.cn Avatar

    wp 2.3.1 the problem still has?

  18. WordPress 在 PHP5 下的語系問題

  19. […]         在浅文 提供的线索:  http://ruleoftech.wordpress.com/ … -language-files-mo/ 里我找到了答案. […]

Leave a Reply

Your email address will not be published. Required fields are marked *