PluginProbe
Bogo / 1.1
Bogo v1.1
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / bogo.php

bogo.php in Bogo 1.1, at bogo.php

188 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Bogo
4 Plugin URI: http://ideasilo.wordpress.com/2009/05/05/bogo/
5 Description: Bogo allows each user to choose their locale for the admin panel.
6 Author: Takayuki Miyoshi
7 Version: 1.1
8 Author URI: http://ideasilo.wordpress.com/
9 */
10
11 /* Copyright 2007-2009 Takayuki Miyoshi (email: takayukister at gmail.com)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28 add_filter( 'locale', 'bogo_locale' );
29 add_action( 'init', 'bogo_load_plugin_textdomain' );
30 add_action( 'personal_options_update', 'bogo_update_user_option' );
31 add_action( 'personal_options', 'bogo_select_own_locale' );
32
33 function bogo_locale( $locale ) {
34 if ( ! function_exists( 'wp_get_current_user' ) )
35 return $locale;
36
37 $locale_option = get_user_option( 'locale' );
38
39 if ( ! empty( $locale_option ) )
40 $locale = $locale_option;
41
42 return $locale;
43 }
44
45 function bogo_load_plugin_textdomain() {
46 load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
47 }
48
49 function bogo_update_user_option() {
50 global $current_user;
51
52 if ( ! isset( $_POST['own_locale'] ) || empty( $_POST['own_locale'] ) )
53 $locale = null;
54 else
55 $locale = trim( $_POST['own_locale'] );
56
57 update_user_option( $current_user->id, 'locale', $locale, true );
58 }
59
60 function bogo_select_own_locale() {
61 $languages = bogo_languages();
62
63 $installed_locales = bogo_installed_locales();
64 $installed_locales[] = 'en_US';
65 $installed_locales = array_unique( $installed_locales );
66
67 $locales = array();
68 foreach ( $installed_locales as $il ) {
69 $label = array_key_exists( $il, $languages ) ? $languages[$il] : "[$il]";
70 $locales[] = array( $il, $label );
71 }
72
73 usort( $locales, create_function( '$a, $b', 'return strnatcmp($a[1], $b[1]);' ) );
74
75 $selected = get_user_option( 'locale' );
76 if ( empty( $selected ) && defined( 'WPLANG' ) )
77 $selected = WPLANG;
78 if ( empty( $selected ) )
79 $selected = 'en_US';
80
81 ?>
82
83 <!-- Bogo plugin -->
84 <tr>
85 <th scope="row"><?php _e( 'Locale', 'bogo' ); ?></th>
86 <td>
87 <select name="own_locale">
88 <?php foreach ( $locales as $locale ) : ?>
89 <option value="<?php echo $locale[0]; ?>" <?php selected( $locale[0], $selected ); ?>><?php echo $locale[1]; ?></option>
90 <?php endforeach; ?>
91 </select>
92 </td>
93 </tr>
94
95 <?php
96 }
97
98 function bogo_installed_locales() {
99 $locales = array();
100
101 if ( $handle = opendir( WP_LANG_DIR ) ) {
102 rewinddir( $handle );
103 while ( false !== ( $file = readdir( $handle ) ) ) {
104 $filename = basename( $file );
105
106 // exceptional case
107 if ( false !== strpos( $filename, 'continents-cities' ) )
108 continue;
109
110 if ( preg_match( '/^([^.]+)\.mo$/', $filename, $regs ) ) {
111 $locale = $regs[1];
112 $locales[] = $locale;
113 }
114 }
115 closedir( $handle );
116 }
117
118 return $locales;
119 }
120
121 function bogo_languages() {
122 $languages = array(
123 'af' => __( 'Afrikaans', 'bogo' ),
124 'ar' => __( 'Arabic', 'bogo' ),
125 'be_BY' => __( 'Belarusian', 'bogo' ),
126 'bg_BG' => __( 'Bulgarian', 'bogo' ),
127 'bn_BD' => __( 'Bengali', 'bogo' ),
128 'ca' => __( 'Catalan', 'bogo' ),
129 'cs_CZ' => __( 'Czech', 'bogo' ),
130 'cy' => __( 'Welsh', 'bogo' ),
131 'da_DK' => __( 'Danish', 'bogo' ),
132 'de_DE' => __( 'German', 'bogo' ),
133 'el' => __( 'Greek', 'bogo' ),
134 'en_US' => __( 'English', 'bogo' ),
135 'eo' => __( 'Esperanto', 'bogo' ),
136 'es_ES' => __( 'Spanish', 'bogo' ),
137 'et' => __( 'Estonian', 'bogo' ),
138 'eu' => __( 'Basque', 'bogo' ),
139 'fa_IR' => __( 'Persian', 'bogo' ),
140 'fi_FI' => __( 'Finnish', 'bogo' ),
141 'fo' => __( 'Faroese', 'bogo' ),
142 'fr_FR' => __( 'French', 'bogo' ),
143 'ge_GE' => __( 'Georgian', 'bogo' ),
144 'gl_ES' => __( 'Galician', 'bogo' ),
145 'he_IL' => __( 'Hebrew', 'bogo' ),
146 'hr' => __( 'Croatian', 'bogo' ),
147 'hu_HU' => __( 'Hungarian', 'bogo' ),
148 'id_ID' => __( 'Indonesian', 'bogo' ),
149 'is_IS' => __( 'Icelandic', 'bogo' ),
150 'it_IT' => __( 'Italian', 'bogo' ),
151 'ja' => __( 'Japanese', 'bogo' ),
152 'km_KH' => __( 'Khmer', 'bogo' ),
153 'ko_KR' => __( 'Korean', 'bogo' ),
154 'lt_LT' => __( 'Lithuanian', 'bogo' ),
155 'lv' => __( 'Latvian', 'bogo' ),
156 'mg_MG' => __( 'Malagasy', 'bogo' ),
157 'mk_MK' => __( 'Macedonian', 'bogo' ),
158 'mn_MN' => __( 'Mongolian', 'bogo' ),
159 'ms_MY' => __( 'Malay', 'bogo' ),
160 'nb_NO' => __( 'Norwegian', 'bogo' ),
161 'ni_ID' => __( 'Nias', 'bogo' ),
162 'nl_NL' => __( 'Dutch', 'bogo' ),
163 'pl_PL' => __( 'Polish', 'bogo' ),
164 'pt_BR' => __( 'Brazilian Portuguese', 'bogo' ),
165 'pt_PT' => __( 'Portuguese', 'bogo' ),
166 'ro' => __( 'Romanian', 'bogo' ),
167 'ru_RU' => __( 'Russian', 'bogo' ),
168 'si_LK' => __( 'Sinhala', 'bogo' ),
169 'sk' => __( 'Slovak', 'bogo' ),
170 'sl_SI' => __( 'Slovenian', 'bogo' ),
171 'sq' => __( 'Albanian', 'bogo' ),
172 'sr_CS' => __( 'Serbian', 'bogo' ),
173 'sv_SE' => __( 'Swedish', 'bogo' ),
174 'su_ID' => __( 'Sundanese', 'bogo' ),
175 'tg' => __( 'Tajik', 'bogo' ),
176 'th' => __( 'Thai', 'bogo' ),
177 'tr' => __( 'Turkish', 'bogo' ),
178 'uk_UA' => __( 'Ukrainian', 'bogo' ),
179 'uz_UZ' => __( 'Uzbek', 'bogo' ),
180 'vi' => __( 'Vietnamse', 'bogo' ),
181 'zh_CN' => __( 'Chinese', 'bogo' ),
182 'zh_TW' => __( 'Traditional Chinese', 'bogo' )
183 );
184
185 return $languages;
186 }
187
188 ?>