Code Duplication    Length = 39-39 lines in 2 locations

modules/sharedaddy/sharing-sources.php 1 location

@@ 981-1019 (lines=39) @@
978
	public function display_header() {
979
	}
980
981
	function guess_locale_from_lang( $lang ) {
982
		if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) {
983
			return 'en_US';
984
		}
985
986
		if ( ! class_exists( 'GP_Locales' ) ) {
987
			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
988
				return false;
989
			}
990
991
			require JETPACK__GLOTPRESS_LOCALES_PATH;
992
		}
993
994
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
995
			// WP.com: get_locale() returns 'it'
996
			$locale = GP_Locales::by_slug( $lang );
997
		} else {
998
			// Jetpack: get_locale() returns 'it_IT';
999
			$locale = GP_Locales::by_field( 'wp_locale', $lang );
1000
		}
1001
1002
		if ( ! $locale ) {
1003
			return false;
1004
		}
1005
1006
		if ( empty( $locale->facebook_locale ) ) {
1007
			if ( empty( $locale->wp_locale ) ) {
1008
				return false;
1009
			} else {
1010
				// Facebook SDK is smart enough to fall back to en_US if a
1011
				// locale isn't supported. Since supported Facebook locales
1012
				// can fall out of sync, we'll attempt to use the known
1013
				// wp_locale value and rely on said fallback.
1014
				return $locale->wp_locale;
1015
			}
1016
		}
1017
1018
		return $locale->facebook_locale;
1019
	}
1020
1021
	public function get_display( $post ) {
1022
		if ( $this->smart ) {

class.jetpack.php 1 location

@@ 1193-1231 (lines=39) @@
1190
	 * @param string $lang Language code.
1191
	 * @return string|bool
1192
	 */
1193
	function guess_locale_from_lang( $lang ) {
1194
		if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) {
1195
			return 'en_US';
1196
		}
1197
1198
		if ( ! class_exists( 'GP_Locales' ) ) {
1199
			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
1200
				return false;
1201
			}
1202
1203
			require JETPACK__GLOTPRESS_LOCALES_PATH;
1204
		}
1205
1206
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
1207
			// WP.com: get_locale() returns 'it'
1208
			$locale = \GP_Locales::by_slug( $lang );
1209
		} else {
1210
			// Jetpack: get_locale() returns 'it_IT';
1211
			$locale = \GP_Locales::by_field( 'facebook_locale', $lang );
1212
		}
1213
1214
		if ( ! $locale ) {
1215
			return false;
1216
		}
1217
1218
		if ( empty( $locale->facebook_locale ) ) {
1219
			if ( empty( $locale->wp_locale ) ) {
1220
				return false;
1221
			} else {
1222
				// Facebook SDK is smart enough to fall back to en_US if a
1223
				// locale isn't supported. Since supported Facebook locales
1224
				// can fall out of sync, we'll attempt to use the known
1225
				// wp_locale value and rely on said fallback.
1226
				return $locale->wp_locale;
1227
			}
1228
		}
1229
1230
		return $locale->facebook_locale;
1231
	}
1232
1233
	/**
1234
	 * Get the locale.