| @@ 868-906 (lines=39) @@ | ||
| 865 | 	public function display_header() { | |
| 866 | } | |
| 867 | ||
| 868 | 	function guess_locale_from_lang( $lang ) { | |
| 869 | 		if ( 'en' == $lang || 'en_US' == $lang || !$lang ) { | |
| 870 | return 'en_US'; | |
| 871 | } | |
| 872 | ||
| 873 | 		if ( !class_exists( 'GP_Locales' ) ) { | |
| 874 | 			if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { | |
| 875 | return false; | |
| 876 | } | |
| 877 | ||
| 878 | require JETPACK__GLOTPRESS_LOCALES_PATH; | |
| 879 | } | |
| 880 | ||
| 881 | 		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 882 | // WP.com: get_locale() returns 'it' | |
| 883 | $locale = GP_Locales::by_slug( $lang ); | |
| 884 | 		} else { | |
| 885 | // Jetpack: get_locale() returns 'it_IT'; | |
| 886 | $locale = GP_Locales::by_field( 'wp_locale', $lang ); | |
| 887 | } | |
| 888 | ||
| 889 | 		if ( ! $locale ) { | |
| 890 | return false; | |
| 891 | } | |
| 892 | ||
| 893 | 		if ( empty( $locale->facebook_locale ) ) { | |
| 894 | 			if ( empty( $locale->wp_locale ) ) { | |
| 895 | return false; | |
| 896 | 			} else { | |
| 897 | // Facebook SDK is smart enough to fall back to en_US if a | |
| 898 | // locale isn't supported. Since supported Facebook locales | |
| 899 | // can fall out of sync, we'll attempt to use the known | |
| 900 | // wp_locale value and rely on said fallback. | |
| 901 | return $locale->wp_locale; | |
| 902 | } | |
| 903 | } | |
| 904 | ||
| 905 | return $locale->facebook_locale; | |
| 906 | } | |
| 907 | ||
| 908 | 	public function get_display( $post ) { | |
| 909 | 		if ( $this->smart ) { | |
| @@ 1027-1065 (lines=39) @@ | ||
| 1024 | * @param string $lang Language code. | |
| 1025 | * @return string|bool | |
| 1026 | */ | |
| 1027 | 	function guess_locale_from_lang( $lang ) { | |
| 1028 | 		if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { | |
| 1029 | return 'en_US'; | |
| 1030 | } | |
| 1031 | ||
| 1032 | 		if ( ! class_exists( 'GP_Locales' ) ) { | |
| 1033 | 			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { | |
| 1034 | return false; | |
| 1035 | } | |
| 1036 | ||
| 1037 | require JETPACK__GLOTPRESS_LOCALES_PATH; | |
| 1038 | } | |
| 1039 | ||
| 1040 | 		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 1041 | // WP.com: get_locale() returns 'it' | |
| 1042 | $locale = GP_Locales::by_slug( $lang ); | |
| 1043 | 		} else { | |
| 1044 | // Jetpack: get_locale() returns 'it_IT'; | |
| 1045 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); | |
| 1046 | } | |
| 1047 | ||
| 1048 | 		if ( ! $locale ) { | |
| 1049 | return false; | |
| 1050 | } | |
| 1051 | ||
| 1052 | 		if ( empty( $locale->facebook_locale ) ) { | |
| 1053 | 			if ( empty( $locale->wp_locale ) ) { | |
| 1054 | return false; | |
| 1055 | 			} else { | |
| 1056 | // Facebook SDK is smart enough to fall back to en_US if a | |
| 1057 | // locale isn't supported. Since supported Facebook locales | |
| 1058 | // can fall out of sync, we'll attempt to use the known | |
| 1059 | // wp_locale value and rely on said fallback. | |
| 1060 | return $locale->wp_locale; | |
| 1061 | } | |
| 1062 | } | |
| 1063 | ||
| 1064 | return $locale->facebook_locale; | |
| 1065 | } | |
| 1066 | ||
| 1067 | /** | |
| 1068 | * Get the locale. | |