| @@ -6,12 +6,12 @@ | ||
| 6 | 6 | Author: Takayuki Miyoshi |
| 7 | 7 | Author URI: http://ideasilo.wordpress.com/ |
| 8 | 8 | Text Domain: bogo |
| 9 | 9 | Domain Path: /languages/ |
| 10 | -Version: 2.7 | |
| 10 | +Version: 2.9 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -define( 'BOGO_VERSION', '2.7' ); | |
| 13 | +define( 'BOGO_VERSION', '2.9' ); | |
| 14 | 14 | |
| 15 | 15 | define( 'BOGO_PLUGIN', __FILE__ ); |
| 16 | 16 | |
| 17 | 17 | define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) ); |
| @@ -20,8 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) ); |
| 22 | 22 | |
| 23 | 23 | require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 24 | +require_once BOGO_PLUGIN_DIR . '/includes/pomo.php'; | |
| 24 | 25 | require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 25 | 26 | require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 26 | 27 | require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php'; |
| 27 | 28 | require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; |
| @@ -30,8 +31,9 @@ | ||
| 30 | 31 | require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| 31 | 32 | require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; |
| 32 | 33 | require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 33 | 34 | require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; |
| 35 | +require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php'; | |
| 34 | 36 | |
| 35 | 37 | if ( is_admin() ) { |
| 36 | 38 | require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; |
| 37 | 39 | } |
| @@ -45,14 +47,16 @@ | ||
| 45 | 47 | add_action( 'init', 'bogo_init' ); |
| 46 | 48 | |
| 47 | 49 | function bogo_init() { |
| 48 | 50 | bogo_languages(); |
| 51 | + Bogo_POMO::import( get_locale() ); | |
| 49 | 52 | |
| 50 | 53 | if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { |
| 51 | 54 | $locale = get_locale(); |
| 52 | 55 | |
| 53 | - if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) | |
| 56 | + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) { | |
| 54 | 57 | setcookie( 'lang', $locale, 0, '/' ); |
| 58 | + } | |
| 55 | 59 | } |
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 62 | add_filter( 'locale', 'bogo_locale' ); |
| @@ -59,21 +63,31 @@ | ||
| 59 | 63 | |
| 60 | 64 | function bogo_locale( $locale ) { |
| 61 | 65 | global $wp_rewrite, $wp_query; |
| 62 | 66 | |
| 63 | - if ( ! did_action( 'plugins_loaded' ) ) | |
| 67 | + if ( ! did_action( 'plugins_loaded' ) ) { | |
| 64 | 68 | return $locale; |
| 69 | + } | |
| 65 | 70 | |
| 66 | - if ( is_admin() ) | |
| 67 | - return bogo_get_user_locale(); | |
| 71 | + static $bogo_locale = ''; | |
| 68 | 72 | |
| 73 | + if ( $bogo_locale ) { | |
| 74 | + return $bogo_locale; | |
| 75 | + } | |
| 76 | + | |
| 77 | + if ( is_admin() ) { | |
| 78 | + return $bogo_locale = bogo_get_user_locale(); | |
| 79 | + } | |
| 80 | + | |
| 69 | 81 | $default_locale = bogo_get_default_locale(); |
| 70 | 82 | |
| 71 | 83 | if ( ! empty( $wp_query->query_vars ) ) { |
| 72 | - if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) ) | |
| 73 | - return $closest; | |
| 74 | - else | |
| 75 | - return $default_locale; | |
| 84 | + if ( ( $lang = get_query_var( 'lang' ) ) | |
| 85 | + && $closest = bogo_get_closest_locale( $lang ) ) { | |
| 86 | + return $bogo_locale = $closest; | |
| 87 | + } else { | |
| 88 | + return $bogo_locale = $default_locale; | |
| 89 | + } | |
| 76 | 90 | } |
| 77 | 91 | |
| 78 | 92 | if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { |
| 79 | 93 | $url = is_ssl() ? 'https://' : 'http://'; |
| @@ -82,26 +96,26 @@ | ||
| 82 | 96 | |
| 83 | 97 | $home = set_url_scheme( get_option( 'home' ) ); |
| 84 | 98 | $home = trailingslashit( $home ); |
| 85 | 99 | |
| 86 | - $available_languages = bogo_available_languages(); | |
| 87 | - $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) ); | |
| 88 | - $available_languages = implode( '|', $available_languages ); | |
| 89 | - $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#'; | |
| 100 | + $available_locales = bogo_available_locales(); | |
| 101 | + $available_locales = array_map( 'bogo_lang_slug', $available_locales ); | |
| 102 | + $available_locales = implode( '|', $available_locales ); | |
| 103 | + $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#'; | |
| 90 | 104 | |
| 91 | 105 | if ( preg_match( $pattern, $url, $matches ) |
| 92 | - && $closest = bogo_get_closest_locale( $matches[1] ) ) | |
| 93 | - return $closest; | |
| 106 | + && $closest = bogo_get_closest_locale( $matches[1] ) ) { | |
| 107 | + return $bogo_locale = $closest; | |
| 108 | + } | |
| 94 | 109 | } |
| 95 | 110 | |
| 96 | 111 | $lang = bogo_get_lang_from_url(); |
| 97 | 112 | |
| 98 | - if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) | |
| 99 | - return $closest; | |
| 113 | + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) { | |
| 114 | + return $bogo_locale = $closest; | |
| 115 | + } | |
| 100 | 116 | |
| 101 | - $locale = $default_locale; | |
| 102 | - | |
| 103 | - return $locale; | |
| 117 | + return $bogo_locale = $default_locale; | |
| 104 | 118 | } |
| 105 | 119 | |
| 106 | 120 | add_filter( 'query_vars', 'bogo_query_vars' ); |
| 107 | 121 | |