@@ 892-930 (lines=39) @@ | ||
889 | public function display_header() { |
|
890 | } |
|
891 | ||
892 | function guess_locale_from_lang( $lang ) { |
|
893 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
894 | return 'en_US'; |
|
895 | } |
|
896 | ||
897 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
898 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
899 | return false; |
|
900 | } |
|
901 | ||
902 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
903 | } |
|
904 | ||
905 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
906 | // WP.com: get_locale() returns 'it' |
|
907 | $locale = GP_Locales::by_slug( $lang ); |
|
908 | } else { |
|
909 | // Jetpack: get_locale() returns 'it_IT'; |
|
910 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
911 | } |
|
912 | ||
913 | if ( ! $locale ) { |
|
914 | return false; |
|
915 | } |
|
916 | ||
917 | if ( empty( $locale->facebook_locale ) ) { |
|
918 | if ( empty( $locale->wp_locale ) ) { |
|
919 | return false; |
|
920 | } else { |
|
921 | // Facebook SDK is smart enough to fall back to en_US if a |
|
922 | // locale isn't supported. Since supported Facebook locales |
|
923 | // can fall out of sync, we'll attempt to use the known |
|
924 | // wp_locale value and rely on said fallback. |
|
925 | return $locale->wp_locale; |
|
926 | } |
|
927 | } |
|
928 | ||
929 | return $locale->facebook_locale; |
|
930 | } |
|
931 | ||
932 | public function get_display( $post ) { |
|
933 | if ( $this->smart ) { |
@@ 1008-1046 (lines=39) @@ | ||
1005 | * @param string $lang Language code. |
|
1006 | * @return string|bool |
|
1007 | */ |
|
1008 | function guess_locale_from_lang( $lang ) { |
|
1009 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
1010 | return 'en_US'; |
|
1011 | } |
|
1012 | ||
1013 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
1014 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
1015 | return false; |
|
1016 | } |
|
1017 | ||
1018 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
1019 | } |
|
1020 | ||
1021 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
1022 | // WP.com: get_locale() returns 'it' |
|
1023 | $locale = GP_Locales::by_slug( $lang ); |
|
1024 | } else { |
|
1025 | // Jetpack: get_locale() returns 'it_IT'; |
|
1026 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
1027 | } |
|
1028 | ||
1029 | if ( ! $locale ) { |
|
1030 | return false; |
|
1031 | } |
|
1032 | ||
1033 | if ( empty( $locale->facebook_locale ) ) { |
|
1034 | if ( empty( $locale->wp_locale ) ) { |
|
1035 | return false; |
|
1036 | } else { |
|
1037 | // Facebook SDK is smart enough to fall back to en_US if a |
|
1038 | // locale isn't supported. Since supported Facebook locales |
|
1039 | // can fall out of sync, we'll attempt to use the known |
|
1040 | // wp_locale value and rely on said fallback. |
|
1041 | return $locale->wp_locale; |
|
1042 | } |
|
1043 | } |
|
1044 | ||
1045 | return $locale->facebook_locale; |
|
1046 | } |
|
1047 | ||
1048 | /** |
|
1049 | * Get the locale. |