l10n.php
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Determine the current locale desired for the request.
*
* @since 5.0.0
*
* @global string $pagenow
*
* @return string The determined locale.
*/
if ( ! function_exists( 'determine_locale' ) ) :
function determine_locale() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null The locale to return and short-circuit, or null as default.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
return $determined_locale;
}
$determined_locale = get_locale();
if ( function_exists( 'get_user_locale' ) && is_admin() ) {
$determined_locale = get_user_locale();
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Copied from WordPress core.
if ( function_exists( 'get_user_locale' ) && isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] ) {
$determined_locale = get_user_locale();
}
if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
endif;
/*
* acf_get_locale
*
* Returns the current locale.
*
* @date 16/12/16
* @since 5.5.0
*
* @param void
* @return string
*/
function acf_get_locale() {
// Determine local.
$locale = determine_locale();
// Fallback to parent language for regions without translation.
// https://wpastra.com/docs/complete-list-wordpress-locale-codes/
$langs = array(
'az_TR' => 'az', // Azerbaijani (Turkey)
'zh_HK' => 'zh_TW', // Chinese (Hong Kong)
'fr_BE' => 'fr_FR', // French (Belgium)
'nn_NO' => 'nb_NO', // Norwegian (Nynorsk)
'fa_AF' => 'fa_IR', // Persian (Afghanistan)
'ru_UA' => 'ru_RU', // Russian (Ukraine)
);
if ( isset( $langs[ $locale ] ) ) {
$locale = $langs[ $locale ];
}
/**
* Filters the determined local.
*
* @date 8/1/19
* @since 5.7.10
*
* @param string $locale The local.
*/
return apply_filters( 'acf/get_locale', $locale );
}
/**
* acf_load_textdomain
*
* Loads the plugin's translated strings similar to load_plugin_textdomain().
*
* @date 8/1/19
* @since 5.7.10
*
* @param string $locale The plugin's current locale.
* @return void
*/
function acf_load_textdomain( $domain = 'acf' ) {
/**
* Filters a plugin's locale.
*
* @date 8/1/19
* @since 5.7.10
*
* @param string $locale The plugin's current locale.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$locale = apply_filters( 'plugin_locale', acf_get_locale(), $domain );
$mofile = $domain . '-' . $locale . '.mo';
// Load from plugin lang folder.
return load_textdomain( $domain, acf_get_path( 'lang/' . $mofile ) );
}
/**
* _acf_apply_language_cache_key
*
* Applies the current language to the cache key.
*
* @date 23/1/19
* @since 5.7.11
*
* @param string $key The cache key.
* @return string
*/
function _acf_apply_language_cache_key( $key ) {
// Get current language.
$current_language = acf_get_setting( 'current_language' );
if ( $current_language ) {
$key = "{$key}:{$current_language}";
}
// Return key.
return $key;
}
// Hook into filter.
add_filter( 'acf/get_cache_key', '_acf_apply_language_cache_key' );