Code Duplication    Length = 39-39 lines in 2 locations

modules/sharedaddy/sharing-sources.php 1 location

@@ 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 ) {

class.jetpack.php 1 location

@@ 802-840 (lines=39) @@
799
	 * @param string $lang Language code.
800
	 * @return string|bool
801
	 */
802
	function guess_locale_from_lang( $lang ) {
803
		if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) {
804
			return 'en_US';
805
		}
806
807
		if ( ! class_exists( 'GP_Locales' ) ) {
808
			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
809
				return false;
810
			}
811
812
			require JETPACK__GLOTPRESS_LOCALES_PATH;
813
		}
814
815
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
816
			// WP.com: get_locale() returns 'it'
817
			$locale = GP_Locales::by_slug( $lang );
818
		} else {
819
			// Jetpack: get_locale() returns 'it_IT';
820
			$locale = GP_Locales::by_field( 'facebook_locale', $lang );
821
		}
822
823
		if ( ! $locale ) {
824
			return false;
825
		}
826
827
		if ( empty( $locale->facebook_locale ) ) {
828
			if ( empty( $locale->wp_locale ) ) {
829
				return false;
830
			} else {
831
				// Facebook SDK is smart enough to fall back to en_US if a
832
				// locale isn't supported. Since supported Facebook locales
833
				// can fall out of sync, we'll attempt to use the known
834
				// wp_locale value and rely on said fallback.
835
				return $locale->wp_locale;
836
			}
837
		}
838
839
		return $locale->facebook_locale;
840
	}
841
842
	/**
843
	 * Get the locale.