Changeset 676953
- Timestamp:
- 03/06/2013 04:56:12 PM (11 years ago)
- Location:
- wcm-user-language-switcher/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
wcm-user-language-switcher/trunk/.gitignore
r654894 r676953 2 2 .DSSTORE 3 3 .gitignore 4 5 6 4 7 5 8 # SVN … … 20 23 .settings 21 24 22 # PSD 23 .psd/*24 . psd25 # PSD 26 /* 27 . -
wcm-user-language-switcher/trunk/README.md
r654894 r676953 3 3 <img width="150" height="150" src="https://raw.github.com/wecodemore/wcm_lang_switch/master/assets/logo.png" /> 4 4 5 **Contributors:** [Stephen Harris](https://github.com/stephenh 1988), [Franz Josef Kaiser](https://github.com/franz-josef-kaiser)5 **Contributors:** [Stephen Harris](https://github.com/stephenh), [Franz Josef Kaiser](https://github.com/franz-josef-kaiser) 6 6 **Tags:** Language, switcher, localisation 7 **Tested up to:** 3.5 8 **Stable tag:** 1. 6.19 **Requires at least:** 3.5 7 **Tested up to:** 3.5 8 **Stable tag:** 1..1 9 **Requires at least:** 3.5 10 10 **License:** GPL3 11 11 **License URI:** http://www.gnu.org/licenses/gpl-3.0.html … … 28 28 Extract the zip file and just drop the contents in the `~/wp-content/plugins/` directory of your WordPress installation and then activate the Plugin from Plugins page. 29 29 30 30 It scans the language directory to build the list of available languages. To add a language, simple [download the appropriate mo file](http://codex.wordpress.org/WordPress_in_Your_Language) and add to your WordPress `languages` folder. 31 31 32 32 This plugin was originally built as a means of plugin and theme developers to test translations of their plugins or themes. … … 40 40 <?php 41 41 /* Plugin Name:** (WCM) Add additional languages */ 42 add_filter( ' uls_get_langs', 'wcm_add_languages' );42 add_filter( '_get_langs', 'wcm_add_languages' ); 43 43 function wcm_add_languages( $languages ) 44 44 { … … 57 57 58 58 ## Changelog ## 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 59 94 60 95 ### 1.6 ### -
wcm-user-language-switcher/trunk/dev_tools.class.php
r654894 r676953 8 8 * @since 1.3 9 9 */ 10 class WCM UserLangSelectDevTools extends WCMUserLangSelect10 class WCM 11 11 { 12 12 public function __construct() … … 71 71 // If we found one, assign it to the array, else empty 72 72 $nn = ! $nn ? $string : ucwords( $native[ $nn ]['nativeName'] ); 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 73 126 $output[ $l ] = array( 74 'int' => $string75 ,'native' => $nn127 'int' => 128 ,'native' => 76 129 ); 77 130 } … … 81 134 return; 82 135 83 # Test if native strings work 84 # foreach ( $output as $k => $v ) 85 # printf ( "<p>%s</p>", $v['native'] ); 86 87 $output = json_encode( $output ); 88 $output_raw = $this->beautify_json( $output ); 89 136 # Output for a complete ISO 639-2 list 137 /* printf( 138 '<textarea rows="5" cols="104">%s</textarea>' 139 ,json_encode( $output ) 140 );*/ 141 142 // Only use the first string for WP UI 143 foreach ( $output as $code => $out ) 144 foreach ( $out as $k => $o ) 145 { 146 $output[ $code ][ $k ] = array_shift( $o ); 147 } 148 149 printf ( '<p>%s</p>', 'Number of languages' ); 150 printf( 151 '<input type="text" value="%s" />' 152 ,count( $output ) 153 ); 90 154 printf ( '<p>%s</p>', 'Readable' ); 91 155 printf( 92 156 '<textarea rows="5" cols="104">%s</textarea>' 93 ,$ output_raw157 ,$ 94 158 ); 95 159 printf ( '<p>%s</p>', 'Compressed' ); 96 160 printf( 97 161 '<textarea rows="5" cols="104">%s</textarea>' 98 , $output162 , 99 163 ); 100 164 101 165 return; 102 166 # Remove the above `return;` to get a DIFF of the changes 103 $this->diff_json( $ output_raw);167 $this->diff_json( $ ); 104 168 } 105 169 … … 143 207 $output_current = file_get_contents( plugin_dir_path( __FILE__ ).'/json/lang_codes.json' ); 144 208 print wp_text_diff( 145 var_export( $output_current, true )209 var_export( $output_current, true ) 146 210 ,var_export( $output_remote, true ) 147 211 ,array( 148 'title' => 'Dev: Changes since last JSON file fetch'149 ,'title_left' => 'Current data'150 ,'title_right' => 'New fetched data'212 'title' => 'Dev: Changes since last JSON file fetch' 213 ,'title_left' => 'Current data' 214 ,'title_right' => 'New fetched data' 151 215 ) 152 216 ); -
wcm-user-language-switcher/trunk/readme.txt
r654894 r676953 2 2 Contributors: stephenharris, F J Kaiser 3 3 Tags: Language, switcher, localisation 4 Tested up to: 3.5 5 Stable tag: 1. 6.14 Tested up to: 3.5 5 Stable tag: 1..1 6 6 Requires at least: 3.5 7 7 License: GPL3 … … 38 38 <?php 39 39 /* Plugin Name: (WCM) Add additional languages */ 40 add_filter( ' uls_get_langs', 'wcm_add_languages' );40 add_filter( '_get_langs', 'wcm_add_languages' ); 41 41 function wcm_add_languages( $languages ) 42 42 { … … 54 54 55 55 == Changelog == 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 56 91 57 92 = 1.6 = -
wcm-user-language-switcher/trunk/wcm_lang_switch.class.php
r654894 r676953 1 1 <?php 2 ! defined( 'ABSPATH' ) ANDexit;2 exit; 3 3 /* 4 4 Plugin Name: User Language Switcher … … 7 7 Author: Stephen Harris 8 8 Author URI: https://plus.google.com/b/109907580576615571040/109907580576615571040/posts 9 Contributors: Franz Josef Kaiser 10 Version: 1. 6.19 Contributors: Franz Josef Kaiser 10 Version: 1..1 11 11 License: GNU GPL 3 12 12 */ … … 14 14 15 15 # PUBLIC API # 16 17 18 19 20 21 22 23 24 25 26 27 16 28 /** 17 29 * A function returns with returns the user's selected locale, if stored. 18 30 * 19 31 * @since 0.1 20 *21 32 * @param bool $locale 22 * @return mixed string/bool $locale 33 * @return mixed string/bool $locale 23 34 */ 24 function wcm_get_user_l ocale( $locale = false )35 function wcm_get_user_l( $locale = false ) 25 36 { 26 if ( $ new_locale= get_user_meta(37 if ( $ = get_user_meta( 27 38 get_current_user_id() 28 39 ,'user_language' 29 40 ,true 30 41 ) ) 31 return $ new_locale;42 return $; 32 43 33 44 return $locale; 34 45 } 35 46 36 add_action( 'plugins_loaded', array( 'WCMUserLangSelect', 'init' ) ); 37 47 add_action( 'plugins_loaded', array( 'WCM_User_Lang_Switch', 'init' ), 5 ); 38 48 /** 39 49 * Allows the user to change the systems language. … … 48 58 * @subpackage User Language Change 49 59 */ 50 class WCM UserLangSelect60 class WCM 51 61 { 52 62 /** … … 65 75 * @var string 66 76 */ 67 static public $name = ' uls_pick_lang';77 static public $name = '_lang'; 68 78 69 79 /** … … 88 98 * @since 0.2 89 99 * @static 90 * @return void100 * @return 91 101 */ 92 102 static public function init() 93 103 { 94 is_null( self :: $instance ) AND self ::$instance = new self;95 return self ::$instance;104 $instance = new self; 105 return self$instance; 96 106 } 97 107 … … 118 128 } 119 129 120 ! defined( 'WPLANG' ) AND define( 'WPLANG', $meta ); 130 defined( 'WPLANG' ) 131 OR define( 'WPLANG', $meta ); 121 132 122 133 // Use the global $locale instead of get_locale() to prevent endless loops … … 130 141 * Hook the functions 131 142 * @since 0.1 132 * @return \WCM UserLangSelect143 * @return \WCM 133 144 */ 134 145 public function __construct() 135 146 { 136 if ( isset( $_REQUEST[ self ::$name ] ) )147 if ( isset( $_REQUEST[ self$name ] ) ) 137 148 add_action( 'locale', array( $this, 'update_user' ) ); 138 149 139 add_filter( 'locale', 'wcm_get_user_l ocale', 20 );150 add_filter( 'locale', 'wcm_get_user_l', 20 ); 140 151 add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar') ); 141 152 … … 158 169 get_current_user_id() 159 170 ,'user_language' 160 ,$_REQUEST[ self ::$name ]171 ,$_REQUEST[ self$name ] 161 172 ); 162 173 163 return wcm_get_user_l ocale( $locale );174 return wcm_get_user_l( $locale ); 164 175 } 165 176 … … 168 179 * The 'drop down' for the admin bar 169 180 * 170 * Based on Thomas "toscho" Scholz answer on the following WP SE question by Stephen Harris:171 * @link http:// wordpress.stackexchange.com/questions/57606/obtain-a-list-of-available-translations/57609181 * Based on Thomas "toscho" Scholz answer on the following WPSE question by Stephen Harris: 182 * @link http:// 172 183 * 173 184 * @since 0.1 … … 184 195 $locale = get_locale(); 185 196 186 $wp_admin_bar->add_menu( array( 187 'id' => 'user_lang_pick' 188 ,'title' => $this->format_code_lang( $locale ) 197 $current = $this->format_code_lang( $locale ); 198 $wp_admin_bar->add_node( array( 199 'id' => 'wcm_user_lang_pick' 200 ,'title' => $current 189 201 ,'href' => '#' 202 203 204 190 205 ) ); 191 206 … … 194 209 $name = $this->format_code_lang( $lang ); 195 210 $link = add_query_arg( 196 self ::$name211 self$name 197 212 ,$lang 198 213 ); 199 214 200 $locale == $lang AND $name = sprintf(215 $locale == $lang AND $name = sprintf( 201 216 '<strong> %s </strong>' 202 217 ,$name 203 ); 204 205 $wp_admin_bar->add_menu( array( 206 'parent' => 'user_lang_pick' 207 ,'id' => "user_lang_pick_lang_{$lang}" 218 );*/ 219 220 // Don't add the current language as menu item 221 if ( $lang === wcm_get_user_lang( 'en_US' ) ) 222 continue; 223 224 $wp_admin_bar->add_node( array( 225 'parent' => 'wcm_user_lang_pick' 226 ,'id' => "wcm_user_lang_pick-{$lang}" 208 227 ,'title' => $name 209 228 ,'href' => $link 229 230 231 232 233 234 235 236 210 237 ) ); 211 238 } … … 216 243 * Get Languages 217 244 * @since 0.3 218 * @return void245 * @return 219 246 */ 220 247 public function get_langs() 221 248 { 222 return apply_filters( ' uls_get_langs', array_merge(249 return apply_filters( '_get_langs', array_merge( 223 250 get_available_languages() 224 251 ,array( 'en_US' ) … … 236 263 * @since 0.2 237 264 * @link http://codex.wordpress.org/Function_Reference/format_code_lang 238 265 * 239 266 * @param string $code Language code, e.g. en_US or en 240 * @return string The human readable language name, e.g. 'English' or the input on Error. 267 * @param string $part Which part to return: International or native name? 268 * @return string The human readable language name, e.g. 'English', or the input on Error. 241 269 */ 242 public function format_code_lang( $code = '' ) 243 { 244 270 public function format_code_lang( $code = '', $part = 'native' ) 271 { 245 272 $label_code = strtok( strtolower( $code ), "_" ); 246 if ( is_null( self :: $lang_codes ) ) 247 self :: $lang_codes = json_decode( reset( file( plugin_dir_path( __FILE__ ).'/json/lang_codes.min.json' ) ), true ); 248 249 if ( 0 !== json_last_error() ) 273 if ( null === self::$lang_codes ) 274 { 275 $iso_639_2 = file( plugin_dir_path( __FILE__ ).'/json/lang_codes.min.json' ); 276 self::$lang_codes = json_decode( reset( $iso_639_2 ), true ); 277 } 278 279 # PHP >= 5.3.0 only... 280 # if ( 0 !== json_last_error() ) 281 if ( ! empty( self::$lang_codes['error'] ) ) 250 282 return $code; 251 283 252 $lang_codes = apply_filters( 'lang_codes', self :: $lang_codes, $code ); 253 $user_locale = wcm_get_user_locale( 'en_US' ); 284 $lang_codes = apply_filters( 'wcm_lang_codes', self::$lang_codes, $code ); 254 285 255 286 if ( ! isset( $lang_codes[ $label_code ] ) ) 256 287 return $code; 257 if( $user_locale == $code ) 258 return $lang_codes[ $label_code ][ 'native' ]; 259 else 260 return $lang_codes[ $label_code ][ 'int' ]; 288 289 return $lang_codes[ $label_code ][ $part ]; 261 290 } 262 291 … … 270 299 271 300 include_once plugin_dir_path( __FILE__ ).'/dev_tools.class.php'; 272 new WCM UserLangSelectDevTools();301 new WCMDevTools(); 273 302 } 274 303 }
Note: See TracChangeset
for help on using the changeset viewer.