admin
1 month ago
ajax
3 months ago
api
2 weeks ago
fields
4 weeks ago
forms
4 weeks ago
legacy
5 months ago
locations
1 month ago
post-types
5 months ago
rest-api
4 weeks ago
walkers
5 months ago
acf-bidirectional-functions.php
5 months ago
acf-field-functions.php
5 months ago
acf-field-group-functions.php
5 months ago
acf-form-functions.php
5 months ago
acf-helper-functions.php
5 months ago
acf-hook-functions.php
5 months ago
acf-input-functions.php
5 months ago
acf-internal-post-type-functions.php
5 months ago
acf-meta-functions.php
2 months ago
acf-post-functions.php
5 months ago
acf-post-type-functions.php
5 months ago
acf-taxonomy-functions.php
5 months ago
acf-user-functions.php
5 months ago
acf-utility-functions.php
5 months ago
acf-value-functions.php
5 months ago
acf-wp-functions.php
5 months ago
assets.php
5 months ago
class-acf-data.php
5 months ago
class-acf-internal-post-type.php
5 months ago
compatibility.php
5 months ago
deprecated.php
5 months ago
fields.php
5 months ago
index.php
2 years ago
l10n.php
5 months ago
local-fields.php
5 months ago
local-json.php
3 months ago
local-meta.php
5 months ago
locations.php
5 months ago
loop.php
5 months ago
media.php
5 months ago
rest-api.php
5 months ago
revisions.php
3 months ago
third-party.php
5 months ago
upgrades.php
2 months ago
validation.php
5 months ago
wpml.php
5 months ago
l10n.php
157 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package ACF |
| 4 | * @author WP Engine |
| 5 | * |
| 6 | * © 2026 Advanced Custom Fields (ACF®). All rights reserved. |
| 7 | * "ACF" is a trademark of WP Engine. |
| 8 | * Licensed under the GNU General Public License v2 or later. |
| 9 | * https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Determine the current locale desired for the request. |
| 14 | * |
| 15 | * @since 5.0.0 |
| 16 | * |
| 17 | * @global string $pagenow |
| 18 | * |
| 19 | * @return string The determined locale. |
| 20 | */ |
| 21 | if ( ! function_exists( 'determine_locale' ) ) : |
| 22 | function determine_locale() { |
| 23 | /** |
| 24 | * Filters the locale for the current request prior to the default determination process. |
| 25 | * |
| 26 | * Using this filter allows to override the default logic, effectively short-circuiting the function. |
| 27 | * |
| 28 | * @since 5.0.0 |
| 29 | * |
| 30 | * @param string|null The locale to return and short-circuit, or null as default. |
| 31 | */ |
| 32 | $determined_locale = apply_filters( 'pre_determine_locale', null ); |
| 33 | if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) { |
| 34 | return $determined_locale; |
| 35 | } |
| 36 | |
| 37 | $determined_locale = get_locale(); |
| 38 | |
| 39 | if ( function_exists( 'get_user_locale' ) && is_admin() ) { |
| 40 | $determined_locale = get_user_locale(); |
| 41 | } |
| 42 | |
| 43 | // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Copied from WordPress core. |
| 44 | if ( function_exists( 'get_user_locale' ) && isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] ) { |
| 45 | $determined_locale = get_user_locale(); |
| 46 | } |
| 47 | |
| 48 | if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { |
| 49 | $determined_locale = sanitize_text_field( $_GET['wp_lang'] ); |
| 50 | } |
| 51 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 52 | |
| 53 | /** |
| 54 | * Filters the locale for the current request. |
| 55 | * |
| 56 | * @since 5.0.0 |
| 57 | * |
| 58 | * @param string $locale The locale. |
| 59 | */ |
| 60 | return apply_filters( 'determine_locale', $determined_locale ); |
| 61 | } |
| 62 | endif; |
| 63 | |
| 64 | /** |
| 65 | * Returns the current locale. |
| 66 | * |
| 67 | * @date 16/12/16 |
| 68 | * @since 5.5.0 |
| 69 | * |
| 70 | * @param void |
| 71 | * @return string |
| 72 | */ |
| 73 | function acf_get_locale() { |
| 74 | |
| 75 | // Determine local. |
| 76 | $locale = determine_locale(); |
| 77 | |
| 78 | // Fallback to parent language for regions without translation. |
| 79 | // https://wpastra.com/docs/complete-list-wordpress-locale-codes/ |
| 80 | $langs = array( |
| 81 | 'az_TR' => 'az', // Azerbaijani (Turkey) |
| 82 | 'zh_HK' => 'zh_TW', // Chinese (Hong Kong) |
| 83 | 'fr_BE' => 'fr_FR', // French (Belgium) |
| 84 | 'nn_NO' => 'nb_NO', // Norwegian (Nynorsk) |
| 85 | 'fa_AF' => 'fa_IR', // Persian (Afghanistan) |
| 86 | 'ru_UA' => 'ru_RU', // Russian (Ukraine) |
| 87 | ); |
| 88 | if ( isset( $langs[ $locale ] ) ) { |
| 89 | $locale = $langs[ $locale ]; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Filters the determined local. |
| 94 | * |
| 95 | * @date 8/1/19 |
| 96 | * @since 5.7.10 |
| 97 | * |
| 98 | * @param string $locale The local. |
| 99 | */ |
| 100 | return apply_filters( 'acf/get_locale', $locale ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * acf_load_textdomain |
| 105 | * |
| 106 | * Loads the plugin's translated strings similar to load_plugin_textdomain(). |
| 107 | * |
| 108 | * @date 8/1/19 |
| 109 | * @since 5.7.10 |
| 110 | * |
| 111 | * @param string $locale The plugin's current locale. |
| 112 | * @return void |
| 113 | */ |
| 114 | function acf_load_textdomain( $domain = 'acf' ) { |
| 115 | |
| 116 | /** |
| 117 | * Filters a plugin's locale. |
| 118 | * |
| 119 | * @date 8/1/19 |
| 120 | * @since 5.7.10 |
| 121 | * |
| 122 | * @param string $locale The plugin's current locale. |
| 123 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 124 | */ |
| 125 | $locale = apply_filters( 'plugin_locale', acf_get_locale(), $domain ); |
| 126 | $mofile = $domain . '-' . $locale . '.mo'; |
| 127 | |
| 128 | // Load from plugin lang folder. |
| 129 | return load_textdomain( $domain, acf_get_path( 'lang/' . $mofile ) ); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * _acf_apply_language_cache_key |
| 134 | * |
| 135 | * Applies the current language to the cache key. |
| 136 | * |
| 137 | * @date 23/1/19 |
| 138 | * @since 5.7.11 |
| 139 | * |
| 140 | * @param string $key The cache key. |
| 141 | * @return string |
| 142 | */ |
| 143 | function _acf_apply_language_cache_key( $key ) { |
| 144 | |
| 145 | // Get current language. |
| 146 | $current_language = acf_get_setting( 'current_language' ); |
| 147 | if ( $current_language ) { |
| 148 | $key = "{$key}:{$current_language}"; |
| 149 | } |
| 150 | |
| 151 | // Return key. |
| 152 | return $key; |
| 153 | } |
| 154 | |
| 155 | // Hook into filter. |
| 156 | add_filter( 'acf/get_cache_key', '_acf_apply_language_cache_key' ); |
| 157 |