Changeset 43776 for branches/5.0/src/wp-includes/l10n.php
- Timestamp:
- 10/21/2018 03:02:49 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/l10n.php
r43759 r43776 106 106 107 107 /** 108 * Determine the current locale desired for the request. 109 * 110 * @since 5.0.0 111 * 112 * @global string $pagenow 113 * 114 * @return string The determined locale. 115 */ 116 function determine_locale() { 117 /** 118 * Filters the locale for the current request prior to the default determination process. 119 * 120 * Using this filter allows to override the default logic, effectively short-circuiting the function. 121 * 122 * @since 5.0.0 123 * 124 * @param string|null The locale to return and short-circuit, or null as default. 125 */ 126 $determined_locale = apply_filters( 'pre_determine_locale', null ); 127 if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) { 128 return $determined_locale; 129 } 130 131 $determined_locale = get_locale(); 132 133 if ( is_admin() ) { 134 $determined_locale = get_user_locale(); 135 } 136 137 if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() && is_user_logged_in() ) { 138 $determined_locale = get_user_locale(); 139 } 140 141 if ( ! empty( $_GET['wp_lang'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { 142 $determined_locale = sanitize_text_field( $_GET['wp_lang'] ); 143 } 144 145 /** 146 * Filters the locale for the current request. 147 * 148 * @since 5.0.0 149 * 150 * @param string $locale The locale. 151 */ 152 return apply_filters( 'determine_locale', $determined_locale ); 153 } 154 155 /** 108 156 * Retrieve the translation of $text. 109 157 * … … 664 712 function load_default_textdomain( $locale = null ) { 665 713 if ( null === $locale ) { 666 $locale = is_admin() ? get_user_locale() : get_locale();714 $locale = determine_locale(); 667 715 } 668 716 … … 712 760 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 713 761 */ 714 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );762 $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); 715 763 716 764 $mofile = $domain . '-' . $locale . '.mo'; … … 746 794 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 747 795 /** This filter is documented in wp-includes/l10n.php */ 748 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );796 $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); 749 797 750 798 $mofile = $domain . '-' . $locale . '.mo'; … … 785 833 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 786 834 */ 787 $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain );835 $locale = apply_filters( 'theme_locale', determine_locale(), $domain ); 788 836 789 837 $mofile = $domain . '-' . $locale . '.mo'; … … 916 964 } 917 965 918 $locale = is_admin() ? get_user_locale() : get_locale();966 $locale = determine_locale(); 919 967 $mofile = "{$domain}-{$locale}.mo"; 920 968 … … 1211 1259 ); 1212 1260 1213 // List installed languages. 1261 // List installed languages. 1214 1262 foreach ( $languages as $language ) { 1215 1263 $structure[] = sprintf( … … 1348 1396 '' => array( 1349 1397 'domain' => $domain, 1350 'lang' => is_admin() ? get_user_locale() : get_locale(),1398 'lang' => determine_locale(), 1351 1399 ), 1352 1400 );
Note: See TracChangeset
for help on using the changeset viewer.