Support » Plugins » Replacing gettext.php with PHP’s gettext function

  • The current localization code (wp-l10n, gettext.php, etc.) is really slow. mo files are parsed by PHP instead of system libraries, which has a deep impact on the page rendering times. On my system the framework initialization takes about 300msec without the WP l10n, and about 1500msec with.
    Here is a short guide on how to replace this library with the PHP gettext functions (gettext support has to be compiled in PHP), move locale files to the right directory and drastically reduce page rendering times:
    1. Copy “wp-includes/languages/[locale].mo” to “wp-includes/locale/[locale]/LC_MESSAGES/” (where [locale] = “de_DE”, “fr_FR” or “it_IT”), create the missing directories.
    2. Replace wp-includes/wp-l10n.php with this:
    $parentpath = dirname(dirname(__FILE__));
    $curpath = dirname(__FILE__).'/';
    $locale = '';
    // WPLANG is defined in wp-config.
    if (defined('WPLANG')) {
    $locale = WPLANG;
    if (empty($locale)) {
    $locale = 'en_US';
    setlocale(LC_ALL, $locale);
    bindtextdomain("wordpress", $curpath."locale");
    // Return a translated string.
    function __($text) {
    return gettext($text);
    // Echo a translated string.
    function _e($text) {
    echo gettext($text);
    // Return the plural form.
    function __ngettext($single, $plural, $number) {
    return ngettext($single, $plural, $number);
    require($curpath . 'locale.php');

    3. Set the right locale in wp-config.php (e.g. “de_DE” for german, “de” will not work)

Viewing 9 replies - 1 through 9 (of 9 total)
  • yeah, what moshu said.
    eager to speed up WP!
    : )

    1. Yes. the file is the language you want to install.
    It’s like every other mo file on a Unix system, they are named after the application and in the LC_MESSAGE directory of the language.
    so has to be copied to
    wp-includes/locale/de_DE/LC_MESSAGES/ to
    and so on.
    2. Yes, this is the new content of wp-l10n.php.
    Tested this on WP 1.3-alpha-4, but wp-l10n.php hasn’t changed since 1.2, so this should work for 1.2 as well.
    3. I don’t really know if gettext support is compiled in PHP by default.
    However it is compiled in by default on Debian, maybe other distributions also. So I think there’s a real change of having gettext already compiled in in a virtual hosting environment.



    I have done so.
    I get this errormessage:
    “Fatal error: Call to undefined function bindtextdomain() in S:\apachefriends\xampp\htdocs\wordpress\wp-includes\wp-l10n.php on line 20”
    Any idea what’s wrong??

    Your php doesn’t have gettext support.
    Also, setlocale() can be very problematic since it is dependent on server configuration. BSD is slightly different than Linux which is different than Windows, … You have to experiment to find out what works with your host.



    thanks ūüôā
    you know an other way to show WP in german? in wp-includes/languages/ causes many errormessages like this:
    “Warning: fread() [function.fread]: Length parameter must be greater than 0. in S:\apachefriends\xampp\htdocs\wordpress\wp-includes\streams.php on line 107
    Warning: Cannot modify header information – headers already sent by (output started at S:\apachefriends\xampp\htdocs\wordpress\wp-includes\streams.php:107) in S:\apachefriends\xampp\htdocs\wordpress\wp-login.php on line 167

    Thank y0u for any help.



    Check out this fix for your porblem:



    hi moshu … thanks! :-)))
    Now it looks a little bit more german.

    Anyone knows how to do this in 1.5?? I have modified wp-l10n.php but it seems to be diferent from 1.2.2 and don’t work it as expected.

    Still looking for a solution on this. I’d really like to replace php-gettext with the gettext library.

    So if anyone (nicokaiser?) know, please let us know as well.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Replacing gettext.php with PHP’s gettext function’ is closed to new replies.