• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/generators/open-graph-locale-generator.php
1
<?php
2

3
namespace Yoast\WP\SEO\Generators;
4

5
use Yoast\WP\SEO\Context\Meta_Tags_Context;
6

7
/**
8
 * Class Open_Graph_Locale_Generator.
9
 */
10
class Open_Graph_Locale_Generator implements Generator_Interface {
11

12
        /**
13
         * Generates the OG Locale.
14
         *
15
         * @param Meta_Tags_Context $context The context.
16
         *
17
         * @return string The OG locale.
18
         */
19
        public function generate( Meta_Tags_Context $context ) {
20
                /**
21
                 * Filter: 'wpseo_locale' - Allow changing the locale output.
22
                 *
23
                 * Note that this filter is different from `wpseo_og_locale`, which is run _after_ the OG specific filtering.
24
                 *
25
                 * @api string Locale string.
26
                 */
27
                $locale = \apply_filters( 'wpseo_locale', \get_locale() );
×
28

29
                // Catch some weird locales served out by WP that are not easily doubled up.
30
                $fix_locales = [
×
31
                        'ca' => 'ca_ES',
×
32
                        'en' => 'en_US',
×
33
                        'el' => 'el_GR',
×
34
                        'et' => 'et_EE',
×
35
                        'ja' => 'ja_JP',
×
36
                        'sq' => 'sq_AL',
×
37
                        'uk' => 'uk_UA',
×
38
                        'vi' => 'vi_VN',
×
39
                        'zh' => 'zh_CN',
×
40
                ];
×
41

42
                if ( isset( $fix_locales[ $locale ] ) ) {
×
43
                        return $fix_locales[ $locale ];
×
44
                }
45

46
                // Convert locales like "es" to "es_ES", in case that works for the given locale (sometimes it does).
47
                if ( \strlen( $locale ) === 2 ) {
×
48
                        $locale = \strtolower( $locale ) . '_' . \strtoupper( $locale );
×
49
                }
50

51
                // These are the locales FB supports.
52
                $fb_valid_fb_locales = [
×
53
                        'af_ZA', // Afrikaans.
×
54
                        'ak_GH', // Akan.
×
55
                        'am_ET', // Amharic.
×
56
                        'ar_AR', // Arabic.
×
57
                        'as_IN', // Assamese.
×
58
                        'ay_BO', // Aymara.
×
59
                        'az_AZ', // Azerbaijani.
×
60
                        'be_BY', // Belarusian.
×
61
                        'bg_BG', // Bulgarian.
×
62
                        'bp_IN', // Bhojpuri.
×
63
                        'bn_IN', // Bengali.
×
64
                        'br_FR', // Breton.
×
65
                        'bs_BA', // Bosnian.
×
66
                        'ca_ES', // Catalan.
×
67
                        'cb_IQ', // Sorani Kurdish.
×
68
                        'ck_US', // Cherokee.
×
69
                        'co_FR', // Corsican.
×
70
                        'cs_CZ', // Czech.
×
71
                        'cx_PH', // Cebuano.
×
72
                        'cy_GB', // Welsh.
×
73
                        'da_DK', // Danish.
×
74
                        'de_DE', // German.
×
75
                        'el_GR', // Greek.
×
76
                        'en_GB', // English (UK).
×
77
                        'en_PI', // English (Pirate).
×
78
                        'en_UD', // English (Upside Down).
×
79
                        'en_US', // English (US).
×
80
                        'em_ZM',
×
81
                        'eo_EO', // Esperanto.
×
82
                        'es_ES', // Spanish (Spain).
×
83
                        'es_LA', // Spanish.
×
84
                        'es_MX', // Spanish (Mexico).
×
85
                        'et_EE', // Estonian.
×
86
                        'eu_ES', // Basque.
×
87
                        'fa_IR', // Persian.
×
88
                        'fb_LT', // Leet Speak.
×
89
                        'ff_NG', // Fulah.
×
90
                        'fi_FI', // Finnish.
×
91
                        'fo_FO', // Faroese.
×
92
                        'fr_CA', // French (Canada).
×
93
                        'fr_FR', // French (France).
×
94
                        'fy_NL', // Frisian.
×
95
                        'ga_IE', // Irish.
×
96
                        'gl_ES', // Galician.
×
97
                        'gn_PY', // Guarani.
×
98
                        'gu_IN', // Gujarati.
×
99
                        'gx_GR', // Classical Greek.
×
100
                        'ha_NG', // Hausa.
×
101
                        'he_IL', // Hebrew.
×
102
                        'hi_IN', // Hindi.
×
103
                        'hr_HR', // Croatian.
×
104
                        'hu_HU', // Hungarian.
×
105
                        'ht_HT', // Haitian Creole.
×
106
                        'hy_AM', // Armenian.
×
107
                        'id_ID', // Indonesian.
×
108
                        'ig_NG', // Igbo.
×
109
                        'is_IS', // Icelandic.
×
110
                        'it_IT', // Italian.
×
111
                        'ik_US',
×
112
                        'iu_CA',
×
113
                        'ja_JP', // Japanese.
×
114
                        'ja_KS', // Japanese (Kansai).
×
115
                        'jv_ID', // Javanese.
×
116
                        'ka_GE', // Georgian.
×
117
                        'kk_KZ', // Kazakh.
×
118
                        'km_KH', // Khmer.
×
119
                        'kn_IN', // Kannada.
×
120
                        'ko_KR', // Korean.
×
121
                        'ks_IN', // Kashmiri.
×
122
                        'ku_TR', // Kurdish (Kurmanji).
×
123
                        'ky_KG', // Kyrgyz.
×
124
                        'la_VA', // Latin.
×
125
                        'lg_UG', // Ganda.
×
126
                        'li_NL', // Limburgish.
×
127
                        'ln_CD', // Lingala.
×
128
                        'lo_LA', // Lao.
×
129
                        'lt_LT', // Lithuanian.
×
130
                        'lv_LV', // Latvian.
×
131
                        'mg_MG', // Malagasy.
×
132
                        'mi_NZ', // Maori.
×
133
                        'mk_MK', // Macedonian.
×
134
                        'ml_IN', // Malayalam.
×
135
                        'mn_MN', // Mongolian.
×
136
                        'mr_IN', // Marathi.
×
137
                        'ms_MY', // Malay.
×
138
                        'mt_MT', // Maltese.
×
139
                        'my_MM', // Burmese.
×
140
                        'nb_NO', // Norwegian (bokmal).
×
141
                        'nd_ZW', // Ndebele.
×
142
                        'ne_NP', // Nepali.
×
143
                        'nl_BE', // Dutch (Belgie).
×
144
                        'nl_NL', // Dutch.
×
145
                        'nn_NO', // Norwegian (nynorsk).
×
146
                        'nr_ZA', // Southern Ndebele.
×
147
                        'ns_ZA', // Northern Sotho.
×
148
                        'ny_MW', // Chewa.
×
149
                        'om_ET', // Oromo.
×
150
                        'or_IN', // Oriya.
×
151
                        'pa_IN', // Punjabi.
×
152
                        'pl_PL', // Polish.
×
153
                        'ps_AF', // Pashto.
×
154
                        'pt_BR', // Portuguese (Brazil).
×
155
                        'pt_PT', // Portuguese (Portugal).
×
156
                        'qc_GT', // Quiché.
×
157
                        'qu_PE', // Quechua.
×
158
                        'qr_GR',
×
159
                        'qz_MM', // Burmese (Zawgyi).
×
160
                        'rm_CH', // Romansh.
×
161
                        'ro_RO', // Romanian.
×
162
                        'ru_RU', // Russian.
×
163
                        'rw_RW', // Kinyarwanda.
×
164
                        'sa_IN', // Sanskrit.
×
165
                        'sc_IT', // Sardinian.
×
166
                        'se_NO', // Northern Sami.
×
167
                        'si_LK', // Sinhala.
×
168
                        'su_ID', // Sundanese.
×
169
                        'sk_SK', // Slovak.
×
170
                        'sl_SI', // Slovenian.
×
171
                        'sn_ZW', // Shona.
×
172
                        'so_SO', // Somali.
×
173
                        'sq_AL', // Albanian.
×
174
                        'sr_RS', // Serbian.
×
175
                        'ss_SZ', // Swazi.
×
176
                        'st_ZA', // Southern Sotho.
×
177
                        'sv_SE', // Swedish.
×
178
                        'sw_KE', // Swahili.
×
179
                        'sy_SY', // Syriac.
×
180
                        'sz_PL', // Silesian.
×
181
                        'ta_IN', // Tamil.
×
182
                        'te_IN', // Telugu.
×
183
                        'tg_TJ', // Tajik.
×
184
                        'th_TH', // Thai.
×
185
                        'tk_TM', // Turkmen.
×
186
                        'tl_PH', // Filipino.
×
187
                        'tl_ST', // Klingon.
×
188
                        'tn_BW', // Tswana.
×
189
                        'tr_TR', // Turkish.
×
190
                        'ts_ZA', // Tsonga.
×
191
                        'tt_RU', // Tatar.
×
192
                        'tz_MA', // Tamazight.
×
193
                        'uk_UA', // Ukrainian.
×
194
                        'ur_PK', // Urdu.
×
195
                        'uz_UZ', // Uzbek.
×
196
                        've_ZA', // Venda.
×
197
                        'vi_VN', // Vietnamese.
×
198
                        'wo_SN', // Wolof.
×
199
                        'xh_ZA', // Xhosa.
×
200
                        'yi_DE', // Yiddish.
×
201
                        'yo_NG', // Yoruba.
×
202
                        'zh_CN', // Simplified Chinese (China).
×
203
                        'zh_HK', // Traditional Chinese (Hong Kong).
×
204
                        'zh_TW', // Traditional Chinese (Taiwan).
×
205
                        'zu_ZA', // Zulu.
×
206
                        'zz_TR', // Zazaki.
×
207
                ];
×
208

209
                // Check to see if the locale is a valid FB one, if not, use en_US as a fallback.
210
                if ( \in_array( $locale, $fb_valid_fb_locales, true ) ) {
×
211
                        return $locale;
×
212
                }
213

214
                $locale = \strtolower( \substr( $locale, 0, 2 ) ) . '_' . \strtoupper( \substr( $locale, 0, 2 ) );
×
215
                if ( ! \in_array( $locale, $fb_valid_fb_locales, true ) ) {
×
216
                        return 'en_US';
×
217
                }
218

219
                return $locale;
×
220
        }
221
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc