Skip to content

Instantly share code, notes, and snippets.

@miya0001
Created October 2, 2011 05:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya0001/1257121 to your computer and use it in GitHub Desktop.
Save miya0001/1257121 to your computer and use it in GitHub Desktop.
WordPressでサイト側の言語を英語に設定しつつadmin_barは日本語で表示する。
<?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;
}
}
}
}
?>
@miya0001
Copy link
Author

miya0001 commented Oct 2, 2011

wp-config.phpで define('SITE_LANG', 'en'); とすれば任意の言語を指定できる。

@miya0001
Copy link
Author

miya0001 commented Oct 2, 2011

マルチサイトは無視してます。たぶんおかしくなる。^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment