@@ 905-943 (lines=39) @@ | ||
902 | public function display_header() { |
|
903 | } |
|
904 | ||
905 | function guess_locale_from_lang( $lang ) { |
|
906 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
907 | return 'en_US'; |
|
908 | } |
|
909 | ||
910 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
911 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
912 | return false; |
|
913 | } |
|
914 | ||
915 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
916 | } |
|
917 | ||
918 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
919 | // WP.com: get_locale() returns 'it' |
|
920 | $locale = GP_Locales::by_slug( $lang ); |
|
921 | } else { |
|
922 | // Jetpack: get_locale() returns 'it_IT'; |
|
923 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
924 | } |
|
925 | ||
926 | if ( ! $locale ) { |
|
927 | return false; |
|
928 | } |
|
929 | ||
930 | if ( empty( $locale->facebook_locale ) ) { |
|
931 | if ( empty( $locale->wp_locale ) ) { |
|
932 | return false; |
|
933 | } else { |
|
934 | // Facebook SDK is smart enough to fall back to en_US if a |
|
935 | // locale isn't supported. Since supported Facebook locales |
|
936 | // can fall out of sync, we'll attempt to use the known |
|
937 | // wp_locale value and rely on said fallback. |
|
938 | return $locale->wp_locale; |
|
939 | } |
|
940 | } |
|
941 | ||
942 | return $locale->facebook_locale; |
|
943 | } |
|
944 | ||
945 | public function get_display( $post ) { |
|
946 | if ( $this->smart ) { |
@@ 1037-1075 (lines=39) @@ | ||
1034 | * @param string $lang Language code. |
|
1035 | * @return string|bool |
|
1036 | */ |
|
1037 | function guess_locale_from_lang( $lang ) { |
|
1038 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
1039 | return 'en_US'; |
|
1040 | } |
|
1041 | ||
1042 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
1043 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
1044 | return false; |
|
1045 | } |
|
1046 | ||
1047 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
1048 | } |
|
1049 | ||
1050 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
1051 | // WP.com: get_locale() returns 'it' |
|
1052 | $locale = GP_Locales::by_slug( $lang ); |
|
1053 | } else { |
|
1054 | // Jetpack: get_locale() returns 'it_IT'; |
|
1055 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
1056 | } |
|
1057 | ||
1058 | if ( ! $locale ) { |
|
1059 | return false; |
|
1060 | } |
|
1061 | ||
1062 | if ( empty( $locale->facebook_locale ) ) { |
|
1063 | if ( empty( $locale->wp_locale ) ) { |
|
1064 | return false; |
|
1065 | } else { |
|
1066 | // Facebook SDK is smart enough to fall back to en_US if a |
|
1067 | // locale isn't supported. Since supported Facebook locales |
|
1068 | // can fall out of sync, we'll attempt to use the known |
|
1069 | // wp_locale value and rely on said fallback. |
|
1070 | return $locale->wp_locale; |
|
1071 | } |
|
1072 | } |
|
1073 | ||
1074 | return $locale->facebook_locale; |
|
1075 | } |
|
1076 | ||
1077 | /** |
|
1078 | * Get the locale. |