Created
October 2, 2011 05:55
-
-
Save miya0001/1257121 to your computer and use it in GitHub Desktop.
WordPressでサイト側の言語を英語に設定しつつadmin_barは日本語で表示する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Switch Locale | |
Author: Takayuki Miyauchi | |
Plugin URI: http://firegoby.theta.ne.jp/wp/switch-locale | |
Description: Set selected langs for your site. | |
Author: Takayuki Miyauchi | |
Version: 0.1.0 | |
Author URI: http://firegoby.theta.ne.jp/ | |
Domain Path: /languages | |
Text Domain: switch-locale | |
*/ | |
new SwicthLocale(); | |
class SwicthLocale { | |
private $site_lang = 'en'; | |
private $wp_lang = null; | |
private $switch_flag = true; | |
function __construct() | |
{ | |
add_action('init', array(&$this, 'init')); | |
add_action('wp_before_admin_bar_render', array(&$this, 'before_admin_bar')); | |
add_action('wp_after_admin_bar_render', array(&$this, 'after_admin_bar')); | |
} | |
public function init() | |
{ | |
$this->wp_lang = get_locale(); | |
add_filter('locale', array(&$this, 'locale')); | |
} | |
public function before_admin_bar() | |
{ | |
$this->switch_flag = false; | |
printf('<div lang="%s">', esc_attr($this->wp_lang)); | |
} | |
public function after_admin_bar() | |
{ | |
$this->switch_flag = true; | |
echo "</div>"; | |
} | |
public function locale() | |
{ | |
if (!is_admin() && $this->switch_flag) { | |
if (defined("SITE_LANG")) { | |
return SITE_LANG; | |
} else { | |
return $this->site_lang; | |
} | |
} | |
} | |
} | |
?> |
マルチサイトは無視してます。たぶんおかしくなる。^^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp-config.phpで
define('SITE_LANG', 'en');
とすれば任意の言語を指定できる。