WordPress.org

Ready to get started?Download WordPress

Forums

HOWTO- Replace gettext.php with PHP's built-in gettext - WordPress 1.5! (1 post)

  1. iwscol
    Member
    Posted 8 years ago #

    this comes the result from my previous post about the gettext annoyance. if any of you is having trouble seeing an "expected" localized WordPress on your server... by not seeing it getting localized... follow the following the get rid of the annoying gettext.php feature and return to the old-school PHP's gettext functions. this might give you a good day!

    thanks to the guy who wrote the guide for previous version of WordPress... i derived these steps from him, most credits should to to him as well...

    1. Copy "wp-includes/languages/[locale].mo" to "wp-includes/locale/[locale]/LC_MESSAGES/wordpress.mo" (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_));
    require_once($parentpath.'/wp-config.php');
    $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");
    textdomain("wordpress");

    function get_locale() {
    global $locale;

    if (isset($locale))
    return $locale;

    // WPLANG is defined in wp-config.
    if (defined('WPLANG')) {
    $locale = WPLANG;
    }

    if (empty($locale)) {
    $locale = 'en_US';
    }

    $locale = apply_filters('locale', $locale);

    return $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');

    function load_textdomain($domain, $mofile) {
    //global $l10n;

    //if (isset($l10n[$domain])) {
    //return;
    //}

    //if ( is_readable($mofile)) {
    // $input = new CachedFileReader($mofile);
    //} else {
    //return;
    //}

    //$l10n[$domain] = new gettext_reader($input);
    }

    function load_default_textdomain() {
    //global $l10n;

    //$locale = get_locale();
    //$mofile = ABSPATH . "wp-includes/languages/$locale.mo";

    //load_textdomain('default', $mofile);
    }

    function load_plugin_textdomain($domain) {
    //$locale = get_locale();

    //$mofile = ABSPATH . "wp-content/plugins/$domain-$locale.mo";
    //load_textdomain($domain, $mofile);
    }

    function load_theme_textdomain($domain) {
    //$locale = get_locale();

    //$mofile = get_template_directory() . "/$locale.mo";
    //load_textdomain($domain, $mofile);
    }

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

    as you might have noticed in step 2, i simply commented out those functions... DON'T delete them or else WordPress won't work!

    cheers and good luck!~ :-)

Topic Closed

This topic has been closed to new replies.

About this Topic