author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
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 |
* |
|
16 | 25 |
* @global string $locale The current locale. |
26 |
* @global string $wp_local_package Locale code of the package. |
|
7
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 ) ) { |
18 | 34 |
/** This filter is documented in wp-includes/l10n.php */ |
0 | 35 |
return apply_filters( 'locale', $locale ); |
5 | 36 |
} |
0 | 37 |
|
5 | 38 |
if ( isset( $wp_local_package ) ) { |
39 |
$locale = $wp_local_package; |
|
40 |
} |
|
41 |
||
42 |
// WPLANG was defined in wp-config. |
|
43 |
if ( defined( 'WPLANG' ) ) { |
|
0 | 44 |
$locale = WPLANG; |
5 | 45 |
} |
0 | 46 |
|
47 |
// If multisite, check options. |
|
48 |
if ( is_multisite() ) { |
|
49 |
// Don't check blog option when installing. |
|
16 | 50 |
if ( wp_installing() ) { |
5 | 51 |
$ms_locale = get_site_option( 'WPLANG' ); |
16 | 52 |
} else { |
53 |
$ms_locale = get_option( 'WPLANG' ); |
|
54 |
if ( false === $ms_locale ) { |
|
55 |
$ms_locale = get_site_option( 'WPLANG' ); |
|
56 |
} |
|
5 | 57 |
} |
0 | 58 |
|
16 | 59 |
if ( false !== $ms_locale ) { |
0 | 60 |
$locale = $ms_locale; |
5 | 61 |
} |
62 |
} else { |
|
63 |
$db_locale = get_option( 'WPLANG' ); |
|
16 | 64 |
if ( false !== $db_locale ) { |
5 | 65 |
$locale = $db_locale; |
66 |
} |
|
0 | 67 |
} |
68 |
||
5 | 69 |
if ( empty( $locale ) ) { |
0 | 70 |
$locale = 'en_US'; |
5 | 71 |
} |
0 | 72 |
|
18 | 73 |
/** |
74 |
* Filters the locale ID of the WordPress installation. |
|
75 |
* |
|
76 |
* @since 1.5.0 |
|
77 |
* |
|
78 |
* @param string $locale The locale ID. |
|
79 |
*/ |
|
0 | 80 |
return apply_filters( 'locale', $locale ); |
81 |
} |
|
82 |
||
83 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* Retrieves the locale of a user. |
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 |
* 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
|
87 |
* returned. Otherwise it returns the locale of get_locale(). |
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 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
* @param int|WP_User $user User's ID or a WP_User object. Defaults to current user. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* @return string The locale of the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
function get_user_locale( $user = 0 ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
95 |
$user_object = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
96 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
$user_object = wp_get_current_user(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
99 |
} elseif ( $user instanceof WP_User ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
$user_object = $user; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
} elseif ( $user && is_numeric( $user ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
102 |
$user_object = get_user_by( 'id', $user ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
if ( ! $user_object ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
return get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
$locale = $user_object->locale; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
110 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
return $locale ? $locale : get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
* Determines the current locale desired for the request. |
9 | 116 |
* |
117 |
* @since 5.0.0 |
|
118 |
* |
|
19 | 119 |
* @global string $pagenow The filename of the current screen. |
9 | 120 |
* |
121 |
* @return string The determined locale. |
|
122 |
*/ |
|
123 |
function determine_locale() { |
|
124 |
/** |
|
125 |
* Filters the locale for the current request prior to the default determination process. |
|
126 |
* |
|
127 |
* Using this filter allows to override the default logic, effectively short-circuiting the function. |
|
128 |
* |
|
129 |
* @since 5.0.0 |
|
130 |
* |
|
16 | 131 |
* @param string|null $locale The locale to return and short-circuit. Default null. |
9 | 132 |
*/ |
133 |
$determined_locale = apply_filters( 'pre_determine_locale', null ); |
|
16 | 134 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
if ( $determined_locale && is_string( $determined_locale ) ) { |
9 | 136 |
return $determined_locale; |
137 |
} |
|
138 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
if ( ! empty( $_GET['wp_lang'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
148 |
} elseif ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
149 |
is_admin() || |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
150 |
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
151 |
) { |
9 | 152 |
$determined_locale = get_user_locale(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
153 |
} elseif ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
154 |
( ! empty( $_REQUEST['language'] ) || isset( $GLOBALS['wp_local_package'] ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
155 |
&& wp_installing() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
156 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
if ( ! empty( $_REQUEST['language'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
$determined_locale = sanitize_locale_name( $_REQUEST['language'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
160 |
$determined_locale = $GLOBALS['wp_local_package']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
161 |
} |
9 | 162 |
} |
163 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
if ( ! $determined_locale ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
$determined_locale = get_locale(); |
9 | 166 |
} |
167 |
||
168 |
/** |
|
169 |
* Filters the locale for the current request. |
|
170 |
* |
|
171 |
* @since 5.0.0 |
|
172 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
* @param string $determined_locale The locale. |
9 | 174 |
*/ |
175 |
return apply_filters( 'determine_locale', $determined_locale ); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
* Retrieves the translation of $text. |
0 | 180 |
* |
181 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
|
182 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* *Note:* Don't use translate() directly, use __() or related functions. |
0 | 184 |
* |
185 |
* @since 2.2.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
186 |
* @since 5.5.0 Introduced `gettext-{$domain}` filter. |
0 | 187 |
* |
188 |
* @param string $text Text to translate. |
|
189 |
* @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
|
190 |
* Default 'default'. |
16 | 191 |
* @return string Translated text. |
0 | 192 |
*/ |
193 |
function translate( $text, $domain = 'default' ) { |
|
194 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
$translation = $translations->translate( $text ); |
5 | 196 |
|
0 | 197 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* Filters text with its translation. |
0 | 199 |
* |
200 |
* @since 2.0.11 |
|
201 |
* |
|
16 | 202 |
* @param string $translation Translated text. |
203 |
* @param string $text Text to translate. |
|
204 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
0 | 205 |
*/ |
16 | 206 |
$translation = apply_filters( 'gettext', $translation, $text, $domain ); |
207 |
||
208 |
/** |
|
209 |
* Filters text with its translation for a domain. |
|
210 |
* |
|
19 | 211 |
* The dynamic portion of the hook name, `$domain`, refers to the text domain. |
16 | 212 |
* |
213 |
* @since 5.5.0 |
|
214 |
* |
|
215 |
* @param string $translation Translated text. |
|
216 |
* @param string $text Text to translate. |
|
217 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
218 |
*/ |
|
219 |
$translation = apply_filters( "gettext_{$domain}", $translation, $text, $domain ); |
|
220 |
||
221 |
return $translation; |
|
0 | 222 |
} |
223 |
||
224 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
225 |
* Removes last item on a pipe-delimited string. |
0 | 226 |
* |
227 |
* Meant for removing the last item in a string, such as 'Role name|User role'. The original |
|
228 |
* string will be returned if no pipe '|' characters are found in the string. |
|
229 |
* |
|
230 |
* @since 2.8.0 |
|
231 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
* @param string $text A pipe-delimited string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
* @return string Either $text or everything before the last pipe. |
0 | 234 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
function before_last_bar( $text ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
236 |
$last_bar = strrpos( $text, '|' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
if ( false === $last_bar ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
238 |
return $text; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
return substr( $text, 0, $last_bar ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
} |
0 | 242 |
} |
243 |
||
244 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
245 |
* Retrieves the translation of $text in the context defined in $context. |
0 | 246 |
* |
16 | 247 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
0 | 248 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* *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
|
250 |
* |
0 | 251 |
* @since 2.8.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
252 |
* @since 5.5.0 Introduced `gettext_with_context-{$domain}` filter. |
0 | 253 |
* |
254 |
* @param string $text Text to translate. |
|
255 |
* @param string $context Context information for the translators. |
|
256 |
* @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
|
257 |
* Default 'default'. |
0 | 258 |
* @return string Translated text on success, original text on failure. |
259 |
*/ |
|
260 |
function translate_with_gettext_context( $text, $context, $domain = 'default' ) { |
|
261 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
$translation = $translations->translate( $text, $context ); |
16 | 263 |
|
0 | 264 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* Filters text with its translation based on context information. |
0 | 266 |
* |
267 |
* @since 2.8.0 |
|
268 |
* |
|
16 | 269 |
* @param string $translation Translated text. |
270 |
* @param string $text Text to translate. |
|
271 |
* @param string $context Context information for the translators. |
|
272 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
0 | 273 |
*/ |
16 | 274 |
$translation = apply_filters( 'gettext_with_context', $translation, $text, $context, $domain ); |
275 |
||
276 |
/** |
|
277 |
* Filters text with its translation based on context information for a domain. |
|
278 |
* |
|
19 | 279 |
* The dynamic portion of the hook name, `$domain`, refers to the text domain. |
16 | 280 |
* |
281 |
* @since 5.5.0 |
|
282 |
* |
|
283 |
* @param string $translation Translated text. |
|
284 |
* @param string $text Text to translate. |
|
285 |
* @param string $context Context information for the translators. |
|
286 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
287 |
*/ |
|
288 |
$translation = apply_filters( "gettext_with_context_{$domain}", $translation, $text, $context, $domain ); |
|
289 |
||
290 |
return $translation; |
|
0 | 291 |
} |
292 |
||
293 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
* Retrieves the translation of $text. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
0 | 297 |
* |
298 |
* @since 2.1.0 |
|
299 |
* |
|
300 |
* @param string $text Text to translate. |
|
301 |
* @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
|
302 |
* Default 'default'. |
0 | 303 |
* @return string Translated text. |
304 |
*/ |
|
305 |
function __( $text, $domain = 'default' ) { |
|
306 |
return translate( $text, $domain ); |
|
307 |
} |
|
308 |
||
309 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
* Retrieves the translation of $text and escapes it for safe use in an attribute. |
0 | 311 |
* |
312 |
* If there is no translation, or the text domain isn't loaded, the original text is returned. |
|
313 |
* |
|
314 |
* @since 2.8.0 |
|
315 |
* |
|
316 |
* @param string $text Text to translate. |
|
317 |
* @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
|
318 |
* Default 'default'. |
0 | 319 |
* @return string Translated text on success, original text on failure. |
320 |
*/ |
|
321 |
function esc_attr__( $text, $domain = 'default' ) { |
|
322 |
return esc_attr( translate( $text, $domain ) ); |
|
323 |
} |
|
324 |
||
325 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
* Retrieves the translation of $text and escapes it for safe use in HTML output. |
0 | 327 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* If there is no translation, or the text domain isn't loaded, the original text |
9 | 329 |
* is escaped and returned. |
0 | 330 |
* |
331 |
* @since 2.8.0 |
|
332 |
* |
|
333 |
* @param string $text Text to translate. |
|
334 |
* @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
|
335 |
* Default 'default'. |
16 | 336 |
* @return string Translated text. |
0 | 337 |
*/ |
338 |
function esc_html__( $text, $domain = 'default' ) { |
|
339 |
return esc_html( translate( $text, $domain ) ); |
|
340 |
} |
|
341 |
||
342 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
* Displays translated text. |
0 | 344 |
* |
345 |
* @since 1.2.0 |
|
346 |
* |
|
347 |
* @param string $text Text to translate. |
|
348 |
* @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
|
349 |
* Default 'default'. |
0 | 350 |
*/ |
351 |
function _e( $text, $domain = 'default' ) { |
|
352 |
echo translate( $text, $domain ); |
|
353 |
} |
|
354 |
||
355 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
356 |
* Displays translated text that has been escaped for safe use in an attribute. |
0 | 357 |
* |
16 | 358 |
* Encodes `< > & " '` (less than, greater than, ampersand, double quote, single quote). |
359 |
* Will never double encode entities. |
|
360 |
* |
|
361 |
* If you need the value for use in PHP, use esc_attr__(). |
|
362 |
* |
|
0 | 363 |
* @since 2.8.0 |
364 |
* |
|
365 |
* @param string $text Text to translate. |
|
366 |
* @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
|
367 |
* Default 'default'. |
0 | 368 |
*/ |
369 |
function esc_attr_e( $text, $domain = 'default' ) { |
|
370 |
echo esc_attr( translate( $text, $domain ) ); |
|
371 |
} |
|
372 |
||
373 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
* Displays translated text that has been escaped for safe use in HTML output. |
0 | 375 |
* |
16 | 376 |
* If there is no translation, or the text domain isn't loaded, the original text |
377 |
* is escaped and displayed. |
|
378 |
* |
|
379 |
* If you need the value for use in PHP, use esc_html__(). |
|
380 |
* |
|
0 | 381 |
* @since 2.8.0 |
382 |
* |
|
383 |
* @param string $text Text to translate. |
|
384 |
* @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
|
385 |
* Default 'default'. |
0 | 386 |
*/ |
387 |
function esc_html_e( $text, $domain = 'default' ) { |
|
388 |
echo esc_html( translate( $text, $domain ) ); |
|
389 |
} |
|
390 |
||
391 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
392 |
* Retrieves translated string with gettext context. |
0 | 393 |
* |
394 |
* Quite a few times, there will be collisions with similar translatable text |
|
395 |
* found in more than two places, but with different translated context. |
|
396 |
* |
|
397 |
* By including the context in the pot file, translators can translate the two |
|
398 |
* strings differently. |
|
399 |
* |
|
400 |
* @since 2.8.0 |
|
401 |
* |
|
402 |
* @param string $text Text to translate. |
|
403 |
* @param string $context Context information for the translators. |
|
404 |
* @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
|
405 |
* Default 'default'. |
0 | 406 |
* @return string Translated context string without pipe. |
407 |
*/ |
|
408 |
function _x( $text, $context, $domain = 'default' ) { |
|
409 |
return translate_with_gettext_context( $text, $context, $domain ); |
|
410 |
} |
|
411 |
||
412 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
* Displays translated string with gettext context. |
0 | 414 |
* |
415 |
* @since 3.0.0 |
|
416 |
* |
|
417 |
* @param string $text Text to translate. |
|
418 |
* @param string $context Context information for the translators. |
|
419 |
* @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
|
420 |
* Default 'default'. |
0 | 421 |
*/ |
422 |
function _ex( $text, $context, $domain = 'default' ) { |
|
423 |
echo _x( $text, $context, $domain ); |
|
424 |
} |
|
425 |
||
426 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
* Translates string with gettext context, and escapes it for safe use in an attribute. |
0 | 428 |
* |
16 | 429 |
* If there is no translation, or the text domain isn't loaded, the original text |
430 |
* is escaped and returned. |
|
431 |
* |
|
0 | 432 |
* @since 2.8.0 |
433 |
* |
|
434 |
* @param string $text Text to translate. |
|
435 |
* @param string $context Context information for the translators. |
|
436 |
* @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
|
437 |
* Default 'default'. |
16 | 438 |
* @return string Translated text. |
0 | 439 |
*/ |
440 |
function esc_attr_x( $text, $context, $domain = 'default' ) { |
|
441 |
return esc_attr( translate_with_gettext_context( $text, $context, $domain ) ); |
|
442 |
} |
|
443 |
||
444 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
* Translates string with gettext context, and escapes it for safe use in HTML output. |
0 | 446 |
* |
16 | 447 |
* If there is no translation, or the text domain isn't loaded, the original text |
448 |
* is escaped and returned. |
|
449 |
* |
|
0 | 450 |
* @since 2.9.0 |
451 |
* |
|
452 |
* @param string $text Text to translate. |
|
453 |
* @param string $context Context information for the translators. |
|
454 |
* @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
|
455 |
* Default 'default'. |
0 | 456 |
* @return string Translated text. |
457 |
*/ |
|
458 |
function esc_html_x( $text, $context, $domain = 'default' ) { |
|
459 |
return esc_html( translate_with_gettext_context( $text, $context, $domain ) ); |
|
460 |
} |
|
461 |
||
462 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* Translates and retrieves the singular or plural form based on the supplied number. |
0 | 464 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* 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
|
466 |
* number is singular or plural. |
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 |
* Example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 471 |
* |
472 |
* @since 2.8.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
* @since 5.5.0 Introduced `ngettext-{$domain}` filter. |
0 | 474 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @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
|
476 |
* @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
|
477 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 478 |
* @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
|
479 |
* Default 'default'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @return string The translated singular or plural form. |
0 | 481 |
*/ |
482 |
function _n( $single, $plural, $number, $domain = 'default' ) { |
|
483 |
$translations = get_translations_for_domain( $domain ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
$translation = $translations->translate_plural( $single, $plural, $number ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
|
0 | 486 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* Filters the singular or plural form of a string. |
0 | 488 |
* |
489 |
* @since 2.2.0 |
|
490 |
* |
|
491 |
* @param string $translation Translated text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @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
|
493 |
* @param string $plural The text to be used if the number is plural. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
494 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 495 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
496 |
*/ |
|
16 | 497 |
$translation = apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); |
498 |
||
499 |
/** |
|
500 |
* Filters the singular or plural form of a string for a domain. |
|
501 |
* |
|
19 | 502 |
* The dynamic portion of the hook name, `$domain`, refers to the text domain. |
16 | 503 |
* |
504 |
* @since 5.5.0 |
|
505 |
* |
|
506 |
* @param string $translation Translated text. |
|
507 |
* @param string $single The text to be used if the number is singular. |
|
508 |
* @param string $plural The text to be used if the number is plural. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
* @param int $number The number to compare against to use either the singular or plural form. |
16 | 510 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
511 |
*/ |
|
512 |
$translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain ); |
|
513 |
||
514 |
return $translation; |
|
0 | 515 |
} |
516 |
||
517 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* 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
|
519 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* This is a hybrid of _n() and _x(). It supports context and plurals. |
0 | 521 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* 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
|
523 |
* number is singular or plural. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* 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
|
526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* 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
|
528 |
* printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) ); |
0 | 529 |
* |
530 |
* @since 2.8.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
* @since 5.5.0 Introduced `ngettext_with_context-{$domain}` filter. |
0 | 532 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
* @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
|
534 |
* @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
|
535 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 536 |
* @param string $context Context information for the translators. |
537 |
* @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
|
538 |
* Default 'default'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
* @return string The translated singular or plural form. |
0 | 540 |
*/ |
9 | 541 |
function _nx( $single, $plural, $number, $context, $domain = 'default' ) { |
0 | 542 |
$translations = get_translations_for_domain( $domain ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
$translation = $translations->translate_plural( $single, $plural, $number, $context ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
|
0 | 545 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
* Filters the singular or plural form of a string with gettext context. |
0 | 547 |
* |
548 |
* @since 2.8.0 |
|
549 |
* |
|
550 |
* @param string $translation Translated text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* @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
|
552 |
* @param string $plural The text to be used if the number is plural. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
553 |
* @param int $number The number to compare against to use either the singular or plural form. |
0 | 554 |
* @param string $context Context information for the translators. |
555 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
556 |
*/ |
|
16 | 557 |
$translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); |
558 |
||
559 |
/** |
|
560 |
* Filters the singular or plural form of a string with gettext context for a domain. |
|
561 |
* |
|
19 | 562 |
* The dynamic portion of the hook name, `$domain`, refers to the text domain. |
16 | 563 |
* |
564 |
* @since 5.5.0 |
|
565 |
* |
|
566 |
* @param string $translation Translated text. |
|
567 |
* @param string $single The text to be used if the number is singular. |
|
568 |
* @param string $plural The text to be used if the number is plural. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
569 |
* @param int $number The number to compare against to use either the singular or plural form. |
16 | 570 |
* @param string $context Context information for the translators. |
571 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
572 |
*/ |
|
573 |
$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain ); |
|
574 |
||
575 |
return $translation; |
|
0 | 576 |
} |
577 |
||
578 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* Registers plural strings in POT file, but does not translate them. |
0 | 580 |
* |
581 |
* 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
|
582 |
* strings and use them later when the number is known. |
0 | 583 |
* |
584 |
* Example: |
|
5 | 585 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* $message = _n_noop( '%s post', '%s posts', 'text-domain' ); |
5 | 587 |
* ... |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 589 |
* |
590 |
* @since 2.5.0 |
|
591 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* @param string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* @param string $plural Plural form to be localized. |
0 | 594 |
* @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
|
595 |
* Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
* @return array { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* Array of translation information for the strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
599 |
* @type string $0 Singular form to be localized. No longer used. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
600 |
* @type string $1 Plural form to be localized. No longer used. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
601 |
* @type string $singular Singular form to be localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
602 |
* @type string $plural Plural form to be localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
603 |
* @type null $context Context information for the translators. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
604 |
* @type string|null $domain Text domain. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* } |
0 | 606 |
*/ |
607 |
function _n_noop( $singular, $plural, $domain = null ) { |
|
9 | 608 |
return array( |
609 |
0 => $singular, |
|
610 |
1 => $plural, |
|
611 |
'singular' => $singular, |
|
612 |
'plural' => $plural, |
|
613 |
'context' => null, |
|
614 |
'domain' => $domain, |
|
615 |
); |
|
0 | 616 |
} |
617 |
||
618 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* 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
|
620 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* 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
|
622 |
* 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
|
623 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* 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
|
625 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* $messages = array( |
9 | 627 |
* 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ), |
628 |
* 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* $message = $messages[ $type ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 633 |
* |
634 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* @param string $singular Singular form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* @param string $plural Plural form to be localized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* @param string $context Context information for the translators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* @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
|
640 |
* Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* @return array { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* Array of translation information for the strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* |
19 | 644 |
* @type string $0 Singular form to be localized. No longer used. |
645 |
* @type string $1 Plural form to be localized. No longer used. |
|
646 |
* @type string $2 Context information for the translators. No longer used. |
|
647 |
* @type string $singular Singular form to be localized. |
|
648 |
* @type string $plural Plural form to be localized. |
|
649 |
* @type string $context Context information for the translators. |
|
650 |
* @type string|null $domain Text domain. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
* } |
0 | 652 |
*/ |
653 |
function _nx_noop( $singular, $plural, $context, $domain = null ) { |
|
9 | 654 |
return array( |
655 |
0 => $singular, |
|
656 |
1 => $plural, |
|
657 |
2 => $context, |
|
658 |
'singular' => $singular, |
|
659 |
'plural' => $plural, |
|
660 |
'context' => $context, |
|
661 |
'domain' => $domain, |
|
662 |
); |
|
0 | 663 |
} |
664 |
||
665 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
666 |
* Translates and returns the singular or plural form of a string that's been registered |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
* with _n_noop() or _nx_noop(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* 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
|
670 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
* Example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
* $message = _n_noop( '%s post', '%s posts', 'text-domain' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) ); |
0 | 676 |
* |
677 |
* @since 3.1.0 |
|
678 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
679 |
* @param array $nooped_plural { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
680 |
* Array that is usually a return value from _n_noop() or _nx_noop(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
681 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
682 |
* @type string $singular Singular form to be localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
683 |
* @type string $plural Plural form to be localized. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
684 |
* @type string|null $context Context information for the translators. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
685 |
* @type string|null $domain Text domain. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
686 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
* @param int $count Number of objects. |
0 | 688 |
* @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
|
689 |
* a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
690 |
* @return string Either $singular or $plural translated text. |
0 | 691 |
*/ |
692 |
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { |
|
9 | 693 |
if ( $nooped_plural['domain'] ) { |
0 | 694 |
$domain = $nooped_plural['domain']; |
9 | 695 |
} |
0 | 696 |
|
9 | 697 |
if ( $nooped_plural['context'] ) { |
0 | 698 |
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); |
9 | 699 |
} else { |
0 | 700 |
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain ); |
9 | 701 |
} |
0 | 702 |
} |
703 |
||
704 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
* Loads a .mo file into the text domain $domain. |
0 | 706 |
* |
707 |
* If the text domain already exists, the translations will be merged. If both |
|
708 |
* sets have the same string, the translation from the original value will be taken. |
|
709 |
* |
|
710 |
* On success, the .mo file will be placed in the $l10n global by $domain |
|
711 |
* and will be a MO object. |
|
712 |
* |
|
713 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
714 |
* @since 6.1.0 Added the `$locale` parameter. |
0 | 715 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
716 |
* @global MO[] $l10n An array of all currently loaded text domains. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
717 |
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
718 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* |
0 | 720 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
721 |
* @param string $mofile Path to the .mo file. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
722 |
* @param string $locale Optional. Locale. Default is the current locale. |
0 | 723 |
* @return bool True on success, false on failure. |
724 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
725 |
function load_textdomain( $domain, $mofile, $locale = null ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
/** @var WP_Textdomain_Registry $wp_textdomain_registry */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
727 |
global $l10n, $l10n_unloaded, $wp_textdomain_registry; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
$l10n_unloaded = (array) $l10n_unloaded; |
0 | 730 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
731 |
if ( ! is_string( $domain ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
732 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
733 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
734 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
735 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
736 |
* Filters whether to short-circuit loading .mo file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
737 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
738 |
* Returning a non-null value from the filter will effectively short-circuit |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
739 |
* the loading, returning the passed value instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
740 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
741 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
742 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
743 |
* @param bool|null $loaded The result of loading a .mo file. Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
744 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
745 |
* @param string $mofile Path to the MO file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
746 |
* @param string|null $locale Locale. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
747 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
748 |
$loaded = apply_filters( 'pre_load_textdomain', null, $domain, $mofile, $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
749 |
if ( null !== $loaded ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
750 |
if ( true === $loaded ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
751 |
unset( $l10n_unloaded[ $domain ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
752 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
753 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
754 |
return $loaded; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
755 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
756 |
|
0 | 757 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
* Filters whether to override the .mo file loading. |
0 | 759 |
* |
760 |
* @since 2.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
761 |
* @since 6.2.0 Added the `$locale` parameter. |
0 | 762 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
763 |
* @param bool $override Whether to override the .mo file loading. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
764 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
765 |
* @param string $mofile Path to the MO file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
766 |
* @param string|null $locale Locale. |
0 | 767 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
768 |
$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile, $locale ); |
0 | 769 |
|
16 | 770 |
if ( true === (bool) $plugin_override ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
unset( $l10n_unloaded[ $domain ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
|
0 | 773 |
return true; |
774 |
} |
|
775 |
||
776 |
/** |
|
777 |
* Fires before the MO translation file is loaded. |
|
778 |
* |
|
779 |
* @since 2.9.0 |
|
780 |
* |
|
781 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
782 |
* @param string $mofile Path to the .mo file. |
|
783 |
*/ |
|
784 |
do_action( 'load_textdomain', $domain, $mofile ); |
|
785 |
||
786 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
* Filters MO file path for loading translations for a specific text domain. |
0 | 788 |
* |
789 |
* @since 2.9.0 |
|
790 |
* |
|
791 |
* @param string $mofile Path to the MO file. |
|
792 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
793 |
*/ |
|
794 |
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); |
|
795 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
796 |
if ( ! $locale ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
797 |
$locale = determine_locale(); |
9 | 798 |
} |
0 | 799 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
800 |
$i18n_controller = WP_Translation_Controller::get_instance(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
801 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
802 |
// Ensures the correct locale is set as the current one, in case it was filtered. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
803 |
$i18n_controller->set_locale( $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
804 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
805 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
806 |
* Filters the preferred file format for translation files. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
807 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
808 |
* Can be used to disable the use of PHP files for translations. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
809 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
810 |
* @since 6.5.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
811 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
812 |
* @param string $preferred_format Preferred file format. Possible values: 'php', 'mo'. Default: 'php'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
813 |
* @param string $domain The text domain. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
814 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
815 |
$preferred_format = apply_filters( 'translation_file_format', 'php', $domain ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
816 |
if ( ! in_array( $preferred_format, array( 'php', 'mo' ), true ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
817 |
$preferred_format = 'php'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
818 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
819 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
820 |
$translation_files = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
822 |
if ( 'mo' !== $preferred_format ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
823 |
$translation_files[] = substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) ); |
9 | 824 |
} |
0 | 825 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
826 |
$translation_files[] = $mofile; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
827 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
828 |
foreach ( $translation_files as $file ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
829 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
830 |
* Filters the file path for loading translations for the given text domain. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
831 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
832 |
* Similar to the {@see 'load_textdomain_mofile'} filter with the difference that |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
833 |
* the file path could be for an MO or PHP file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
834 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
835 |
* @since 6.5.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
836 |
* @since 6.6.0 Added the `$locale` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
837 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
838 |
* @param string $file Path to the translation file to load. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
839 |
* @param string $domain The text domain. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
840 |
* @param string $locale The locale. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
841 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
842 |
$file = (string) apply_filters( 'load_translation_file', $file, $domain, $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
843 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
844 |
$success = $i18n_controller->load_file( $file, $domain, $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
845 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
if ( $success ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
847 |
if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof MO ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
848 |
$i18n_controller->load_file( $l10n[ $domain ]->get_filename(), $domain, $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
849 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
850 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
851 |
// Unset NOOP_Translations reference in get_translations_for_domain(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
852 |
unset( $l10n[ $domain ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
853 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
854 |
$l10n[ $domain ] = new WP_Translations( $i18n_controller, $domain ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
855 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
856 |
$wp_textdomain_registry->set( $domain, $locale, dirname( $file ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
857 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
858 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
859 |
} |
9 | 860 |
} |
0 | 861 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
862 |
return false; |
0 | 863 |
} |
864 |
||
865 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
866 |
* Unloads translations for a text domain. |
0 | 867 |
* |
868 |
* @since 3.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
869 |
* @since 6.1.0 Added the `$reloadable` parameter. |
0 | 870 |
* |
9 | 871 |
* @global MO[] $l10n An array of all currently loaded text domains. |
872 |
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
874 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
875 |
* @param bool $reloadable Whether the text domain can be loaded just-in-time again. |
0 | 876 |
* @return bool Whether textdomain was unloaded. |
877 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
878 |
function unload_textdomain( $domain, $reloadable = false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
global $l10n, $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
$l10n_unloaded = (array) $l10n_unloaded; |
0 | 882 |
|
883 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
* Filters whether to override the text domain unloading. |
0 | 885 |
* |
886 |
* @since 3.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
887 |
* @since 6.1.0 Added the `$reloadable` parameter. |
0 | 888 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
889 |
* @param bool $override Whether to override the text domain unloading. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
890 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
891 |
* @param bool $reloadable Whether the text domain can be loaded just-in-time again. |
0 | 892 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
893 |
$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain, $reloadable ); |
0 | 894 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
if ( $plugin_override ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
896 |
if ( ! $reloadable ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
897 |
$l10n_unloaded[ $domain ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
898 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
|
0 | 900 |
return true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
} |
0 | 902 |
|
903 |
/** |
|
904 |
* Fires before the text domain is unloaded. |
|
905 |
* |
|
906 |
* @since 3.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
907 |
* @since 6.1.0 Added the `$reloadable` parameter. |
0 | 908 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
909 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
910 |
* @param bool $reloadable Whether the text domain can be loaded just-in-time again. |
0 | 911 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
912 |
do_action( 'unload_textdomain', $domain, $reloadable ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
913 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
914 |
// Since multiple locales are supported, reloadable text domains don't actually need to be unloaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
915 |
if ( ! $reloadable ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
916 |
WP_Translation_Controller::get_instance()->unload_textdomain( $domain ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
917 |
} |
0 | 918 |
|
9 | 919 |
if ( isset( $l10n[ $domain ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
920 |
if ( $l10n[ $domain ] instanceof NOOP_Translations ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
921 |
unset( $l10n[ $domain ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
922 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
923 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
924 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
925 |
|
9 | 926 |
unset( $l10n[ $domain ] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
928 |
if ( ! $reloadable ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
929 |
$l10n_unloaded[ $domain ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
930 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
|
0 | 932 |
return true; |
933 |
} |
|
934 |
||
935 |
return false; |
|
936 |
} |
|
937 |
||
938 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
939 |
* Loads default translated strings based on locale. |
0 | 940 |
* |
941 |
* Loads the .mo file in WP_LANG_DIR constant path from WordPress root. |
|
942 |
* The translated (.mo) file is named based on the locale. |
|
943 |
* |
|
944 |
* @see load_textdomain() |
|
945 |
* |
|
946 |
* @since 1.5.0 |
|
5 | 947 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
* @param string $locale Optional. Locale to load. Default is the value of get_locale(). |
5 | 949 |
* @return bool Whether the textdomain was loaded. |
0 | 950 |
*/ |
5 | 951 |
function load_default_textdomain( $locale = null ) { |
952 |
if ( null === $locale ) { |
|
9 | 953 |
$locale = determine_locale(); |
5 | 954 |
} |
0 | 955 |
|
5 | 956 |
// Unload previously loaded strings so we can switch translations. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
957 |
unload_textdomain( 'default', true ); |
5 | 958 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
959 |
$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo", $locale ); |
0 | 960 |
|
9 | 961 |
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
962 |
load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo", $locale ); |
5 | 963 |
return $return; |
0 | 964 |
} |
965 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
967 |
load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo", $locale ); |
5 | 968 |
} |
0 | 969 |
|
9 | 970 |
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
971 |
load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo", $locale ); |
9 | 972 |
} |
0 | 973 |
|
5 | 974 |
return $return; |
0 | 975 |
} |
976 |
||
977 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
* Loads a plugin's translated strings. |
0 | 979 |
* |
980 |
* If the path is not given then it will be the root of the plugin directory. |
|
981 |
* |
|
982 |
* The .mo file should be named based on the text domain with a dash, and then the locale exactly. |
|
983 |
* |
|
984 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 986 |
* |
9 | 987 |
* @param string $domain Unique identifier for retrieving translated strings |
988 |
* @param string|false $deprecated Optional. Deprecated. Use the $plugin_rel_path parameter instead. |
|
989 |
* Default false. |
|
990 |
* @param string|false $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides. |
|
991 |
* Default false. |
|
5 | 992 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
0 | 993 |
*/ |
994 |
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
995 |
/** @var WP_Textdomain_Registry $wp_textdomain_registry */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
996 |
global $wp_textdomain_registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
997 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
998 |
if ( ! is_string( $domain ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
999 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1000 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1001 |
|
0 | 1002 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
* Filters a plugin's locale. |
0 | 1004 |
* |
1005 |
* @since 3.0.0 |
|
1006 |
* |
|
1007 |
* @param string $locale The plugin's current locale. |
|
1008 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
1009 |
*/ |
|
9 | 1010 |
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
$mofile = $domain . '-' . $locale . '.mo'; |
0 | 1013 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
// Try to load from the languages directory first. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1015 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile, $locale ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
} |
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 |
if ( false !== $plugin_rel_path ) { |
0 | 1020 |
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); |
5 | 1021 |
} elseif ( false !== $deprecated ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
_deprecated_argument( __FUNCTION__, '2.7.0' ); |
0 | 1023 |
$path = ABSPATH . trim( $deprecated, '/' ); |
1024 |
} else { |
|
1025 |
$path = WP_PLUGIN_DIR; |
|
1026 |
} |
|
1027 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
$wp_textdomain_registry->set_custom_path( $domain, $path ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1029 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1030 |
return load_textdomain( $domain, $path . '/' . $mofile, $locale ); |
0 | 1031 |
} |
1032 |
||
1033 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1034 |
* Loads the translated strings for a plugin residing in the mu-plugins directory. |
0 | 1035 |
* |
1036 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 1038 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1039 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1040 |
* |
0 | 1041 |
* @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
|
1042 |
* @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
|
1043 |
* file resides. Default empty string. |
0 | 1044 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
1045 |
*/ |
|
1046 |
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
/** @var WP_Textdomain_Registry $wp_textdomain_registry */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1048 |
global $wp_textdomain_registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1049 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1050 |
if ( ! is_string( $domain ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1051 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1052 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1053 |
|
5 | 1054 |
/** This filter is documented in wp-includes/l10n.php */ |
9 | 1055 |
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); |
0 | 1056 |
|
1057 |
$mofile = $domain . '-' . $locale . '.mo'; |
|
1058 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
// Try to load from the languages directory first. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1060 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile, $locale ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
$path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1066 |
$wp_textdomain_registry->set_custom_path( $domain, $path ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1067 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1068 |
return load_textdomain( $domain, $path . '/' . $mofile, $locale ); |
0 | 1069 |
} |
1070 |
||
1071 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1072 |
* Loads the theme's translated strings. |
0 | 1073 |
* |
1074 |
* If the current locale exists as a .mo file in the theme's root directory, it |
|
1075 |
* will be included in the translated strings by the $domain. |
|
1076 |
* |
|
1077 |
* The .mo files must be named based on the locale exactly. |
|
1078 |
* |
|
1079 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
0 | 1081 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1082 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1083 |
* |
18 | 1084 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
1085 |
* @param string|false $path Optional. Path to the directory containing the .mo file. |
|
1086 |
* Default false. |
|
0 | 1087 |
* @return bool True when textdomain is successfully loaded, false otherwise. |
1088 |
*/ |
|
1089 |
function load_theme_textdomain( $domain, $path = false ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1090 |
/** @var WP_Textdomain_Registry $wp_textdomain_registry */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1091 |
global $wp_textdomain_registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1092 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1093 |
if ( ! is_string( $domain ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1094 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1095 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1096 |
|
0 | 1097 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* Filters a theme's locale. |
0 | 1099 |
* |
1100 |
* @since 3.0.0 |
|
1101 |
* |
|
1102 |
* @param string $locale The theme's current locale. |
|
1103 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
1104 |
*/ |
|
9 | 1105 |
$locale = apply_filters( 'theme_locale', determine_locale(), $domain ); |
0 | 1106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
$mofile = $domain . '-' . $locale . '.mo'; |
0 | 1108 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
// Try to load from the languages directory first. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1110 |
if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile, $locale ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
} |
0 | 1113 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
if ( ! $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
$path = get_template_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1118 |
$wp_textdomain_registry->set_custom_path( $domain, $path ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1119 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1120 |
return load_textdomain( $domain, $path . '/' . $locale . '.mo', $locale ); |
0 | 1121 |
} |
1122 |
||
1123 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1124 |
* Loads the child theme's translated strings. |
0 | 1125 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1126 |
* If the current locale exists as a .mo file in the child theme's |
0 | 1127 |
* root directory, it will be included in the translated strings by the $domain. |
1128 |
* |
|
1129 |
* The .mo files must be named based on the locale exactly. |
|
1130 |
* |
|
1131 |
* @since 2.9.0 |
|
1132 |
* |
|
18 | 1133 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
1134 |
* @param string|false $path Optional. Path to the directory containing the .mo file. |
|
1135 |
* Default false. |
|
0 | 1136 |
* @return bool True when the theme textdomain is successfully loaded, false otherwise. |
1137 |
*/ |
|
1138 |
function load_child_theme_textdomain( $domain, $path = false ) { |
|
9 | 1139 |
if ( ! $path ) { |
0 | 1140 |
$path = get_stylesheet_directory(); |
9 | 1141 |
} |
0 | 1142 |
return load_theme_textdomain( $domain, $path ); |
1143 |
} |
|
1144 |
||
1145 |
/** |
|
9 | 1146 |
* Loads the script translated strings. |
1147 |
* |
|
1148 |
* @since 5.0.0 |
|
1149 |
* @since 5.0.2 Uses load_script_translations() to load translation data. |
|
1150 |
* @since 5.1.0 The `$domain` parameter was made optional. |
|
1151 |
* |
|
1152 |
* @see WP_Scripts::set_translations() |
|
1153 |
* |
|
1154 |
* @param string $handle Name of the script to register a translation domain to. |
|
1155 |
* @param string $domain Optional. Text domain. Default 'default'. |
|
1156 |
* @param string $path Optional. The full file path to the directory containing translation files. |
|
18 | 1157 |
* @return string|false The translated strings in JSON encoding on success, |
1158 |
* false if the script textdomain could not be loaded. |
|
9 | 1159 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1160 |
function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { |
9 | 1161 |
$wp_scripts = wp_scripts(); |
1162 |
||
1163 |
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
|
1164 |
return false; |
|
1165 |
} |
|
1166 |
||
1167 |
$path = untrailingslashit( $path ); |
|
1168 |
$locale = determine_locale(); |
|
1169 |
||
1170 |
// If a path was given and the handle file exists simply return it. |
|
16 | 1171 |
$file_base = 'default' === $domain ? $locale : $domain . '-' . $locale; |
9 | 1172 |
$handle_filename = $file_base . '-' . $handle . '.json'; |
1173 |
||
1174 |
if ( $path ) { |
|
1175 |
$translations = load_script_translations( $path . '/' . $handle_filename, $handle, $domain ); |
|
1176 |
||
1177 |
if ( $translations ) { |
|
1178 |
return $translations; |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
1182 |
$src = $wp_scripts->registered[ $handle ]->src; |
|
1183 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1184 |
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && str_starts_with( $src, $wp_scripts->content_url ) ) ) { |
9 | 1185 |
$src = $wp_scripts->base_url . $src; |
1186 |
} |
|
1187 |
||
1188 |
$relative = false; |
|
1189 |
$languages_path = WP_LANG_DIR; |
|
1190 |
||
1191 |
$src_url = wp_parse_url( $src ); |
|
1192 |
$content_url = wp_parse_url( content_url() ); |
|
16 | 1193 |
$plugins_url = wp_parse_url( plugins_url() ); |
9 | 1194 |
$site_url = wp_parse_url( site_url() ); |
1195 |
||
1196 |
// If the host is the same or it's a relative URL. |
|
1197 |
if ( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1198 |
( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path'], $content_url['path'] ) ) && |
18 | 1199 |
( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] ) |
9 | 1200 |
) { |
1201 |
// Make the src relative the specific plugin or theme. |
|
16 | 1202 |
if ( isset( $content_url['path'] ) ) { |
1203 |
$relative = substr( $src_url['path'], strlen( $content_url['path'] ) ); |
|
1204 |
} else { |
|
1205 |
$relative = $src_url['path']; |
|
1206 |
} |
|
1207 |
$relative = trim( $relative, '/' ); |
|
9 | 1208 |
$relative = explode( '/', $relative ); |
1209 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1210 |
$languages_path = WP_LANG_DIR . '/plugins'; |
9 | 1211 |
|
16 | 1212 |
$relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>. |
1213 |
$relative = implode( '/', $relative ); |
|
1214 |
} elseif ( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1215 |
( ! isset( $plugins_url['path'] ) || str_starts_with( $src_url['path'], $plugins_url['path'] ) ) && |
18 | 1216 |
( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) |
16 | 1217 |
) { |
1218 |
// Make the src relative the specific plugin. |
|
1219 |
if ( isset( $plugins_url['path'] ) ) { |
|
1220 |
$relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) ); |
|
1221 |
} else { |
|
1222 |
$relative = $src_url['path']; |
|
1223 |
} |
|
1224 |
$relative = trim( $relative, '/' ); |
|
1225 |
$relative = explode( '/', $relative ); |
|
1226 |
||
1227 |
$languages_path = WP_LANG_DIR . '/plugins'; |
|
1228 |
||
1229 |
$relative = array_slice( $relative, 1 ); // Remove <plugin name>. |
|
9 | 1230 |
$relative = implode( '/', $relative ); |
18 | 1231 |
} elseif ( ! isset( $src_url['host'] ) || ! isset( $site_url['host'] ) || $src_url['host'] === $site_url['host'] ) { |
9 | 1232 |
if ( ! isset( $site_url['path'] ) ) { |
1233 |
$relative = trim( $src_url['path'], '/' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1234 |
} elseif ( str_starts_with( $src_url['path'], trailingslashit( $site_url['path'] ) ) ) { |
9 | 1235 |
// Make the src relative to the WP root. |
1236 |
$relative = substr( $src_url['path'], strlen( $site_url['path'] ) ); |
|
1237 |
$relative = trim( $relative, '/' ); |
|
1238 |
} |
|
1239 |
} |
|
1240 |
||
1241 |
/** |
|
1242 |
* Filters the relative path of scripts used for finding translation files. |
|
1243 |
* |
|
1244 |
* @since 5.0.2 |
|
1245 |
* |
|
16 | 1246 |
* @param string|false $relative The relative path of the script. False if it could not be determined. |
1247 |
* @param string $src The full source URL of the script. |
|
9 | 1248 |
*/ |
1249 |
$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src ); |
|
1250 |
||
1251 |
// If the source is not from WP. |
|
1252 |
if ( false === $relative ) { |
|
1253 |
return load_script_translations( false, $handle, $domain ); |
|
1254 |
} |
|
1255 |
||
1256 |
// Translations are always based on the unminified filename. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1257 |
if ( str_ends_with( $relative, '.min.js' ) ) { |
9 | 1258 |
$relative = substr( $relative, 0, -7 ) . '.js'; |
1259 |
} |
|
1260 |
||
1261 |
$md5_filename = $file_base . '-' . md5( $relative ) . '.json'; |
|
1262 |
||
1263 |
if ( $path ) { |
|
1264 |
$translations = load_script_translations( $path . '/' . $md5_filename, $handle, $domain ); |
|
1265 |
||
1266 |
if ( $translations ) { |
|
1267 |
return $translations; |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
$translations = load_script_translations( $languages_path . '/' . $md5_filename, $handle, $domain ); |
|
1272 |
||
1273 |
if ( $translations ) { |
|
1274 |
return $translations; |
|
1275 |
} |
|
1276 |
||
1277 |
return load_script_translations( false, $handle, $domain ); |
|
1278 |
} |
|
1279 |
||
1280 |
/** |
|
1281 |
* Loads the translation data for the given script handle and text domain. |
|
1282 |
* |
|
1283 |
* @since 5.0.2 |
|
1284 |
* |
|
1285 |
* @param string|false $file Path to the translation file to load. False if there isn't one. |
|
1286 |
* @param string $handle Name of the script to register a translation domain to. |
|
1287 |
* @param string $domain The text domain. |
|
18 | 1288 |
* @return string|false The JSON-encoded translated strings for the given script handle and text domain. |
1289 |
* False if there are none. |
|
9 | 1290 |
*/ |
1291 |
function load_script_translations( $file, $handle, $domain ) { |
|
1292 |
/** |
|
1293 |
* Pre-filters script translations for the given file, script handle and text domain. |
|
1294 |
* |
|
1295 |
* Returning a non-null value allows to override the default logic, effectively short-circuiting the function. |
|
1296 |
* |
|
1297 |
* @since 5.0.2 |
|
1298 |
* |
|
16 | 1299 |
* @param string|false|null $translations JSON-encoded translation data. Default null. |
1300 |
* @param string|false $file Path to the translation file to load. False if there isn't one. |
|
1301 |
* @param string $handle Name of the script to register a translation domain to. |
|
1302 |
* @param string $domain The text domain. |
|
9 | 1303 |
*/ |
1304 |
$translations = apply_filters( 'pre_load_script_translations', null, $file, $handle, $domain ); |
|
1305 |
||
1306 |
if ( null !== $translations ) { |
|
1307 |
return $translations; |
|
1308 |
} |
|
1309 |
||
1310 |
/** |
|
1311 |
* Filters the file path for loading script translations for the given script handle and text domain. |
|
1312 |
* |
|
1313 |
* @since 5.0.2 |
|
1314 |
* |
|
1315 |
* @param string|false $file Path to the translation file to load. False if there isn't one. |
|
1316 |
* @param string $handle Name of the script to register a translation domain to. |
|
1317 |
* @param string $domain The text domain. |
|
1318 |
*/ |
|
1319 |
$file = apply_filters( 'load_script_translation_file', $file, $handle, $domain ); |
|
1320 |
||
1321 |
if ( ! $file || ! is_readable( $file ) ) { |
|
1322 |
return false; |
|
1323 |
} |
|
1324 |
||
1325 |
$translations = file_get_contents( $file ); |
|
1326 |
||
1327 |
/** |
|
1328 |
* Filters script translations for the given file, script handle and text domain. |
|
1329 |
* |
|
1330 |
* @since 5.0.2 |
|
1331 |
* |
|
1332 |
* @param string $translations JSON-encoded translation data. |
|
1333 |
* @param string $file Path to the translation file that was loaded. |
|
1334 |
* @param string $handle Name of the script to register a translation domain to. |
|
1335 |
* @param string $domain The text domain. |
|
1336 |
*/ |
|
1337 |
return apply_filters( 'load_script_translations', $translations, $file, $handle, $domain ); |
|
1338 |
} |
|
1339 |
||
1340 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1341 |
* Loads plugin and theme text domains just-in-time. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
* 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
|
1344 |
* the translation file from `wp-content/languages`, removing the need |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1345 |
* to call load_plugin_textdomain() or load_theme_textdomain(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1350 |
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1351 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* @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
|
1354 |
* @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
|
1355 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
function _load_textdomain_just_in_time( $domain ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1357 |
/** @var WP_Textdomain_Registry $wp_textdomain_registry */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1358 |
global $l10n_unloaded, $wp_textdomain_registry; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
$l10n_unloaded = (array) $l10n_unloaded; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
// 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
|
1363 |
if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1367 |
if ( ! $wp_textdomain_registry->has( $domain ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1371 |
$locale = determine_locale(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1372 |
$path = $wp_textdomain_registry->get( $domain, $locale ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1373 |
if ( ! $path ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1374 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1375 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1376 |
// Themes with their language directory outside of WP_LANG_DIR have a different file name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1377 |
$template_directory = trailingslashit( get_template_directory() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1378 |
$stylesheet_directory = trailingslashit( get_stylesheet_directory() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1379 |
if ( str_starts_with( $path, $template_directory ) || str_starts_with( $path, $stylesheet_directory ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1380 |
$mofile = "{$path}{$locale}.mo"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1381 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1382 |
$mofile = "{$path}{$domain}-{$locale}.mo"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1385 |
return load_textdomain( $domain, $mofile, $locale ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1389 |
* Returns the Translations instance for a text domain. |
0 | 1390 |
* |
1391 |
* If there isn't one, returns empty Translations instance. |
|
1392 |
* |
|
5 | 1393 |
* @since 2.8.0 |
1394 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1395 |
* @global MO[] $l10n An array of all currently loaded text domains. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
* |
0 | 1397 |
* @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
|
1398 |
* @return Translations|NOOP_Translations A Translations instance. |
0 | 1399 |
*/ |
1400 |
function get_translations_for_domain( $domain ) { |
|
1401 |
global $l10n; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
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
|
1403 |
return $l10n[ $domain ]; |
0 | 1404 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
static $noop_translations = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
if ( null === $noop_translations ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1408 |
$noop_translations = new NOOP_Translations(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1411 |
$l10n[ $domain ] = &$noop_translations; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1412 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
return $noop_translations; |
0 | 1414 |
} |
1415 |
||
1416 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1417 |
* Determines whether there are translations for the text domain. |
0 | 1418 |
* |
1419 |
* @since 3.0.0 |
|
5 | 1420 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1421 |
* @global MO[] $l10n An array of all currently loaded text domains. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
* |
0 | 1423 |
* @param string $domain Text domain. Unique identifier for retrieving translated strings. |
1424 |
* @return bool Whether there are translations. |
|
1425 |
*/ |
|
1426 |
function is_textdomain_loaded( $domain ) { |
|
1427 |
global $l10n; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1428 |
return isset( $l10n[ $domain ] ) && ! $l10n[ $domain ] instanceof NOOP_Translations; |
0 | 1429 |
} |
1430 |
||
1431 |
/** |
|
1432 |
* Translates role name. |
|
1433 |
* |
|
1434 |
* Since the role names are in the database and not in the source there |
|
1435 |
* are dummy gettext calls to get them into the POT file and this function |
|
1436 |
* properly translates them back. |
|
1437 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
* The before_last_bar() call is needed, because older installations keep the roles |
0 | 1439 |
* 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
|
1440 |
* content after the last bar is easier than fixing them in the DB. New installations |
0 | 1441 |
* won't suffer from that problem. |
1442 |
* |
|
1443 |
* @since 2.8.0 |
|
9 | 1444 |
* @since 5.2.0 Added the `$domain` parameter. |
0 | 1445 |
* |
9 | 1446 |
* @param string $name The role name. |
1447 |
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
|
1448 |
* Default 'default'. |
|
0 | 1449 |
* @return string Translated role name on success, original name on failure. |
1450 |
*/ |
|
9 | 1451 |
function translate_user_role( $name, $domain = 'default' ) { |
1452 |
return translate_with_gettext_context( before_last_bar( $name ), 'User role', $domain ); |
|
0 | 1453 |
} |
1454 |
||
1455 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1456 |
* Gets all available languages based on the presence of *.mo and *.l10n.php files in a given directory. |
0 | 1457 |
* |
1458 |
* The default directory is WP_LANG_DIR. |
|
1459 |
* |
|
1460 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
* @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1462 |
* @since 6.5.0 The initial file list is now cached and also takes into account *.l10n.php files. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1463 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1464 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
0 | 1465 |
* |
1466 |
* @param string $dir A directory to search for language files. |
|
1467 |
* Default WP_LANG_DIR. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1468 |
* @return string[] An array of language codes or an empty array if no languages are present. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1469 |
* Language codes are formed by stripping the file extension from the language file names. |
0 | 1470 |
*/ |
1471 |
function get_available_languages( $dir = null ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1472 |
global $wp_textdomain_registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1473 |
|
0 | 1474 |
$languages = array(); |
1475 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1476 |
$path = is_null( $dir ) ? WP_LANG_DIR : $dir; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1477 |
$lang_files = $wp_textdomain_registry->get_language_files_from_path( $path ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1478 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
if ( $lang_files ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
foreach ( $lang_files as $lang_file ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
$lang_file = basename( $lang_file, '.mo' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1482 |
$lang_file = basename( $lang_file, '.l10n.php' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1483 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1484 |
if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1485 |
! str_starts_with( $lang_file, 'admin-' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
$languages[] = $lang_file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
} |
0 | 1489 |
} |
1490 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
* Filters the list of available language codes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
* |
16 | 1496 |
* @param string[] $languages An array of available language codes. |
1497 |
* @param string $dir The directory where the language files were found. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1499 |
return apply_filters( 'get_available_languages', array_unique( $languages ), $dir ); |
0 | 1500 |
} |
1501 |
||
1502 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1503 |
* Gets installed translations. |
0 | 1504 |
* |
1505 |
* Looks in the wp-content/languages directory for translations of |
|
1506 |
* plugins or themes. |
|
1507 |
* |
|
1508 |
* @since 3.7.0 |
|
1509 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1510 |
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1511 |
* |
0 | 1512 |
* @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. |
1513 |
* @return array Array of language data. |
|
1514 |
*/ |
|
1515 |
function wp_get_installed_translations( $type ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1516 |
global $wp_textdomain_registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1517 |
|
16 | 1518 |
if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) { |
0 | 1519 |
return array(); |
9 | 1520 |
} |
0 | 1521 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1522 |
$dir = 'core' === $type ? WP_LANG_DIR : WP_LANG_DIR . "/$type"; |
0 | 1523 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1524 |
if ( ! is_dir( $dir ) ) { |
0 | 1525 |
return array(); |
9 | 1526 |
} |
0 | 1527 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1528 |
$files = $wp_textdomain_registry->get_language_files_from_path( $dir ); |
9 | 1529 |
if ( ! $files ) { |
0 | 1530 |
return array(); |
9 | 1531 |
} |
0 | 1532 |
|
1533 |
$language_data = array(); |
|
1534 |
||
1535 |
foreach ( $files as $file ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1536 |
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?)\.(?:mo|l10n\.php)/', basename( $file ), $match ) ) { |
0 | 1537 |
continue; |
5 | 1538 |
} |
0 | 1539 |
|
1540 |
list( , $textdomain, $language ) = $match; |
|
5 | 1541 |
if ( '' === $textdomain ) { |
0 | 1542 |
$textdomain = 'default'; |
5 | 1543 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1544 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1545 |
if ( str_ends_with( $file, '.mo' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1546 |
$pofile = substr_replace( $file, '.po', - strlen( '.mo' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1547 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1548 |
if ( ! file_exists( $pofile ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1549 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1550 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1551 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1552 |
$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $pofile ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1553 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1554 |
$pofile = substr_replace( $file, '.po', - strlen( '.l10n.php' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1555 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1556 |
// If both a PO and a PHP file exist, prefer the PO file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
if ( file_exists( $pofile ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1558 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1559 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1560 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1561 |
$language_data[ $textdomain ][ $language ] = wp_get_l10n_php_file_data( $file ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1562 |
} |
0 | 1563 |
} |
1564 |
return $language_data; |
|
1565 |
} |
|
1566 |
||
1567 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1568 |
* Extracts headers from a PO file. |
0 | 1569 |
* |
1570 |
* @since 3.7.0 |
|
1571 |
* |
|
1572 |
* @param string $po_file Path to PO file. |
|
16 | 1573 |
* @return string[] Array of PO file header values keyed by header name. |
0 | 1574 |
*/ |
1575 |
function wp_get_pomo_file_data( $po_file ) { |
|
9 | 1576 |
$headers = get_file_data( |
1577 |
$po_file, |
|
1578 |
array( |
|
1579 |
'POT-Creation-Date' => '"POT-Creation-Date', |
|
1580 |
'PO-Revision-Date' => '"PO-Revision-Date', |
|
1581 |
'Project-Id-Version' => '"Project-Id-Version', |
|
1582 |
'X-Generator' => '"X-Generator', |
|
1583 |
) |
|
1584 |
); |
|
0 | 1585 |
foreach ( $headers as $header => $value ) { |
1586 |
// Remove possible contextual '\n' and closing double quote. |
|
1587 |
$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value ); |
|
1588 |
} |
|
1589 |
return $headers; |
|
1590 |
} |
|
5 | 1591 |
|
1592 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1593 |
* Extracts headers from a PHP translation file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1594 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1595 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1596 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1597 |
* @param string $php_file Path to a `.l10n.php` file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1598 |
* @return string[] Array of file header values keyed by header name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1599 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1600 |
function wp_get_l10n_php_file_data( $php_file ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1601 |
$data = (array) include $php_file; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1602 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1603 |
unset( $data['messages'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1604 |
$headers = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1605 |
'POT-Creation-Date' => 'pot-creation-date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1606 |
'PO-Revision-Date' => 'po-revision-date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1607 |
'Project-Id-Version' => 'project-id-version', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1608 |
'X-Generator' => 'x-generator', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1609 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1610 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1611 |
$result = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1612 |
'POT-Creation-Date' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1613 |
'PO-Revision-Date' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1614 |
'Project-Id-Version' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1615 |
'X-Generator' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1616 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1617 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1618 |
foreach ( $headers as $po_header => $php_header ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1619 |
if ( isset( $data[ $php_header ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1620 |
$result[ $po_header ] = $data[ $php_header ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1621 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1622 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1623 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1624 |
return $result; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1625 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1626 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1627 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1628 |
* Displays or returns a Language selector. |
5 | 1629 |
* |
1630 |
* @since 4.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
* @since 4.3.0 Introduced the `echo` argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
* @since 4.7.0 Introduced the `show_option_site_default` argument. |
9 | 1633 |
* @since 5.1.0 Introduced the `show_option_en_us` argument. |
19 | 1634 |
* @since 5.9.0 Introduced the `explicit_option_en_us` argument. |
5 | 1635 |
* |
1636 |
* @see get_available_languages() |
|
1637 |
* @see wp_get_available_translations() |
|
1638 |
* |
|
1639 |
* @param string|array $args { |
|
1640 |
* Optional. Array or string of arguments for outputting the language selector. |
|
1641 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
* @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
|
1643 |
* @type string $name Name attribute of the select element. Default 'locale'. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1644 |
* @type string[] $languages List of installed languages, contain only the locales. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
* @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
|
1647 |
* wp_get_available_translations(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
* @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
|
1649 |
* @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
|
1650 |
* boolean equivalents. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
* @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
|
1652 |
* @type bool $show_option_site_default Whether to show an option to fall back to the site's locale. Default false. |
9 | 1653 |
* @type bool $show_option_en_us Whether to show an option for English (United States). Default true. |
19 | 1654 |
* @type bool $explicit_option_en_us Whether the English (United States) option uses an explicit value of en_US |
1655 |
* instead of an empty value. Default false. |
|
5 | 1656 |
* } |
16 | 1657 |
* @return string HTML dropdown list of languages. |
5 | 1658 |
*/ |
1659 |
function wp_dropdown_languages( $args = array() ) { |
|
1660 |
||
9 | 1661 |
$parsed_args = wp_parse_args( |
1662 |
$args, |
|
1663 |
array( |
|
1664 |
'id' => 'locale', |
|
1665 |
'name' => 'locale', |
|
1666 |
'languages' => array(), |
|
1667 |
'translations' => array(), |
|
1668 |
'selected' => '', |
|
1669 |
'echo' => 1, |
|
1670 |
'show_available_translations' => true, |
|
1671 |
'show_option_site_default' => false, |
|
1672 |
'show_option_en_us' => true, |
|
19 | 1673 |
'explicit_option_en_us' => false, |
9 | 1674 |
) |
1675 |
); |
|
5 | 1676 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
// Bail if no ID or no name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
// English (United States) uses an empty string for the value attribute. |
19 | 1683 |
if ( 'en_US' === $parsed_args['selected'] && ! $parsed_args['explicit_option_en_us'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
$parsed_args['selected'] = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1686 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
$translations = $parsed_args['translations']; |
5 | 1688 |
if ( empty( $translations ) ) { |
16 | 1689 |
require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
5 | 1690 |
$translations = wp_get_available_translations(); |
1691 |
} |
|
1692 |
||
1693 |
/* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1694 |
* $parsed_args['languages'] should only contain the locales. Find the locale in |
5 | 1695 |
* $translations to get the native name. Fall back to locale. |
1696 |
*/ |
|
1697 |
$languages = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
foreach ( $parsed_args['languages'] as $locale ) { |
5 | 1699 |
if ( isset( $translations[ $locale ] ) ) { |
1700 |
$translation = $translations[ $locale ]; |
|
1701 |
$languages[] = array( |
|
1702 |
'language' => $translation['language'], |
|
1703 |
'native_name' => $translation['native_name'], |
|
1704 |
'lang' => current( $translation['iso'] ), |
|
1705 |
); |
|
1706 |
||
1707 |
// Remove installed language from available translations. |
|
1708 |
unset( $translations[ $locale ] ); |
|
1709 |
} else { |
|
1710 |
$languages[] = array( |
|
1711 |
'language' => $locale, |
|
1712 |
'native_name' => $locale, |
|
1713 |
'lang' => '', |
|
1714 |
); |
|
1715 |
} |
|
1716 |
} |
|
1717 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
$translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] ); |
5 | 1719 |
|
1720 |
// Holds the HTML markup. |
|
1721 |
$structure = array(); |
|
1722 |
||
1723 |
// List installed languages. |
|
1724 |
if ( $translations_available ) { |
|
1725 |
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; |
|
1726 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
// Site default. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
if ( $parsed_args['show_option_site_default'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
$structure[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
'<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
|
1732 |
selected( 'site-default', $parsed_args['selected'], false ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
_x( 'Site Default', 'default site language' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
|
9 | 1737 |
if ( $parsed_args['show_option_en_us'] ) { |
19 | 1738 |
$value = ( $parsed_args['explicit_option_en_us'] ) ? 'en_US' : ''; |
9 | 1739 |
$structure[] = sprintf( |
19 | 1740 |
'<option value="%s" lang="en" data-installed="1"%s>English (United States)</option>', |
1741 |
esc_attr( $value ), |
|
9 | 1742 |
selected( '', $parsed_args['selected'], false ) |
1743 |
); |
|
1744 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
|
9 | 1746 |
// List installed languages. |
5 | 1747 |
foreach ( $languages as $language ) { |
1748 |
$structure[] = sprintf( |
|
1749 |
'<option value="%s" lang="%s"%s data-installed="1">%s</option>', |
|
1750 |
esc_attr( $language['language'] ), |
|
1751 |
esc_attr( $language['lang'] ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
selected( $language['language'], $parsed_args['selected'], false ), |
5 | 1753 |
esc_html( $language['native_name'] ) |
1754 |
); |
|
1755 |
} |
|
1756 |
if ( $translations_available ) { |
|
1757 |
$structure[] = '</optgroup>'; |
|
1758 |
} |
|
1759 |
||
1760 |
// List available translations. |
|
1761 |
if ( $translations_available ) { |
|
1762 |
$structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">'; |
|
1763 |
foreach ( $translations as $translation ) { |
|
1764 |
$structure[] = sprintf( |
|
1765 |
'<option value="%s" lang="%s"%s>%s</option>', |
|
1766 |
esc_attr( $translation['language'] ), |
|
1767 |
esc_attr( current( $translation['iso'] ) ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1768 |
selected( $translation['language'], $parsed_args['selected'], false ), |
5 | 1769 |
esc_html( $translation['native_name'] ) |
1770 |
); |
|
1771 |
} |
|
1772 |
$structure[] = '</optgroup>'; |
|
1773 |
} |
|
1774 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
// Combine the output string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) ); |
18 | 1777 |
$output .= implode( "\n", $structure ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
$output .= '</select>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
if ( $parsed_args['echo'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
echo $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
return $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
/** |
9 | 1788 |
* Determines whether the current locale is right-to-left (RTL). |
1789 |
* |
|
1790 |
* For more information on this and similar theme functions, check out |
|
1791 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1792 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
* |
16 | 1796 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
* @return bool Whether locale is RTL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
function is_rtl() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
global $wp_locale; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
if ( ! ( $wp_locale instanceof WP_Locale ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1804 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
return $wp_locale->is_rtl(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
* Switches the translations according to the given locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
* |
16 | 1813 |
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
* @param string $locale The locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
function switch_to_locale( $locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1819 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1822 |
if ( ! $wp_locale_switcher ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1823 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1824 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1825 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
return $wp_locale_switcher->switch_to_locale( $locale ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1827 |
} |
5 | 1828 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1830 |
* Switches the translations according to the given user's locale. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1831 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1832 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1833 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1834 |
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1835 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1836 |
* @param int $user_id User ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1837 |
* @return bool True on success, false on failure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1838 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1839 |
function switch_to_user_locale( $user_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1840 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1841 |
global $wp_locale_switcher; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1842 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1843 |
if ( ! $wp_locale_switcher ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1844 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1845 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1846 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1847 |
return $wp_locale_switcher->switch_to_user_locale( $user_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1848 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1849 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1850 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1851 |
* Restores the translations according to the previous locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
* |
16 | 1855 |
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
* @return string|false Locale on success, false on error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
function restore_previous_locale() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1863 |
if ( ! $wp_locale_switcher ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1864 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1865 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1866 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1867 |
return $wp_locale_switcher->restore_previous_locale(); |
5 | 1868 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1870 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1871 |
* Restores the translations according to the original locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1872 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1873 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1874 |
* |
16 | 1875 |
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
* @return string|false Locale on success, false on error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1878 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
function restore_current_locale() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1882 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1883 |
if ( ! $wp_locale_switcher ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1884 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1885 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1886 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1887 |
return $wp_locale_switcher->restore_current_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1890 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1891 |
* Determines whether switch_to_locale() is in effect. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1892 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1894 |
* |
16 | 1895 |
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
* @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
|
1898 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1899 |
function is_locale_switched() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1900 |
/* @var WP_Locale_Switcher $wp_locale_switcher */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1901 |
global $wp_locale_switcher; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
return $wp_locale_switcher->is_switched(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
} |
19 | 1905 |
|
1906 |
/** |
|
1907 |
* Translates the provided settings value using its i18n schema. |
|
1908 |
* |
|
1909 |
* @since 5.9.0 |
|
1910 |
* @access private |
|
1911 |
* |
|
1912 |
* @param string|string[]|array[]|object $i18n_schema I18n schema for the setting. |
|
1913 |
* @param string|string[]|array[] $settings Value for the settings. |
|
1914 |
* @param string $textdomain Textdomain to use with translations. |
|
1915 |
* |
|
1916 |
* @return string|string[]|array[] Translated settings. |
|
1917 |
*/ |
|
1918 |
function translate_settings_using_i18n_schema( $i18n_schema, $settings, $textdomain ) { |
|
1919 |
if ( empty( $i18n_schema ) || empty( $settings ) || empty( $textdomain ) ) { |
|
1920 |
return $settings; |
|
1921 |
} |
|
1922 |
||
1923 |
if ( is_string( $i18n_schema ) && is_string( $settings ) ) { |
|
1924 |
return translate_with_gettext_context( $settings, $i18n_schema, $textdomain ); |
|
1925 |
} |
|
1926 |
if ( is_array( $i18n_schema ) && is_array( $settings ) ) { |
|
1927 |
$translated_settings = array(); |
|
1928 |
foreach ( $settings as $value ) { |
|
1929 |
$translated_settings[] = translate_settings_using_i18n_schema( $i18n_schema[0], $value, $textdomain ); |
|
1930 |
} |
|
1931 |
return $translated_settings; |
|
1932 |
} |
|
1933 |
if ( is_object( $i18n_schema ) && is_array( $settings ) ) { |
|
1934 |
$group_key = '*'; |
|
1935 |
$translated_settings = array(); |
|
1936 |
foreach ( $settings as $key => $value ) { |
|
1937 |
if ( isset( $i18n_schema->$key ) ) { |
|
1938 |
$translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $value, $textdomain ); |
|
1939 |
} elseif ( isset( $i18n_schema->$group_key ) ) { |
|
1940 |
$translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$group_key, $value, $textdomain ); |
|
1941 |
} else { |
|
1942 |
$translated_settings[ $key ] = $value; |
|
1943 |
} |
|
1944 |
} |
|
1945 |
return $translated_settings; |
|
1946 |
} |
|
1947 |
return $settings; |
|
1948 |
} |
|
1949 |
||
1950 |
/** |
|
1951 |
* Retrieves the list item separator based on the locale. |
|
1952 |
* |
|
1953 |
* @since 6.0.0 |
|
1954 |
* |
|
1955 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
1956 |
* |
|
1957 |
* @return string Locale-specific list item separator. |
|
1958 |
*/ |
|
1959 |
function wp_get_list_item_separator() { |
|
1960 |
global $wp_locale; |
|
1961 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1962 |
if ( ! ( $wp_locale instanceof WP_Locale ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1963 |
// Default value of WP_Locale::get_list_item_separator(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1964 |
/* translators: Used between list items, there is a space after the comma. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1965 |
return __( ', ' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1966 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1967 |
|
19 | 1968 |
return $wp_locale->get_list_item_separator(); |
1969 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1970 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1971 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1972 |
* Retrieves the word count type based on the locale. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1973 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1974 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1975 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1976 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1977 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
* @return string Locale-specific word count type. Possible values are `characters_excluding_spaces`, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1979 |
* `characters_including_spaces`, or `words`. Defaults to `words`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1980 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1981 |
function wp_get_word_count_type() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1982 |
global $wp_locale; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1984 |
if ( ! ( $wp_locale instanceof WP_Locale ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1985 |
// Default value of WP_Locale::get_word_count_type(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
return 'words'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1987 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1989 |
return $wp_locale->get_word_count_type(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1990 |
} |