| @@ 866-904 (lines=39) @@ | ||
| 863 | public function display_header() { |
|
| 864 | } |
|
| 865 | ||
| 866 | function guess_locale_from_lang( $lang ) { |
|
| 867 | if ( 'en' == $lang || 'en_US' == $lang || !$lang ) { |
|
| 868 | return 'en_US'; |
|
| 869 | } |
|
| 870 | ||
| 871 | if ( !class_exists( 'GP_Locales' ) ) { |
|
| 872 | if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 873 | return false; |
|
| 874 | } |
|
| 875 | ||
| 876 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 877 | } |
|
| 878 | ||
| 879 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 880 | // WP.com: get_locale() returns 'it' |
|
| 881 | $locale = GP_Locales::by_slug( $lang ); |
|
| 882 | } else { |
|
| 883 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 884 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
| 885 | } |
|
| 886 | ||
| 887 | if ( ! $locale ) { |
|
| 888 | return false; |
|
| 889 | } |
|
| 890 | ||
| 891 | if ( empty( $locale->facebook_locale ) ) { |
|
| 892 | if ( empty( $locale->wp_locale ) ) { |
|
| 893 | return false; |
|
| 894 | } else { |
|
| 895 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 896 | // locale isn't supported. Since supported Facebook locales |
|
| 897 | // can fall out of sync, we'll attempt to use the known |
|
| 898 | // wp_locale value and rely on said fallback. |
|
| 899 | return $locale->wp_locale; |
|
| 900 | } |
|
| 901 | } |
|
| 902 | ||
| 903 | return $locale->facebook_locale; |
|
| 904 | } |
|
| 905 | ||
| 906 | public function get_display( $post ) { |
|
| 907 | if ( $this->smart ) { |
|
| @@ 942-980 (lines=39) @@ | ||
| 939 | * @param string $lang Language code. |
|
| 940 | * @return string|bool |
|
| 941 | */ |
|
| 942 | function guess_locale_from_lang( $lang ) { |
|
| 943 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
| 944 | return 'en_US'; |
|
| 945 | } |
|
| 946 | ||
| 947 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 948 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 949 | return false; |
|
| 950 | } |
|
| 951 | ||
| 952 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 953 | } |
|
| 954 | ||
| 955 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 956 | // WP.com: get_locale() returns 'it' |
|
| 957 | $locale = GP_Locales::by_slug( $lang ); |
|
| 958 | } else { |
|
| 959 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 960 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
| 961 | } |
|
| 962 | ||
| 963 | if ( ! $locale ) { |
|
| 964 | return false; |
|
| 965 | } |
|
| 966 | ||
| 967 | if ( empty( $locale->facebook_locale ) ) { |
|
| 968 | if ( empty( $locale->wp_locale ) ) { |
|
| 969 | return false; |
|
| 970 | } else { |
|
| 971 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 972 | // locale isn't supported. Since supported Facebook locales |
|
| 973 | // can fall out of sync, we'll attempt to use the known |
|
| 974 | // wp_locale value and rely on said fallback. |
|
| 975 | return $locale->wp_locale; |
|
| 976 | } |
|
| 977 | } |
|
| 978 | ||
| 979 | return $locale->facebook_locale; |
|
| 980 | } |
|
| 981 | ||
| 982 | /** |
|
| 983 | * Get the locale. |
|