| @@ 893-931 (lines=39) @@ | ||
| 890 | public function display_header() { |
|
| 891 | } |
|
| 892 | ||
| 893 | function guess_locale_from_lang( $lang ) { |
|
| 894 | if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
|
| 895 | return 'en_US'; |
|
| 896 | } |
|
| 897 | ||
| 898 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 899 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 900 | return false; |
|
| 901 | } |
|
| 902 | ||
| 903 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 904 | } |
|
| 905 | ||
| 906 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 907 | // WP.com: get_locale() returns 'it' |
|
| 908 | $locale = GP_Locales::by_slug( $lang ); |
|
| 909 | } else { |
|
| 910 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 911 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); |
|
| 912 | } |
|
| 913 | ||
| 914 | if ( ! $locale ) { |
|
| 915 | return false; |
|
| 916 | } |
|
| 917 | ||
| 918 | if ( empty( $locale->facebook_locale ) ) { |
|
| 919 | if ( empty( $locale->wp_locale ) ) { |
|
| 920 | return false; |
|
| 921 | } else { |
|
| 922 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 923 | // locale isn't supported. Since supported Facebook locales |
|
| 924 | // can fall out of sync, we'll attempt to use the known |
|
| 925 | // wp_locale value and rely on said fallback. |
|
| 926 | return $locale->wp_locale; |
|
| 927 | } |
|
| 928 | } |
|
| 929 | ||
| 930 | return $locale->facebook_locale; |
|
| 931 | } |
|
| 932 | ||
| 933 | public function get_display( $post ) { |
|
| 934 | if ( $this->smart ) { |
|
| @@ 954-992 (lines=39) @@ | ||
| 951 | * @param string $lang Language code. |
|
| 952 | * @return string|bool |
|
| 953 | */ |
|
| 954 | function guess_locale_from_lang( $lang ) { |
|
| 955 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
|
| 956 | return 'en_US'; |
|
| 957 | } |
|
| 958 | ||
| 959 | if ( ! class_exists( 'GP_Locales' ) ) { |
|
| 960 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
|
| 961 | return false; |
|
| 962 | } |
|
| 963 | ||
| 964 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
|
| 965 | } |
|
| 966 | ||
| 967 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 968 | // WP.com: get_locale() returns 'it' |
|
| 969 | $locale = GP_Locales::by_slug( $lang ); |
|
| 970 | } else { |
|
| 971 | // Jetpack: get_locale() returns 'it_IT'; |
|
| 972 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
|
| 973 | } |
|
| 974 | ||
| 975 | if ( ! $locale ) { |
|
| 976 | return false; |
|
| 977 | } |
|
| 978 | ||
| 979 | if ( empty( $locale->facebook_locale ) ) { |
|
| 980 | if ( empty( $locale->wp_locale ) ) { |
|
| 981 | return false; |
|
| 982 | } else { |
|
| 983 | // Facebook SDK is smart enough to fall back to en_US if a |
|
| 984 | // locale isn't supported. Since supported Facebook locales |
|
| 985 | // can fall out of sync, we'll attempt to use the known |
|
| 986 | // wp_locale value and rely on said fallback. |
|
| 987 | return $locale->wp_locale; |
|
| 988 | } |
|
| 989 | } |
|
| 990 | ||
| 991 | return $locale->facebook_locale; |
|
| 992 | } |
|
| 993 | ||
| 994 | /** |
|
| 995 | * Get the locale. |
|