| @@ 1240-1278 (lines=39) @@ | ||
| 1237 | * @param string $lang Language code. |
|
| 1238 | * @return string|bool |
|
| 1239 | */ |
|
| 1240 | function guess_locale_from_lang( $lang ) { |
|
| 1241 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
| 1242 | return 'en_US'; |
|
| 1243 | } |
|
| 1244 | ||
| 1245 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 1246 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 1247 | return false; |
|
| 1248 | } |
|
| 1249 | ||
| 1250 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 1251 | } |
|
| 1252 | ||
| 1253 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 1254 | // WP.com: get_locale() returns 'it' |
|
| 1255 | $locale = GP_Locales::by_slug( $lang ); |
|
| 1256 | } else { |
|
| 1257 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 1258 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
| 1259 | } |
|
| 1260 | ||
| 1261 | if ( ! $locale ) { |
|
| 1262 | return false; |
|
| 1263 | } |
|
| 1264 | ||
| 1265 | if ( empty( $locale->facebook_locale ) ) { |
|
| 1266 | if ( empty( $locale->wp_locale ) ) { |
|
| 1267 | return false; |
|
| 1268 | } else { |
|
| 1269 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 1270 | // locale isn't supported. Since supported Facebook locales |
|
| 1271 | // can fall out of sync, we'll attempt to use the known |
|
| 1272 | // wp_locale value and rely on said fallback. |
|
| 1273 | return $locale->wp_locale; |
|
| 1274 | } |
|
| 1275 | } |
|
| 1276 | ||
| 1277 | return $locale->facebook_locale; |
|
| 1278 | } |
|
| 1279 | ||
| 1280 | /** |
|
| 1281 | * Get the locale. |
|
| @@ 1063-1101 (lines=39) @@ | ||
| 1060 | public function display_header() { |
|
| 1061 | } |
|
| 1062 | ||
| 1063 | function guess_locale_from_lang( $lang ) { |
|
| 1064 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
| 1065 | return 'en_US'; |
|
| 1066 | } |
|
| 1067 | ||
| 1068 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 1069 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 1070 | return false; |
|
| 1071 | } |
|
| 1072 | ||
| 1073 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 1074 | } |
|
| 1075 | ||
| 1076 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 1077 | // WP.com: get_locale() returns 'it' |
|
| 1078 | $locale = GP_Locales::by_slug( $lang ); |
|
| 1079 | } else { |
|
| 1080 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 1081 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
| 1082 | } |
|
| 1083 | ||
| 1084 | if ( ! $locale ) { |
|
| 1085 | return false; |
|
| 1086 | } |
|
| 1087 | ||
| 1088 | if ( empty( $locale->facebook_locale ) ) { |
|
| 1089 | if ( empty( $locale->wp_locale ) ) { |
|
| 1090 | return false; |
|
| 1091 | } else { |
|
| 1092 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 1093 | // locale isn't supported. Since supported Facebook locales |
|
| 1094 | // can fall out of sync, we'll attempt to use the known |
|
| 1095 | // wp_locale value and rely on said fallback. |
|
| 1096 | return $locale->wp_locale; |
|
| 1097 | } |
|
| 1098 | } |
|
| 1099 | ||
| 1100 | return $locale->facebook_locale; |
|
| 1101 | } |
|
| 1102 | ||
| 1103 | public function get_display( $post ) { |
|
| 1104 | if ( $this->smart ) { |
|