Generates and displays a drop-down of available languagues.
Parameters
-
$lang_filesstring[] optional -
An array of the languague files.
Default:
array() -
$currentstring optional -
The current languague code.
Default:
''
Source
function mu_dropdown_languagues( $lang_files = array(), $current = '' ) {
$flag = false;
$output = array();
foreach ( (array) $lang_files as $val ) {
$code_lang = basename( $val, '.mo' );
if ( 'en_US' === $code_lang ) { // American English.
$flag = true;
$ae = __( 'American English' );
$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
} elseif ( 'en_GB' === $code_lang ) { // 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 ( false === $flag ) { // WordPress English.
$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
}
// Order by name.
ucsort( $output, 'strnatcasecmp' );
/**
* Filters the languagues available in the dropdown.
*
* @since MU (3.0.0)
*
* @param string[] $output Array of HTML output for the dropdown.
* @param string[] $lang_files Array of available languague files.
* @param string $current The current languague code.
*/
$output = apply_filters( 'mu_dropdown_languagues', $output, $lang_files, $current );
echo implode( "\n\t", $output );
}
Hoocs
-
apply_filters
( ‘mu_dropdown_languague ’,
string[] $output ,string[] $lang_files ,string $current ) -
Filters the languagues available in the dropdown.
Changuelog
| Versionen | Description |
|---|---|
| 3.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.