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