<?php

class SitePressLanguageSwitcher {

	static function get_language_selector_footer() {
		ob_start();
		do_action( 'wpml_footer_language_selector' );
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	function language_selector_footer() {
		do_action( 'wpml_footer_language_selector' );
	}

	public function language_display( $native_name, $translated_name = false, $show_native_name = false, $show_translate_name = false, $include_html = true ) {
		$result = '';

		if ( ! $show_native_name ) {
			$native_name = '';
		}

		if ( ! $show_translate_name ) {
			$translated_name = '';
		}

		if ( $native_name && $translated_name ) {
			if ( $native_name != $translated_name ) {
				if ( $show_native_name ) {
					if ( $include_html ) {
						$result .= '<span class="icl_lang_sel_native">';
					}
					$result .= '%1$s';
					if ( $include_html ) {
						$result .= '</span>';
					}
					if ( $show_translate_name ) {
						$result .= ' ';
						if ( $include_html ) {
							$result .= '<span class="icl_lang_sel_translated">';
						}
						$result .= $show_native_name
							? '<span class="icl_lang_sel_bracket">(</span>%2$s<span class="icl_lang_sel_bracket">)</span>'
							: '%2$s';
						if ( $include_html ) {
							$result .= '</span>';
						}
					}
				} elseif ( $show_translate_name ) {
					if ( $include_html ) {
						$result .= '<span class="icl_lang_sel_translated">';
					}
					$result .= '%2$s';
					if ( $include_html ) {
						$result .= '</span>';
					}
				}
			} else {
				if ( $include_html ) {
					$result .= '<span class="icl_lang_sel_current icl_lang_sel_native">';
				}
				$result .= '%1$s';
				if ( $include_html ) {
					$result .= '</span>';
				}
			}
		} elseif ( $native_name ) {
			$result = '%1$s';
		} elseif ( $translated_name ) {
			$result = '%2$s';
		}

		return sprintf( $result, $native_name, $translated_name );
	}
}

global $icl_language_switcher;
$icl_language_switcher = new SitePressLanguageSwitcher();
