author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Translation API |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage i18n |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 1.2.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* Retrieves the current locale. |
0 | 12 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* If the locale is set, then it will filter the locale in the {@see 'locale'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* filter hook and return the value. |
0 | 15 |
* |
16 |
* If the locale is not set already, then the WPLANG constant is used if it is |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* defined. Then it is filtered through the {@see 'locale'} filter hook and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* the value for the locale global set and the locale is returned. |
0 | 19 |
* |
20 |
* The process to get the locale should only be done once, but the locale will |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* always be filtered using the {@see 'locale'} hook. |
0 | 22 |
* |
23 |
* @since 1.5.0 |
|
24 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @global string $locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* @global string $wp_local_package |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* @return string The locale of the blog or from the {@see 'locale'} hook. |
0 | 29 |
*/ |
30 |
function get_locale() { |
|
5 | 31 |
global $locale, $wp_local_package; |
0 | 32 |
|
5 | 33 |
if ( isset( $locale ) ) { |
0 | 34 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* Filters the locale ID of the WordPress installation. |
0 | 36 |
* |
5 | 37 |
* @since 1.5.0 |
0 | 38 |
* |
39 |
* @param string $locale The locale ID. |
|
40 |
*/ |
|
41 |
return apply_filters( 'locale', $locale ); |
|
5 | 42 |
} |
0 | 43 |
|
5 | 44 |
if ( isset( $wp_local_package ) ) { |
45 |
$locale = $wp_local_package; |
|
46 |
} |
|
47 |
||
48 |
// WPLANG was defined in wp-config. |
|
49 |
if ( defined( 'WPLANG' ) ) { |
|
0 | 50 |
$locale = WPLANG; |
5 | 51 |
} |
0 | 52 |
|
53 |
// If multisite, check options. |
|
54 |
if ( is_multisite() ) { |
|
55 |
// Don't check blog option when installing. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { |
5 | 57 |
$ms_locale = get_site_option( 'WPLANG' ); |
58 |
} |
|
0 | 59 |
|
5 | 60 |
if ( $ms_locale !== false ) { |
0 | 61 |
$locale = $ms_locale; |
5 | 62 |
} |
63 |
} else { |
|
64 |
$db_locale = get_option( 'WPLANG' ); |
|
65 |
if ( $db_locale !== false ) { |
|
66 |
$locale = $db_locale; |
|
67 |
} |
|
0 | 68 |
} |
69 |
||
5 | 70 |
if ( empty( $locale ) ) { |
0 | 71 |
$locale = 'en_US'; |
5 | 72 |
} |
0 | 73 |
|
5 | 74 |
/** This filter is documented in wp-includes/l10n.php */ |
0 | 75 |
return apply_filters( 'locale', $locale ); |
76 |
} |
|
77 |
||
78 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* Retrieves the locale of a user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* If the user has a locale set to a non-empty string then it will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* returned. Otherwise it returns the locale of get_locale(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* @return string The locale of the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
function get_user_locale( $user_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
$user = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
$user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
} elseif ( $user_id instanceof WP_User ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
$user = $user_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
} elseif ( $user_id && is_numeric( $user_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
$user = get_user_by( 'id', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
if ( ! $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
return get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
$locale = $user->locale; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
return $locale ? $locale : get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
/** |
0 | 108 |
* Retrieve the translation of $text. |
109 |
* |
|
110 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
|
111 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* *Note:* Don't use translate() directly, use __() or related functions. |
0 | 113 |
* |
114 |
* @since 2.2.0 |
|
115 |
* |
|
116 |
* @param string $text Text to translate. |
|
117 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* Default 'default'. |
0 | 119 |
* @return string Translated text |
120 |
*/ |
|
121 |
function translate( $text, $domain = 'default' ) { |
|
122 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
$translation = $translations->translate( $text ); |
5 | 124 |
|
0 | 125 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* Filters text with its translation. |
0 | 127 |
* |
128 |
* @since 2.0.11 |
|
129 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* @param string $translation Translated text. |
0 | 131 |
* @param string $text Text to translate. |
132 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
133 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
return apply_filters( 'gettext', $translation, $text, $domain ); |
0 | 135 |
} |
136 |
||
137 |
/** |
|
138 |
* Remove last item on a pipe-delimited string. |
|
139 |
* |
|
140 |
* Meant for removing the last item in a string, such as 'Role name|User role'. The original |
|
141 |
* string will be returned if no pipe '|' characters are found in the string. |
|
142 |
* |
|
143 |
* @since 2.8.0 |
|
144 |
* |
|
145 |
* @param string $string A pipe-delimited string. |
|
146 |
* @return string Either $string or everything before the last pipe. |
|
147 |
*/ |
|
148 |
function before_last_bar( $string ) { |
|
149 |
$last_bar = strrpos( $string, '|' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
if ( false === $last_bar ) { |
0 | 151 |
return $string; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
} else { |
0 | 153 |
return substr( $string, 0, $last_bar ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
} |
0 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* Retrieve the translation of $text in the context defined in $context. |
|
159 |
* |
|
160 |
* If there is no translation, or the text domain isn't loaded the original |
|
161 |
* text is returned. |
|
162 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* *Note:* Don't use translate_with_gettext_context() directly, use _x() or related functions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* |
0 | 165 |
* @since 2.8.0 |
166 |
* |
|
167 |
* @param string $text Text to translate. |
|
168 |
* @param string $context Context information for the translators. |
|
169 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* Default 'default'. |
0 | 171 |
* @return string Translated text on success, original text on failure. |
172 |
*/ |
|
173 |
function translate_with_gettext_context( $text, $context, $domain = 'default' ) { |
|
174 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
$translation = $translations->translate( $text, $context ); |
0 | 176 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* Filters text with its translation based on context information. |
0 | 178 |
* |
179 |
* @since 2.8.0 |
|
180 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* @param string $translation Translated text. |
0 | 182 |
* @param string $text Text to translate. |
183 |
* @param string $context Context information for the translators. |
|
184 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
185 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
return apply_filters( 'gettext_with_context', $translation, $text, $context, $domain ); |
0 | 187 |
} |
188 |
||
189 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* Retrieve the translation of $text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
0 | 193 |
* |
194 |
* @since 2.1.0 |
|
195 |
* |
|
196 |
* @param string $text Text to translate. |
|
197 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* Default 'default'. |
0 | 199 |
* @return string Translated text. |
200 |
*/ |
|
201 |
function __( $text, $domain = 'default' ) { |
|
202 |
return translate( $text, $domain ); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Retrieve the translation of $text and escapes it for safe use in an attribute. |
|
207 |
* |
|
208 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
|
209 |
* |
|
210 |
* @since 2.8.0 |
|
211 |
* |
|
212 |
* @param string $text Text to translate. |
|
213 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* Default 'default'. |
0 | 215 |
* @return string Translated text on success, original text on failure. |
216 |
*/ |
|
217 |
function esc_attr__( $text, $domain = 'default' ) { |
|
218 |
return esc_attr( translate( $text, $domain ) ); |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Retrieve the translation of $text and escapes it for safe use in HTML output. |
|
223 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* If there is no translation, or the text domain isn't loaded, the original text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* is escaped and returned.. |
0 | 226 |
* |
227 |
* @since 2.8.0 |
|
228 |
* |
|
229 |
* @param string $text Text to translate. |
|
230 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* Default 'default'. |
0 | 232 |
* @return string Translated text |
233 |
*/ |
|
234 |
function esc_html__( $text, $domain = 'default' ) { |
|
235 |
return esc_html( translate( $text, $domain ) ); |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Display translated text. |
|
240 |
* |
|
241 |
* @since 1.2.0 |
|
242 |
* |
|
243 |
* @param string $text Text to translate. |
|
244 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* Default 'default'. |
0 | 246 |
*/ |
247 |
function _e( $text, $domain = 'default' ) { |
|
248 |
echo translate( $text, $domain ); |
|
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
* Display translated text that has been escaped for safe use in an attribute. |
|
253 |
* |
|
254 |
* @since 2.8.0 |
|
255 |
* |
|
256 |
* @param string $text Text to translate. |
|
257 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* Default 'default'. |
0 | 259 |
*/ |
260 |
function esc_attr_e( $text, $domain = 'default' ) { |
|
261 |
echo esc_attr( translate( $text, $domain ) ); |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Display translated text that has been escaped for safe use in HTML output. |
|
266 |
* |
|
267 |
* @since 2.8.0 |
|
268 |
* |
|
269 |
* @param string $text Text to translate. |
|
270 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
* Default 'default'. |
0 | 272 |
*/ |
273 |
function esc_html_e( $text, $domain = 'default' ) { |
|
274 |
echo esc_html( translate( $text, $domain ) ); |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Retrieve translated string with gettext context. |
|
279 |
* |
|
280 |
* Quite a few times, there will be collisions with similar translatable text |
|
281 |
* found in more than two places, but with different translated context. |
|
282 |
* |
|
283 |
* By including the context in the pot file, translators can translate the two |
|
284 |
* strings differently. |
|
285 |
* |
|
286 |
* @since 2.8.0 |
|
287 |
* |
|
288 |
* @param string $text Text to translate. |
|
289 |
* @param string $context Context information for the translators. |
|
290 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
* Default 'default'. |
0 | 292 |
* @return string Translated context string without pipe. |
293 |
*/ |
|
294 |
function _x( $text, $context, $domain = 'default' ) { |
|
295 |
return translate_with_gettext_context( $text, $context, $domain ); |
|
296 |
} |
|
297 |
||
298 |
/** |
|
299 |
* Display translated string with gettext context. |
|
300 |
* |
|
301 |
* @since 3.0.0 |
|
302 |
* |
|
303 |
* @param string $text Text to translate. |
|
304 |
* @param string $context Context information for the translators. |
|
305 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
* Default 'default'. |
0 | 307 |
* @return string Translated context string without pipe. |
308 |
*/ |
|
309 |
function _ex( $text, $context, $domain = 'default' ) { |
|
310 |
echo _x( $text, $context, $domain ); |
|
311 |
} |
|
312 |
||
313 |
/** |
|
314 |
* Translate string with gettext context, and escapes it for safe use in an attribute. |
|
315 |
* |
|
316 |
* @since 2.8.0 |
|
317 |
* |
|
318 |
* @param string $text Text to translate. |
|
319 |
* @param string $context Context information for the translators. |
|
320 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* Default 'default'. |
0 | 322 |
* @return string Translated text |
323 |
*/ |
|
324 |
function esc_attr_x( $text, $context, $domain = 'default' ) { |
|
325 |
return esc_attr( translate_with_gettext_context( $text, $context, $domain ) ); |
|
326 |
} |
|
327 |
||
328 |
/** |
|
329 |
* Translate string with gettext context, and escapes it for safe use in HTML output. |
|
330 |
* |
|
331 |
* @since 2.9.0 |
|
332 |
* |
|
333 |
* @param string $text Text to translate. |
|
334 |
* @param string $context Context information for the translators. |
|
335 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* Default 'default'. |
0 | 337 |
* @return string Translated text. |
338 |
*/ |
|
339 |
function esc_html_x( $text, $context, $domain = 'default' ) { |
|
340 |
return esc_html( translate_with_gettext_context( $text, $context, $domain ) ); |
|
341 |
} |
|
342 |
||
343 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* Translates and retrieves the singular or plural form based on the supplied number. |
0 | 345 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
* Used when you want to use the appropriate form of a string based on whether a |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
* number is singular or plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* Example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 352 |
* |
353 |
* @since 2.8.0 |
|
354 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
* @param string $single The text to be used if the number is singular. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
* @param string $plural The text to be used if the number is plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 358 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
* Default 'default'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* @return string The translated singular or plural form. |
0 | 361 |
*/ |
362 |
function _n( $single, $plural, $number, $domain = 'default' ) { |
|
363 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
$translation = $translations->translate_plural( $single, $plural, $number ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
|
0 | 366 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
* Filters the singular or plural form of a string. |
0 | 368 |
* |
369 |
* @since 2.2.0 |
|
370 |
* |
|
371 |
* @param string $translation Translated text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* @param string $single The text to be used if the number is singular. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* @param string $plural The text to be used if the number is plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* @param string $number The number to compare against to use either the singular or plural form. |
0 | 375 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
376 |
*/ |
|
377 |
return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); |
|
378 |
} |
|
379 |
||
380 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* Translates and retrieves the singular or plural form based on the supplied number, with gettext context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* This is a hybrid of _n() and _x(). It supports context and plurals. |
0 | 384 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* Used when you want to use the appropriate form of a string with context based on whether a |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* number is singular or plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* Example of a generic phrase which is disambiguated via the context parameter: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) ); |
0 | 392 |
* |
393 |
* @since 2.8.0 |
|
394 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @param string $single The text to be used if the number is singular. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* @param string $plural The text to be used if the number is plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 398 |
* @param string $context Context information for the translators. |
399 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
* Default 'default'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
* @return string The translated singular or plural form. |
0 | 402 |
*/ |
403 |
function _nx($single, $plural, $number, $context, $domain = 'default') { |
|
404 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
$translation = $translations->translate_plural( $single, $plural, $number, $context ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
|
0 | 407 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* Filters the singular or plural form of a string with gettext context. |
0 | 409 |
* |
410 |
* @since 2.8.0 |
|
411 |
* |
|
412 |
* @param string $translation Translated text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
* @param string $single The text to be used if the number is singular. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
* @param string $plural The text to be used if the number is plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* @param string $number The number to compare against to use either the singular or plural form. |
0 | 416 |
* @param string $context Context information for the translators. |
417 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
418 |
*/ |
|
419 |
return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); |
|
420 |
} |
|
421 |
||
422 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* Registers plural strings in POT file, but does not translate them. |
0 | 424 |
* |
425 |
* Used when you want to keep structures with translatable plural |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* strings and use them later when the number is known. |
0 | 427 |
* |
428 |
* Example: |
|
5 | 429 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* $message = _n_noop( '%s post', '%s posts', 'text-domain' ); |
5 | 431 |
* ... |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 433 |
* |
434 |
* @since 2.5.0 |
|
435 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* @param string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @param string $plural Plural form to be localized. |
0 | 438 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
* Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
* @return array { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* Array of translation information for the strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* @type string $0 Singular form to be localized. No longer used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* @type string $1 Plural form to be localized. No longer used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* @type string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* @type string $plural Plural form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* @type null $context Context information for the translators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @type string $domain Text domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* } |
0 | 450 |
*/ |
451 |
function _n_noop( $singular, $plural, $domain = null ) { |
|
452 |
return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); |
|
453 |
} |
|
454 |
||
455 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* Registers plural strings with gettext context in POT file, but does not translate them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* Used when you want to keep structures with translatable plural |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* strings and use them later when the number is known. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* Example of a generic phrase which is disambiguated via the context parameter: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* $messages = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* $message = $messages[ $type ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 470 |
* |
471 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
* @param string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* @param string $plural Plural form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @param string $context Context information for the translators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* @return array { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* Array of translation information for the strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* @type string $0 Singular form to be localized. No longer used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* @type string $1 Plural form to be localized. No longer used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* @type string $2 Context information for the translators. No longer used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
* @type string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* @type string $plural Plural form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
* @type string $context Context information for the translators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* @type string $domain Text domain. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* } |
0 | 489 |
*/ |
490 |
function _nx_noop( $singular, $plural, $context, $domain = null ) { |
|
491 |
return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); |
|
492 |
} |
|
493 |
||
494 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* Translates and retrieves the singular or plural form of a string that's been registered |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* with _n_noop() or _nx_noop(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* Used when you want to use a translatable plural string once the number is known. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* Example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* $message = _n_noop( '%s post', '%s posts', 'text-domain' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 505 |
* |
506 |
* @since 3.1.0 |
|
507 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
* @param array $nooped_plural Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* @param int $count Number of objects. |
0 | 510 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'. |
0 | 512 |
* @return string Either $single or $plural translated text. |
513 |
*/ |
|
514 |
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { |
|
515 |
if ( $nooped_plural['domain'] ) |
|
516 |
$domain = $nooped_plural['domain']; |
|
517 |
||
518 |
if ( $nooped_plural['context'] ) |
|
519 |
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); |
|
520 |
else |
|
521 |
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain ); |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Load a .mo file into the text domain $domain. |
|
526 |
* |
|
527 |
* If the text domain already exists, the translations will be merged. If both |
|
528 |
* sets have the same string, the translation from the original value will be taken. |
|
529 |
* |
|
530 |
* On success, the .mo file will be placed in the $l10n global by $domain |
|
531 |
* and will be a MO object. |
|
532 |
* |
|
533 |
* @since 1.5.0 |
|
534 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
* @global array $l10n An array of all currently loaded text domains. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* @global array $l10n_unloaded An array of all text domains that have been unloaded again. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* |
0 | 538 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
539 |
* @param string $mofile Path to the .mo file. |
|
540 |
* @return bool True on success, false on failure. |
|
541 |
*/ |
|
542 |
function load_textdomain( $domain, $mofile ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
global $l10n, $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
$l10n_unloaded = (array) $l10n_unloaded; |
0 | 546 |
|
547 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
* Filters whether to override the .mo file loading. |
0 | 549 |
* |
550 |
* @since 2.9.0 |
|
551 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
* @param bool $override Whether to override the .mo file loading. Default false. |
5 | 553 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
554 |
* @param string $mofile Path to the MO file. |
|
0 | 555 |
*/ |
556 |
$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile ); |
|
557 |
||
558 |
if ( true == $plugin_override ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
unset( $l10n_unloaded[ $domain ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
|
0 | 561 |
return true; |
562 |
} |
|
563 |
||
564 |
/** |
|
565 |
* Fires before the MO translation file is loaded. |
|
566 |
* |
|
567 |
* @since 2.9.0 |
|
568 |
* |
|
569 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
570 |
* @param string $mofile Path to the .mo file. |
|
571 |
*/ |
|
572 |
do_action( 'load_textdomain', $domain, $mofile ); |
|
573 |
||
574 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* Filters MO file path for loading translations for a specific text domain. |
0 | 576 |
* |
577 |
* @since 2.9.0 |
|
578 |
* |
|
579 |
* @param string $mofile Path to the MO file. |
|
580 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
581 |
*/ |
|
582 |
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); |
|
583 |
||
584 |
if ( !is_readable( $mofile ) ) return false; |
|
585 |
||
586 |
$mo = new MO(); |
|
587 |
if ( !$mo->import_from_file( $mofile ) ) return false; |
|
588 |
||
589 |
if ( isset( $l10n[$domain] ) ) |
|
590 |
$mo->merge_with( $l10n[$domain] ); |
|
591 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
unset( $l10n_unloaded[ $domain ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
|
0 | 594 |
$l10n[$domain] = &$mo; |
595 |
||
596 |
return true; |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Unload translations for a text domain. |
|
601 |
* |
|
602 |
* @since 3.0.0 |
|
603 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* @global array $l10n An array of all currently loaded text domains. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* @global array $l10n_unloaded An array of all text domains that have been unloaded again. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* |
0 | 607 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
608 |
* @return bool Whether textdomain was unloaded. |
|
609 |
*/ |
|
610 |
function unload_textdomain( $domain ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
global $l10n, $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
$l10n_unloaded = (array) $l10n_unloaded; |
0 | 614 |
|
615 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* Filters whether to override the text domain unloading. |
0 | 617 |
* |
618 |
* @since 3.0.0 |
|
619 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @param bool $override Whether to override the text domain unloading. Default false. |
5 | 621 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
0 | 622 |
*/ |
623 |
$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); |
|
624 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
if ( $plugin_override ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
$l10n_unloaded[ $domain ] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
|
0 | 628 |
return true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
} |
0 | 630 |
|
631 |
/** |
|
632 |
* Fires before the text domain is unloaded. |
|
633 |
* |
|
634 |
* @since 3.0.0 |
|
635 |
* |
|
636 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
637 |
*/ |
|
638 |
do_action( 'unload_textdomain', $domain ); |
|
639 |
||
640 |
if ( isset( $l10n[$domain] ) ) { |
|
641 |
unset( $l10n[$domain] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
$l10n_unloaded[ $domain ] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
|
0 | 645 |
return true; |
646 |
} |
|
647 |
||
648 |
return false; |
|
649 |
} |
|
650 |
||
651 |
/** |
|
652 |
* Load default translated strings based on locale. |
|
653 |
* |
|
654 |
* Loads the .mo file in WP_LANG_DIR constant path from WordPress root. |
|
655 |
* The translated (.mo) file is named based on the locale. |
|
656 |
* |
|
657 |
* @see load_textdomain() |
|
658 |
* |
|
659 |
* @since 1.5.0 |
|
5 | 660 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @param string $locale Optional. Locale to load. Default is the value of get_locale(). |
5 | 662 |
* @return bool Whether the textdomain was loaded. |
0 | 663 |
*/ |
5 | 664 |
function load_default_textdomain( $locale = null ) { |
665 |
if ( null === $locale ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
$locale = is_admin() ? get_user_locale() : get_locale(); |
5 | 667 |
} |
0 | 668 |
|
5 | 669 |
// Unload previously loaded strings so we can switch translations. |
670 |
unload_textdomain( 'default' ); |
|
671 |
||
672 |
$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); |
|
0 | 673 |
|
674 |
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { |
|
675 |
load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); |
|
5 | 676 |
return $return; |
0 | 677 |
} |
678 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { |
0 | 680 |
load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); |
5 | 681 |
} |
0 | 682 |
|
683 |
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) |
|
684 |
load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); |
|
685 |
||
5 | 686 |
return $return; |
0 | 687 |
} |
688 |
||
689 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* Loads a plugin's translated strings. |
0 | 691 |
* |
692 |
* If the path is not given then it will be the root of the plugin directory. |
|
693 |
* |
|
694 |
* The .mo file should be named based on the text domain with a dash, and then the locale exactly. |
|
695 |
* |
|
696 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 698 |
* |
699 |
* @param string $domain Unique identifier for retrieving translated strings |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* @param string $deprecated Optional. Use the $plugin_rel_path parameter instead. Default false. |
0 | 701 |
* @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides. |
5 | 702 |
* Default false. |
703 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
|
0 | 704 |
*/ |
705 |
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { |
|
706 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* Filters a plugin's locale. |
0 | 708 |
* |
709 |
* @since 3.0.0 |
|
710 |
* |
|
711 |
* @param string $locale The plugin's current locale. |
|
712 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
713 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
$locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
$mofile = $domain . '-' . $locale . '.mo'; |
0 | 717 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
// Try to load from the languages directory first. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
if ( false !== $plugin_rel_path ) { |
0 | 724 |
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); |
5 | 725 |
} elseif ( false !== $deprecated ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
726 |
_deprecated_argument( __FUNCTION__, '2.7.0' ); |
0 | 727 |
$path = ABSPATH . trim( $deprecated, '/' ); |
728 |
} else { |
|
729 |
$path = WP_PLUGIN_DIR; |
|
730 |
} |
|
731 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
return load_textdomain( $domain, $path . '/' . $mofile ); |
0 | 733 |
} |
734 |
||
735 |
/** |
|
736 |
* Load the translated strings for a plugin residing in the mu-plugins directory. |
|
737 |
* |
|
738 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 740 |
* |
741 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
* @param string $mu_plugin_rel_path Optional. Relative to `WPMU_PLUGIN_DIR` directory in which the .mo |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
* file resides. Default empty string. |
0 | 744 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
745 |
*/ |
|
746 |
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { |
|
5 | 747 |
/** This filter is documented in wp-includes/l10n.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
$locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); |
0 | 749 |
|
750 |
$mofile = $domain . '-' . $locale . '.mo'; |
|
751 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
// Try to load from the languages directory first. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
$path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
return load_textdomain( $domain, $path . '/' . $mofile ); |
0 | 760 |
} |
761 |
||
762 |
/** |
|
763 |
* Load the theme's translated strings. |
|
764 |
* |
|
765 |
* If the current locale exists as a .mo file in the theme's root directory, it |
|
766 |
* will be included in the translated strings by the $domain. |
|
767 |
* |
|
768 |
* The .mo files must be named based on the locale exactly. |
|
769 |
* |
|
770 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 772 |
* |
773 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
774 |
* @param string $path Optional. Path to the directory containing the .mo file. |
|
775 |
* Default false. |
|
776 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
|
777 |
*/ |
|
778 |
function load_theme_textdomain( $domain, $path = false ) { |
|
779 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* Filters a theme's locale. |
0 | 781 |
* |
782 |
* @since 3.0.0 |
|
783 |
* |
|
784 |
* @param string $locale The theme's current locale. |
|
785 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
786 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
$locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); |
0 | 788 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
$mofile = $domain . '-' . $locale . '.mo'; |
0 | 790 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
// Try to load from the languages directory first. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
} |
0 | 795 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
if ( ! $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
$path = get_template_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
return load_textdomain( $domain, $path . '/' . $locale . '.mo' ); |
0 | 801 |
} |
802 |
||
803 |
/** |
|
804 |
* Load the child themes translated strings. |
|
805 |
* |
|
806 |
* If the current locale exists as a .mo file in the child themes |
|
807 |
* root directory, it will be included in the translated strings by the $domain. |
|
808 |
* |
|
809 |
* The .mo files must be named based on the locale exactly. |
|
810 |
* |
|
811 |
* @since 2.9.0 |
|
812 |
* |
|
813 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
5 | 814 |
* @param string $path Optional. Path to the directory containing the .mo file. |
815 |
* Default false. |
|
0 | 816 |
* @return bool True when the theme textdomain is successfully loaded, false otherwise. |
817 |
*/ |
|
818 |
function load_child_theme_textdomain( $domain, $path = false ) { |
|
819 |
if ( ! $path ) |
|
820 |
$path = get_stylesheet_directory(); |
|
821 |
return load_theme_textdomain( $domain, $path ); |
|
822 |
} |
|
823 |
||
824 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* Loads plugin and theme textdomains just-in-time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* When a textdomain is encountered for the first time, we try to load |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* the translation file from `wp-content/languages`, removing the need |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* to call load_plugin_texdomain() or load_theme_texdomain(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* @see get_translations_for_domain() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
* @global array $l10n_unloaded An array of all text domains that have been unloaded again. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* @return bool True when the textdomain is successfully loaded, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
function _load_textdomain_just_in_time( $domain ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
global $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
$l10n_unloaded = (array) $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
// Short-circuit if domain is 'default' which is reserved for core. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
$translation_path = _get_path_to_translation( $domain ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
if ( false === $translation_path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
return load_textdomain( $domain, $translation_path ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* Gets the path to a translation file for loading a textdomain just in time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* Caches the retrieved results internally. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* @see _load_textdomain_just_in_time() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* @return string|false The path to the translation file or false if no translation file was found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
function _get_path_to_translation( $domain, $reset = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
static $available_translations = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
if ( true === $reset ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
$available_translations = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
if ( ! isset( $available_translations[ $domain ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
$available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
return $available_translations[ $domain ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* Gets the path to a translation file in the languages directory for the current locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
* Holds a cached list of available .mo files to improve performance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
* @see _get_path_to_translation() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
* @return string|false The path to the translation file or false if no translation file was found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
function _get_path_to_translation_from_lang_dir( $domain ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
static $cached_mofiles = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
if ( null === $cached_mofiles ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
$cached_mofiles = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
$locations = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
WP_LANG_DIR . '/plugins', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
WP_LANG_DIR . '/themes', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
foreach ( $locations as $location ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
$mofiles = glob( $location . '/*.mo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
if ( $mofiles ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
$cached_mofiles = array_merge( $cached_mofiles, $mofiles ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
$locale = is_admin() ? get_user_locale() : get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
$mofile = "{$domain}-{$locale}.mo"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
$path = WP_LANG_DIR . '/plugins/' . $mofile; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
if ( in_array( $path, $cached_mofiles ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
return $path; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
$path = WP_LANG_DIR . '/themes/' . $mofile; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
if ( in_array( $path, $cached_mofiles ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
return $path; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
/** |
0 | 935 |
* Return the Translations instance for a text domain. |
936 |
* |
|
937 |
* If there isn't one, returns empty Translations instance. |
|
938 |
* |
|
5 | 939 |
* @since 2.8.0 |
940 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
* @global array $l10n |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* |
0 | 943 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
* @return Translations|NOOP_Translations A Translations instance. |
0 | 945 |
*/ |
946 |
function get_translations_for_domain( $domain ) { |
|
947 |
global $l10n; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
return $l10n[ $domain ]; |
0 | 950 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
static $noop_translations = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
if ( null === $noop_translations ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
$noop_translations = new NOOP_Translations; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
return $noop_translations; |
0 | 958 |
} |
959 |
||
960 |
/** |
|
961 |
* Whether there are translations for the text domain. |
|
962 |
* |
|
963 |
* @since 3.0.0 |
|
5 | 964 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
* @global array $l10n |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
* |
0 | 967 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
968 |
* @return bool Whether there are translations. |
|
969 |
*/ |
|
970 |
function is_textdomain_loaded( $domain ) { |
|
971 |
global $l10n; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
return isset( $l10n[ $domain ] ); |
0 | 973 |
} |
974 |
||
975 |
/** |
|
976 |
* Translates role name. |
|
977 |
* |
|
978 |
* Since the role names are in the database and not in the source there |
|
979 |
* are dummy gettext calls to get them into the POT file and this function |
|
980 |
* properly translates them back. |
|
981 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
* The before_last_bar() call is needed, because older installations keep the roles |
0 | 983 |
* using the old context format: 'Role name|User role' and just skipping the |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
* content after the last bar is easier than fixing them in the DB. New installations |
0 | 985 |
* won't suffer from that problem. |
986 |
* |
|
987 |
* @since 2.8.0 |
|
988 |
* |
|
989 |
* @param string $name The role name. |
|
990 |
* @return string Translated role name on success, original name on failure. |
|
991 |
*/ |
|
992 |
function translate_user_role( $name ) { |
|
993 |
return translate_with_gettext_context( before_last_bar($name), 'User role' ); |
|
994 |
} |
|
995 |
||
996 |
/** |
|
997 |
* Get all available languages based on the presence of *.mo files in a given directory. |
|
998 |
* |
|
999 |
* The default directory is WP_LANG_DIR. |
|
1000 |
* |
|
1001 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter. |
0 | 1003 |
* |
1004 |
* @param string $dir A directory to search for language files. |
|
1005 |
* Default WP_LANG_DIR. |
|
1006 |
* @return array An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. |
|
1007 |
*/ |
|
1008 |
function get_available_languages( $dir = null ) { |
|
1009 |
$languages = array(); |
|
1010 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
$lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
if ( $lang_files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
foreach ( $lang_files as $lang_file ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
$lang_file = basename( $lang_file, '.mo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
0 !== strpos( $lang_file, 'admin-' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
$languages[] = $lang_file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
} |
0 | 1020 |
} |
1021 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
* Filters the list of available language codes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
* @param array $languages An array of available language codes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
* @param string $dir The directory where the language files were found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
return apply_filters( 'get_available_languages', $languages, $dir ); |
0 | 1031 |
} |
1032 |
||
1033 |
/** |
|
1034 |
* Get installed translations. |
|
1035 |
* |
|
1036 |
* Looks in the wp-content/languages directory for translations of |
|
1037 |
* plugins or themes. |
|
1038 |
* |
|
1039 |
* @since 3.7.0 |
|
1040 |
* |
|
1041 |
* @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. |
|
1042 |
* @return array Array of language data. |
|
1043 |
*/ |
|
1044 |
function wp_get_installed_translations( $type ) { |
|
1045 |
if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) |
|
1046 |
return array(); |
|
1047 |
||
1048 |
$dir = 'core' === $type ? '' : "/$type"; |
|
1049 |
||
1050 |
if ( ! is_dir( WP_LANG_DIR ) ) |
|
1051 |
return array(); |
|
1052 |
||
1053 |
if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) |
|
1054 |
return array(); |
|
1055 |
||
1056 |
$files = scandir( WP_LANG_DIR . $dir ); |
|
1057 |
if ( ! $files ) |
|
1058 |
return array(); |
|
1059 |
||
1060 |
$language_data = array(); |
|
1061 |
||
1062 |
foreach ( $files as $file ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) { |
5 | 1064 |
continue; |
1065 |
} |
|
1066 |
if ( substr( $file, -3 ) !== '.po' ) { |
|
0 | 1067 |
continue; |
5 | 1068 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { |
0 | 1070 |
continue; |
5 | 1071 |
} |
1072 |
if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) { |
|
0 | 1073 |
continue; |
5 | 1074 |
} |
0 | 1075 |
|
1076 |
list( , $textdomain, $language ) = $match; |
|
5 | 1077 |
if ( '' === $textdomain ) { |
0 | 1078 |
$textdomain = 'default'; |
5 | 1079 |
} |
0 | 1080 |
$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); |
1081 |
} |
|
1082 |
return $language_data; |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
1086 |
* Extract headers from a PO file. |
|
1087 |
* |
|
1088 |
* @since 3.7.0 |
|
1089 |
* |
|
1090 |
* @param string $po_file Path to PO file. |
|
1091 |
* @return array PO file headers. |
|
1092 |
*/ |
|
1093 |
function wp_get_pomo_file_data( $po_file ) { |
|
1094 |
$headers = get_file_data( $po_file, array( |
|
1095 |
'POT-Creation-Date' => '"POT-Creation-Date', |
|
1096 |
'PO-Revision-Date' => '"PO-Revision-Date', |
|
1097 |
'Project-Id-Version' => '"Project-Id-Version', |
|
1098 |
'X-Generator' => '"X-Generator', |
|
1099 |
) ); |
|
1100 |
foreach ( $headers as $header => $value ) { |
|
1101 |
// Remove possible contextual '\n' and closing double quote. |
|
1102 |
$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value ); |
|
1103 |
} |
|
1104 |
return $headers; |
|
1105 |
} |
|
5 | 1106 |
|
1107 |
/** |
|
1108 |
* Language selector. |
|
1109 |
* |
|
1110 |
* @since 4.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
* @since 4.3.0 Introduced the `echo` argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
* @since 4.7.0 Introduced the `show_option_site_default` argument. |
5 | 1113 |
* |
1114 |
* @see get_available_languages() |
|
1115 |
* @see wp_get_available_translations() |
|
1116 |
* |
|
1117 |
* @param string|array $args { |
|
1118 |
* Optional. Array or string of arguments for outputting the language selector. |
|
1119 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* @type string $id ID attribute of the select element. Default 'locale'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
* @type string $name Name attribute of the select element. Default 'locale'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
* @type array $languages List of installed languages, contain only the locales. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
* @type array $translations List of available translations. Default result of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
* wp_get_available_translations(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
* @type string $selected Language which should be selected. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
* @type bool|int $echo Whether to echo the generated markup. Accepts 0, 1, or their |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
* boolean equivalents. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* @type bool $show_available_translations Whether to show available translations. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* @type bool $show_option_site_default Whether to show an option to fall back to the site's locale. Default false. |
5 | 1131 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
* @return string HTML content |
5 | 1133 |
*/ |
1134 |
function wp_dropdown_languages( $args = array() ) { |
|
1135 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
$parsed_args = wp_parse_args( $args, array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
'id' => 'locale', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
'name' => 'locale', |
5 | 1139 |
'languages' => array(), |
1140 |
'translations' => array(), |
|
1141 |
'selected' => '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
'echo' => 1, |
5 | 1143 |
'show_available_translations' => true, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
'show_option_site_default' => false, |
5 | 1145 |
) ); |
1146 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
// Bail if no ID or no name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
// English (United States) uses an empty string for the value attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
if ( 'en_US' === $parsed_args['selected'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
$parsed_args['selected'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
$translations = $parsed_args['translations']; |
5 | 1158 |
if ( empty( $translations ) ) { |
1159 |
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
|
1160 |
$translations = wp_get_available_translations(); |
|
1161 |
} |
|
1162 |
||
1163 |
/* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* $parsed_args['languages'] should only contain the locales. Find the locale in |
5 | 1165 |
* $translations to get the native name. Fall back to locale. |
1166 |
*/ |
|
1167 |
$languages = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
foreach ( $parsed_args['languages'] as $locale ) { |
5 | 1169 |
if ( isset( $translations[ $locale ] ) ) { |
1170 |
$translation = $translations[ $locale ]; |
|
1171 |
$languages[] = array( |
|
1172 |
'language' => $translation['language'], |
|
1173 |
'native_name' => $translation['native_name'], |
|
1174 |
'lang' => current( $translation['iso'] ), |
|
1175 |
); |
|
1176 |
||
1177 |
// Remove installed language from available translations. |
|
1178 |
unset( $translations[ $locale ] ); |
|
1179 |
} else { |
|
1180 |
$languages[] = array( |
|
1181 |
'language' => $locale, |
|
1182 |
'native_name' => $locale, |
|
1183 |
'lang' => '', |
|
1184 |
); |
|
1185 |
} |
|
1186 |
} |
|
1187 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
$translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] ); |
5 | 1189 |
|
1190 |
// Holds the HTML markup. |
|
1191 |
$structure = array(); |
|
1192 |
||
1193 |
// List installed languages. |
|
1194 |
if ( $translations_available ) { |
|
1195 |
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; |
|
1196 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
// Site default. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
if ( $parsed_args['show_option_site_default'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
$structure[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
'<option value="site-default" data-installed="1"%s>%s</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
selected( 'site-default', $parsed_args['selected'], false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
_x( 'Site Default', 'default site language' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
// Always show English. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
$structure[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
selected( '', $parsed_args['selected'], false ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
// List installed languages. |
5 | 1214 |
foreach ( $languages as $language ) { |
1215 |
$structure[] = sprintf( |
|
1216 |
'<option value="%s" lang="%s"%s data-installed="1">%s</option>', |
|
1217 |
esc_attr( $language['language'] ), |
|
1218 |
esc_attr( $language['lang'] ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
selected( $language['language'], $parsed_args['selected'], false ), |
5 | 1220 |
esc_html( $language['native_name'] ) |
1221 |
); |
|
1222 |
} |
|
1223 |
if ( $translations_available ) { |
|
1224 |
$structure[] = '</optgroup>'; |
|
1225 |
} |
|
1226 |
||
1227 |
// List available translations. |
|
1228 |
if ( $translations_available ) { |
|
1229 |
$structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">'; |
|
1230 |
foreach ( $translations as $translation ) { |
|
1231 |
$structure[] = sprintf( |
|
1232 |
'<option value="%s" lang="%s"%s>%s</option>', |
|
1233 |
esc_attr( $translation['language'] ), |
|
1234 |
esc_attr( current( $translation['iso'] ) ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
selected( $translation['language'], $parsed_args['selected'], false ), |
5 | 1236 |
esc_html( $translation['native_name'] ) |
1237 |
); |
|
1238 |
} |
|
1239 |
$structure[] = '</optgroup>'; |
|
1240 |
} |
|
1241 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
// Combine the output string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
$output .= join( "\n", $structure ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
$output .= '</select>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
if ( $parsed_args['echo'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
echo $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
return $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* Checks if current locale is RTL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
* @return bool Whether locale is RTL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
function is_rtl() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
global $wp_locale; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
if ( ! ( $wp_locale instanceof WP_Locale ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
return $wp_locale->is_rtl(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* Switches the translations according to the given locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
* @global WP_Locale_Switcher $wp_locale_switcher |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* @param string $locale The locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
function switch_to_locale( $locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
return $wp_locale_switcher->switch_to_locale( $locale ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
} |
5 | 1287 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
* Restores the translations according to the previous locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
* @global WP_Locale_Switcher $wp_locale_switcher |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
* @return string|false Locale on success, false on error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
function restore_previous_locale() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
return $wp_locale_switcher->restore_previous_locale(); |
5 | 1302 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* Restores the translations according to the original locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
* @global WP_Locale_Switcher $wp_locale_switcher |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* @return string|false Locale on success, false on error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
function restore_current_locale() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
return $wp_locale_switcher->restore_current_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
* Whether switch_to_locale() is in effect. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
* @global WP_Locale_Switcher $wp_locale_switcher |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
* @return bool True if the locale has been switched, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
function is_locale_switched() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
return $wp_locale_switcher->is_switched(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
} |