| @@ 981-1019 (lines=39) @@ | ||
| 978 | public function display_header() { |
|
| 979 | } |
|
| 980 | ||
| 981 | function guess_locale_from_lang( $lang ) { |
|
| 982 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
| 983 | return 'en_US'; |
|
| 984 | } |
|
| 985 | ||
| 986 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 987 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 988 | return false; |
|
| 989 | } |
|
| 990 | ||
| 991 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 992 | } |
|
| 993 | ||
| 994 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 995 | // WP.com: get_locale() returns 'it' |
|
| 996 | $locale = GP_Locales::by_slug( $lang ); |
|
| 997 | } else { |
|
| 998 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 999 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
| 1000 | } |
|
| 1001 | ||
| 1002 | if ( ! $locale ) { |
|
| 1003 | return false; |
|
| 1004 | } |
|
| 1005 | ||
| 1006 | if ( empty( $locale->facebook_locale ) ) { |
|
| 1007 | if ( empty( $locale->wp_locale ) ) { |
|
| 1008 | return false; |
|
| 1009 | } else { |
|
| 1010 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 1011 | // locale isn't supported. Since supported Facebook locales |
|
| 1012 | // can fall out of sync, we'll attempt to use the known |
|
| 1013 | // wp_locale value and rely on said fallback. |
|
| 1014 | return $locale->wp_locale; |
|
| 1015 | } |
|
| 1016 | } |
|
| 1017 | ||
| 1018 | return $locale->facebook_locale; |
|
| 1019 | } |
|
| 1020 | ||
| 1021 | public function get_display( $post ) { |
|
| 1022 | if ( $this->smart ) { |
|
| @@ 1154-1192 (lines=39) @@ | ||
| 1151 | * @param string $lang Language code. |
|
| 1152 | * @return string|bool |
|
| 1153 | */ |
|
| 1154 | function guess_locale_from_lang( $lang ) { |
|
| 1155 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
| 1156 | return 'en_US'; |
|
| 1157 | } |
|
| 1158 | ||
| 1159 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 1160 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 1161 | return false; |
|
| 1162 | } |
|
| 1163 | ||
| 1164 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 1165 | } |
|
| 1166 | ||
| 1167 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 1168 | // WP.com: get_locale() returns 'it' |
|
| 1169 | $locale = GP_Locales::by_slug( $lang ); |
|
| 1170 | } else { |
|
| 1171 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 1172 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
| 1173 | } |
|
| 1174 | ||
| 1175 | if ( ! $locale ) { |
|
| 1176 | return false; |
|
| 1177 | } |
|
| 1178 | ||
| 1179 | if ( empty( $locale->facebook_locale ) ) { |
|
| 1180 | if ( empty( $locale->wp_locale ) ) { |
|
| 1181 | return false; |
|
| 1182 | } else { |
|
| 1183 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 1184 | // locale isn't supported. Since supported Facebook locales |
|
| 1185 | // can fall out of sync, we'll attempt to use the known |
|
| 1186 | // wp_locale value and rely on said fallback. |
|
| 1187 | return $locale->wp_locale; |
|
| 1188 | } |
|
| 1189 | } |
|
| 1190 | ||
| 1191 | return $locale->facebook_locale; |
|
| 1192 | } |
|
| 1193 | ||
| 1194 | /** |
|
| 1195 | * Get the locale. |
|