mu_dropdown_languages

Generates and displays a drop-down of available languages.

Description

mu_dropdown_languages( (array) $lang_files = array(), (string) $current = '' ); 

Parameters (2)

0. $lang_files — Optional. (array) => array()
An array of the language files. Default empty array.
1. $current — Optional. (string) => ''
The current language code. Default empty.

Usage

  1. if ( !function_exists( 'mu_dropdown_languages' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4. // Optional. An array of the language files. Default empty array. 
  5. $lang_files = array(); 
  6.  
  7. // Optional. The current language code. Default empty. 
  8. $current = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = mu_dropdown_languages($lang_files, $current); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function mu_dropdown_languages( $lang_files = array(), $current = '' ) { 
  2. $flag = false; 
  3. $output = array(); 
  4.  
  5. foreach ( (array) $lang_files as $val ) { 
  6. $code_lang = basename( $val, '.mo' ); 
  7.  
  8. if ( $code_lang == 'en_US' ) { // American English 
  9. $flag = true; 
  10. $ae = __( 'American English' ); 
  11. $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>'; 
  12. } elseif ( $code_lang == 'en_GB' ) { // British English 
  13. $flag = true; 
  14. $be = __( 'British English' ); 
  15. $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>'; 
  16. } else { 
  17. $translated = format_code_lang( $code_lang ); 
  18. $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>'; 
  19.  
  20.  
  21. if ( $flag === false ) // WordPress english 
  22. $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>"; 
  23.  
  24. // Order by name 
  25. uksort( $output, 'strnatcasecmp' ); 
  26.  
  27. /** 
  28. * Filters the languages available in the dropdown. 
  29. * @since MU 
  30. * @param array $output HTML output of the dropdown. 
  31. * @param array $lang_files Available language files. 
  32. * @param string $current The current language code. 
  33. */ 
  34. $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current ); 
  35.  
  36. echo implode( "\n\t", $output );