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