@@ 1136-1174 (lines=39) @@ | ||
1133 | * @param string $lang Language code. |
|
1134 | * @return string|bool |
|
1135 | */ |
|
1136 | function guess_locale_from_lang( $lang ) { |
|
1137 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
1138 | return 'en_US'; |
|
1139 | } |
|
1140 | ||
1141 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
1142 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
1143 | return false; |
|
1144 | } |
|
1145 | ||
1146 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
1147 | } |
|
1148 | ||
1149 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
1150 | // WP.com: get_locale() returns 'it' |
|
1151 | $locale = GP_Locales::by_slug( $lang ); |
|
1152 | } else { |
|
1153 | // Jetpack: get_locale() returns 'it_IT'; |
|
1154 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
1155 | } |
|
1156 | ||
1157 | if ( ! $locale ) { |
|
1158 | return false; |
|
1159 | } |
|
1160 | ||
1161 | if ( empty( $locale->facebook_locale ) ) { |
|
1162 | if ( empty( $locale->wp_locale ) ) { |
|
1163 | return false; |
|
1164 | } else { |
|
1165 | // Facebook SDK is smart enough to fall back to en_US if a |
|
1166 | // locale isn't supported. Since supported Facebook locales |
|
1167 | // can fall out of sync, we'll attempt to use the known |
|
1168 | // wp_locale value and rely on said fallback. |
|
1169 | return $locale->wp_locale; |
|
1170 | } |
|
1171 | } |
|
1172 | ||
1173 | return $locale->facebook_locale; |
|
1174 | } |
|
1175 | ||
1176 | /** |
|
1177 | * Get the locale. |
@@ 977-1015 (lines=39) @@ | ||
974 | public function display_header() { |
|
975 | } |
|
976 | ||
977 | function guess_locale_from_lang( $lang ) { |
|
978 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
979 | return 'en_US'; |
|
980 | } |
|
981 | ||
982 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
983 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
984 | return false; |
|
985 | } |
|
986 | ||
987 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
988 | } |
|
989 | ||
990 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
991 | // WP.com: get_locale() returns 'it' |
|
992 | $locale = GP_Locales::by_slug( $lang ); |
|
993 | } else { |
|
994 | // Jetpack: get_locale() returns 'it_IT'; |
|
995 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
996 | } |
|
997 | ||
998 | if ( ! $locale ) { |
|
999 | return false; |
|
1000 | } |
|
1001 | ||
1002 | if ( empty( $locale->facebook_locale ) ) { |
|
1003 | if ( empty( $locale->wp_locale ) ) { |
|
1004 | return false; |
|
1005 | } else { |
|
1006 | // Facebook SDK is smart enough to fall back to en_US if a |
|
1007 | // locale isn't supported. Since supported Facebook locales |
|
1008 | // can fall out of sync, we'll attempt to use the known |
|
1009 | // wp_locale value and rely on said fallback. |
|
1010 | return $locale->wp_locale; |
|
1011 | } |
|
1012 | } |
|
1013 | ||
1014 | return $locale->facebook_locale; |
|
1015 | } |
|
1016 | ||
1017 | public function get_display( $post ) { |
|
1018 | if ( $this->smart ) { |