Code Duplication    Length = 39-39 lines in 2 locations

modules/sharedaddy/sharing-sources.php 1 location

@@ 866-904 (lines=39) @@
863
	public function display_header() {
864
	}
865
866
	function guess_locale_from_lang( $lang ) {
867
		if ( 'en' == $lang || 'en_US' == $lang || !$lang ) {
868
			return 'en_US';
869
		}
870
871
		if ( !class_exists( 'GP_Locales' ) ) {
872
			if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
873
				return false;
874
			}
875
876
			require JETPACK__GLOTPRESS_LOCALES_PATH;
877
		}
878
879
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
880
			// WP.com: get_locale() returns 'it'
881
			$locale = GP_Locales::by_slug( $lang );
882
		} else {
883
			// Jetpack: get_locale() returns 'it_IT';
884
			$locale = GP_Locales::by_field( 'wp_locale', $lang );
885
		}
886
887
		if ( ! $locale ) {
888
			return false;
889
		}
890
891
		if ( empty( $locale->facebook_locale ) ) {
892
			if ( empty( $locale->wp_locale ) ) {
893
				return false;
894
			} else {
895
				// Facebook SDK is smart enough to fall back to en_US if a
896
				// locale isn't supported. Since supported Facebook locales
897
				// can fall out of sync, we'll attempt to use the known
898
				// wp_locale value and rely on said fallback.
899
				return $locale->wp_locale;
900
			}
901
		}
902
903
		return $locale->facebook_locale;
904
	}
905
906
	public function get_display( $post ) {
907
		if ( $this->smart ) {

class.jetpack.php 1 location

@@ 787-825 (lines=39) @@
784
	 * @param string $lang Language code.
785
	 * @return string|bool
786
	 */
787
	function guess_locale_from_lang( $lang ) {
788
		if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) {
789
			return 'en_US';
790
		}
791
792
		if ( ! class_exists( 'GP_Locales' ) ) {
793
			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
794
				return false;
795
			}
796
797
			require JETPACK__GLOTPRESS_LOCALES_PATH;
798
		}
799
800
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
801
			// WP.com: get_locale() returns 'it'
802
			$locale = GP_Locales::by_slug( $lang );
803
		} else {
804
			// Jetpack: get_locale() returns 'it_IT';
805
			$locale = GP_Locales::by_field( 'facebook_locale', $lang );
806
		}
807
808
		if ( ! $locale ) {
809
			return false;
810
		}
811
812
		if ( empty( $locale->facebook_locale ) ) {
813
			if ( empty( $locale->wp_locale ) ) {
814
				return false;
815
			} else {
816
				// Facebook SDK is smart enough to fall back to en_US if a
817
				// locale isn't supported. Since supported Facebook locales
818
				// can fall out of sync, we'll attempt to use the known
819
				// wp_locale value and rely on said fallback.
820
				return $locale->wp_locale;
821
			}
822
		}
823
824
		return $locale->facebook_locale;
825
	}
826
827
	/**
828
	 * Get the locale.