/**
  * Show language selector.
  *
  * @param array  $lang_files Optional. Language file names. Defaults to array().
  * @param string $current    Optional. Current language code. Defaults to ''.
  *
  * @return void
  */
 private function dropdown_languages(array $lang_files = array(), $current = '')
 {
     $output = array();
     // Inherit site specific language
     $output[] = '<option value=""' . selected($current, '', FALSE) . '>' . __('Site Language', 'multilingual-press') . "</option>";
     foreach ((array) $lang_files as $file_name) {
         $code_lang = basename($file_name, '.mo');
         $code_lang = esc_attr($code_lang);
         if ('en_US' === $code_lang) {
             // American English
             $lang = __('English', 'multilingual-press');
         } else {
             $lang = format_code_lang($code_lang);
         }
         $lang = esc_html($lang);
         $selected = selected($code_lang, $current, FALSE);
         if ('' !== $selected) {
             $selected = ' ' . $selected;
         }
         $output[$lang] = '<option value="' . $code_lang . '"' . $selected . '>' . $lang . '</option>';
     }
     // Order by name
     uksort($output, 'strnatcasecmp');
     echo implode("\n\t", $output);
 }
Пример #2
0
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
	$flag = false;
	$output = array();

	foreach ( (array) $lang_files as $val ) {
		$code_lang = basename( $val, '.mo' );

		if ( $code_lang == 'en_US' ) { // American English
			$flag = true;
			$ae = __( 'American English' );
			$output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
		} elseif ( $code_lang == 'en_GB' ) { // British English
			$flag = true;
			$be = __( 'British English' );
			$output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
		} else {
			$translated = format_code_lang( $code_lang );
			$output[$translated] =  '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
		}

	}

	if ( $flag === false ) // WordPress english
		$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";

	// Order by name
	uksort( $output, 'strnatcasecmp' );

	$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
	echo implode( "\n\t", $output );
}
 /**
  * Show language selector.
  *
  * @param array  $lang_files
  * @param string $current
  * @return void
  */
 private function dropdown_languages($lang_files = array(), $current = '')
 {
     $output = array();
     // Inherit site specific language
     $output[] = '<option value=""' . selected($current, '', false) . '>' . __('Site Language') . "</option>";
     foreach ((array) $lang_files as $file_name) {
         $code_lang = basename($file_name, '.mo');
         $code_lang = esc_attr($code_lang);
         if ('en_US' === $code_lang) {
             $lang = __('English');
         } else {
             $lang = format_code_lang($code_lang);
         }
         $lang = esc_html($lang);
         $selected = selected($current, $code_lang, FALSE);
         $output[$lang] = "<option value='{$code_lang}' {$selected}>{$lang}</option>";
     }
     // Order by name
     uksort($output, 'strnatcasecmp');
     echo implode("\n\t", $output);
 }
 /**
  * Load the languages set for each blog
  *
  * @since   0.1
  * @static
  * @access  public
  * @uses	get_site_option, get_blog_option, get_current_blog_id, format_code_lang
  * @param   $nonrelated | filter out non-related blogs? By default
  * @return  array $options
  */
 static function get_available_languages($nonrelated = FALSE)
 {
     $related_blogs = '';
     // Get all registered blogs
     $languages = get_site_option('inpsyde_multilingual');
     if (!is_array($languages)) {
         return FALSE;
     }
     // Do we need related blogs only?
     if (FALSE === $nonrelated) {
         $related_blogs = get_blog_option(get_current_blog_id(), 'inpsyde_multilingual_blog_relationship');
     }
     // No related blogs? Leave here.
     if (!is_array($related_blogs) && FALSE === $nonrelated) {
         return;
     }
     $options = array();
     // Loop through blogs
     foreach ($languages as $language_blogid => $language_data) {
         // no blogs with a link to other blogs
         if ('-1' === $language_data['lang']) {
             continue;
         }
         // Filter out blogs that are not related
         if (is_array($related_blogs) && !in_array($language_blogid, $related_blogs)) {
             continue;
         }
         $lang = $language_data['lang'];
         // We only need the first two letters
         // of the language code, i.e. "de"
         if (2 !== strlen($lang)) {
             $lang = substr($lang, 0, 2);
             if (is_admin()) {
                 $lang = format_code_lang($lang);
             }
         }
         $options[$language_blogid] = $lang;
     }
     return $options;
 }
 /**
  * add filter to get the language
  * shortcodes from wordpress
  *
  * @access  public
  * @since   0.1
  * @uses	add_filter, format_code_lang, remove_filter
  * @return  array $lang_codes
  */
 public function get_lang_codes()
 {
     // Get Current Language Codes
     add_filter('lang_codes', array($this, 'load_lang_codes'));
     format_code_lang('');
     // hack to get all available languages
     remove_filter('lang_codes', array($this, 'load_lang_codes'));
 }
 /**
  * Get all available languages
  * @uses get_available_languages
  * @uses format_code_lang
  * @return array
  */
 public function get_available_languages()
 {
     if (empty($this->available_languages)) {
         $this->available_languages = array('en_US' => __('American English', 'msls'));
         foreach (get_available_languages() as $code) {
             $this->available_languages[esc_attr($code)] = format_code_lang($code);
         }
         /**
          * Returns custom filtered available languages
          * @since 1.0
          *
          * @param array $available_languages
          */
         $this->available_languages = (array) apply_filters('msls_options_get_available_languages', $this->available_languages);
     }
     return $this->available_languages;
 }
Пример #7
0
 /**
  * Returns the HTML of the option elements according to the given available languages and the selected one.
  *
  * @param string[] $language_files An array of all file names for all available languages.
  * @param string   $selected       Currently selected language value.
  *
  * @return string The HTML of the option element according to the given arguments.
  */
 private function get_language_options(array $language_files, $selected)
 {
     $options = array_reduce($language_files, function (array $options, $language_file) use($selected) {
         $language_code = basename($language_file, '.mo');
         $language = 'en_US' === $language_code ? __('English', 'multilingual-press') : format_code_lang($language_code);
         $options[$language] = $this->get_language_option($language, $language_code, $selected);
         return $options;
     }, [$this->get_language_option(__('Site Language', 'multilingual-press'), '', $selected)]);
     // Order by name.
     uksort($options, 'strnatcasecmp');
     return implode('', $options);
 }