• File: open-graph-locale-generator.php
  • Full Path: /home/matthif/www/wp-content/plugins/wordpress-seo/src/generators/open-graph-locale-generator.php
  • Date Modified: 02/24/2024 11:29 PM
  • File size: 5.49 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Yoast\WP\SEO\Generators;

use 
Yoast\WP\SEO\Context\Meta_Tags_Context;

/**
 * Class Open_Graph_Locale_Generator.
 */
class Open_Graph_Locale_Generator implements Generator_Interface {

    
/**
     * Generates the OG Locale.
     *
     * @param Meta_Tags_Context $context The context.
     *
     * @return string The OG locale.
     */
    
public function generateMeta_Tags_Context $context ) {
        
/**
         * Filter: 'wpseo_locale' - Allow changing the locale output.
         *
         * Note that this filter is different from `wpseo_og_locale`, which is run _after_ the OG specific filtering.
         *
         * @param string $locale Locale string.
         */
        
$locale \apply_filters'wpseo_locale'\get_locale() );

        
// Catch some weird locales served out by WP that are not easily doubled up.
        
$fix_locales = [
            
'ca' => 'ca_ES',
            
'en' => 'en_US',
            
'el' => 'el_GR',
            
'et' => 'et_EE',
            
'ja' => 'ja_JP',
            
'sq' => 'sq_AL',
            
'uk' => 'uk_UA',
            
'vi' => 'vi_VN',
            
'zh' => 'zh_CN',
        ];

        if ( isset( 
$fix_locales$locale ] ) ) {
            return 
$fix_locales$locale ];
        }

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

        
// These are the locales FB supports.
        
