multi language - Setting WPLANG from a plugin

For a single site wordpress, the language must be set from wp-config.php's WPLANG, but is it possible to set from m

For a single site wordpress, the language must be set from wp-config.php's WPLANG, but is it possible to set from my plugin which override the default value?

For a single site wordpress, the language must be set from wp-config.php's WPLANG, but is it possible to set from my plugin which override the default value?

Share Improve this question edited May 17, 2012 at 11:39 Stephen Harris 32.6k6 gold badges84 silver badges118 bronze badges asked May 17, 2012 at 8:52 HowardHoward 1131 gold badge5 silver badges15 bronze badges 1
  • 1 The link also appears at the right column of this page, but I think it's worth noting in the comments another approach for a similar situation: wordpress.stackexchange/a/53678/12615 – brasofilo Commented May 31, 2012 at 21:00
Add a comment  | 

1 Answer 1

Reset to default 17

In wp-includes/l10n.php you will find the function get_locale(). It offers a filter; you can set the language and ignore the constant:

function get_locale() {
    global $locale;

    if ( isset( $locale ) )
        return apply_filters( 'locale', $locale );

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

    // If multisite, check options.
    if ( is_multisite() ) {
        // Don't check blog option when installing.
        if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) )
            $ms_locale = get_site_option('WPLANG');

        if ( $ms_locale !== false )
            $locale = $ms_locale;
    }

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

    return apply_filters( 'locale', $locale );
}

To change it per plugin use the filter 'locale'. Example:

add_filter( 'locale', 'wpse_52419_change_language' );
function wpse_52419_change_language( $locale )
{
    return 'de_DE';
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744936381a4602051.html

相关推荐

  • multi language - Setting WPLANG from a plugin

    For a single site wordpress, the language must be set from wp-config.php's WPLANG, but is it possible to set from m

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信