function guess_locale_from_lang($lang)
{
if ('en' === $lang || 'en_US' === $lang || !$lang) {
return 'en_US';
}
if (!class_exists('GP_Locales')) {
if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
return false;
}
require JETPACK__GLOTPRESS_LOCALES_PATH;
}
if (defined('IS_WPCOM') && IS_WPCOM) {
// WP.com: get_locale() returns 'it'
$locale = GP_Locales::by_slug($lang);
} else {
// Jetpack: get_locale() returns 'it_IT';
$locale = GP_Locales::by_field('facebook_locale', $lang);
}
if (!$locale) {
return false;
}
if (empty($locale->facebook_locale)) {
if (empty($locale->wp_locale)) {
return false;
} else {
// Facebook SDK is smart enough to fall back to en_US if a
// locale isn't supported. Since supported Facebook locales
// can fall out of sync, we'll attempt to use the known
// wp_locale value and rely on said fallback.
return $locale->wp_locale;
}
}
return $locale->facebook_locale;
}