$fb_valid_fb_locales = [
            
'af_ZA'// Afrikaans.
            
'ak_GH'// Akan.
            
'am_ET'// Amharic.
            
'ar_AR'// Arabic.
            
'as_IN'// Assamese.
            
'ay_BO'// Aymara.
            
'az_AZ'// Azerbaijani.
            
'be_BY'// Belarusian.
            
'bg_BG'// Bulgarian.
            
'bp_IN'// Bhojpuri.
            
'bn_IN'// Bengali.
            
'br_FR'// Breton.
            
'bs_BA'// Bosnian.
            
'ca_ES'// Catalan.
            
'cb_IQ'// Sorani Kurdish.
            
'ck_US'// Cherokee.
            
'co_FR'// Corsican.
            
'cs_CZ'// Czech.
            
'cx_PH'// Cebuano.
            
'cy_GB'// Welsh.
            
'da_DK'// Danish.
            
'de_DE'// German.
            
'el_GR'// Greek.
            
'en_GB'// English (UK).
            
'en_PI'// English (Pirate).
            
'en_UD'// English (Upside Down).
            
'en_US'// English (US).
            
'em_ZM',
            
'eo_EO'// Esperanto.
            
'es_ES'// Spanish (Spain).
            
'es_LA'// Spanish.
            
'es_MX'// Spanish (Mexico).
            
'et_EE'// Estonian.
            
'eu_ES'// Basque.
            
'fa_IR'// Persian.
            
'fb_LT'// Leet Speak.
            
'ff_NG'// Fulah.
            
'fi_FI'// Finnish.
            
'fo_FO'// Faroese.
            
'fr_CA'// French (Canada).
            
'fr_FR'// French (France).
            
'fy_NL'// Frisian.
            
'ga_IE'// Irish.
            
'gl_ES'// Galician.
            
'gn_PY'// Guarani.
            
'gu_IN'// Gujarati.
            
'gx_GR'// Classical Greek.
            
'ha_NG'// Hausa.
            
'he_IL'// Hebrew.
            
'hi_IN'// Hindi.
            
'hr_HR'// Croatian.
            
'hu_HU'// Hungarian.
            
'ht_HT'// Haitian Creole.
            
'hy_AM'// Armenian.
            
'id_ID'// Indonesian.
            
'ig_NG'// Igbo.
            
'is_IS'// Icelandic.
            
'it_IT'// Italian.
            
'ik_US',
            
'iu_CA',
            
'ja_JP'// Japanese.
            
'ja_KS'// Japanese (Kansai).
            
'jv_ID'// Javanese.
            
'ka_GE'// Georgian.
            
'kk_KZ'// Kazakh.
            
'km_KH'// Khmer.
            
'kn_IN'// Kannada.
            
'ko_KR'// Korean.
            
'ks_IN'// Kashmiri.
            
'ku_TR'// Kurdish (Kurmanji).
            
'ky_KG'// Kyrgyz.
            
'la_VA'// Latin.
            
'lg_UG'// Ganda.
            
'li_NL'// Limburgish.
            
'ln_CD'// Lingala.
            
'lo_LA'// Lao.
            
'lt_LT'// Lithuanian.
            
'lv_LV'// Latvian.
            
'mg_MG'// Malagasy.
            
'mi_NZ'// Maori.
            
'mk_MK'// Macedonian.
            
'ml_IN'// Malayalam.
            
'mn_MN'// Mongolian.
            
'mr_IN'// Marathi.
            
'ms_MY'// Malay.
            
'mt_MT'// Maltese.
            
'my_MM'// Burmese.
            
'nb_NO'// Norwegian (bokmal).
            
'nd_ZW'// Ndebele.
            
'ne_NP'// Nepali.
            
'nl_BE'// Dutch (Belgie).
            
'nl_NL'// Dutch.
            
'nn_NO'// Norwegian (nynorsk).
            
'nr_ZA'// Southern Ndebele.
            
'ns_ZA'// Northern Sotho.
            
'ny_MW'// Chewa.
            
'om_ET'// Oromo.
            
'or_IN'// Oriya.
            
'pa_IN'// Punjabi.
            
'pl_PL'// Polish.
            
'ps_AF'// Pashto.
            
'pt_BR'// Portuguese (Brazil).
            
'pt_PT'// Portuguese (Portugal).
            
'qc_GT'// Quiché.
            
'qu_PE'// Quechua.
            
'qr_GR',
            
'qz_MM'// Burmese (Zawgyi).
            
'rm_CH'// Romansh.
            
'ro_RO'// Romanian.
            
'ru_RU'// Russian.
            
'rw_RW'// Kinyarwanda.
            
'sa_IN'// Sanskrit.
            
'sc_IT'// Sardinian.
            
'se_NO'// Northern Sami.
            
'si_LK'// Sinhala.
            
'su_ID'// Sundanese.
            
'sk_SK'// Slovak.
            
'sl_SI'// Slovenian.
            
'sn_ZW'// Shona.
            
'so_SO'// Somali.
            
'sq_AL'// Albanian.
            
'sr_RS'// Serbian.
            
'ss_SZ'// Swazi.
            
'st_ZA'// Southern Sotho.
            
'sv_SE'// Swedish.
            
'sw_KE'// Swahili.
            
'sy_SY'// Syriac.
            
'sz_PL'// Silesian.
            
'ta_IN'// Tamil.
            
'te_IN'// Telugu.
            
'tg_TJ'// Tajik.
            
'th_TH'// Thai.
            
'tk_TM'// Turkmen.
            
'tl_PH'// Filipino.
            
'tl_ST'// Klingon.
            
'tn_BW'// Tswana.
            
'tr_TR'// Turkish.
            
'ts_ZA'// Tsonga.
            
'tt_RU'// Tatar.
            
'tz_MA'// Tamazight.
            
'uk_UA'// Ukrainian.
            
'ur_PK'// Urdu.
            
'uz_UZ'// Uzbek.
            
've_ZA'// Venda.
            
'vi_VN'// Vietnamese.
            
'wo_SN'// Wolof.
            
'xh_ZA'// Xhosa.
            
'yi_DE'// Yiddish.
            
'yo_NG'// Yoruba.
            
'zh_CN'// Simplified Chinese (China).
            
'zh_HK'// Traditional Chinese (Hong Kong).
            
'zh_TW'// Traditional Chinese (Taiwan).
            
'zu_ZA'// Zulu.
            
'zz_TR'// Zazaki.
        
];

        
// Check to see if the locale is a valid FB one, if not, use en_US as a fallback.
        
if ( \in_array$locale$fb_valid_fb_localestrue ) ) {
            return 
$locale;
        }

        
$locale \strtolower\substr$locale0) ) . '_' \strtoupper\substr$locale0) );
        if ( ! 
\in_array$locale$fb_valid_fb_localestrue ) ) {
            return 
'en_US';
        }

        return 
$locale;
    }
}