Introduce get_available_languages(). Validate WPLANG. fixes #11774
git-svn-id: http://svn.automattic.com/wordpress/trunk@12946 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b595595a43
commit
cf7da6eab8
|
@ -23,7 +23,7 @@ switch ( $_GET['action'] ) {
|
||||||
if ( empty( $_POST ) )
|
if ( empty( $_POST ) )
|
||||||
wp_die( __("You probably need to go back to the <a href='ms-options.php'>options page</a>") );
|
wp_die( __("You probably need to go back to the <a href='ms-options.php'>options page</a>") );
|
||||||
|
|
||||||
if ( isset($_POST['WPLANG']) )
|
if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array($_POST['WPLANG'], get_available_languages()) ) )
|
||||||
update_site_option( "WPLANG", $_POST['WPLANG'] );
|
update_site_option( "WPLANG", $_POST['WPLANG'] );
|
||||||
|
|
||||||
if ( is_email( $_POST['admin_email'] ) )
|
if ( is_email( $_POST['admin_email'] ) )
|
||||||
|
|
|
@ -252,19 +252,15 @@ if (isset($_GET['updated'])) {
|
||||||
<h3><?php _e('Site Wide Settings <em>(These settings may be overridden by blog owners)</em>') ?></h3>
|
<h3><?php _e('Site Wide Settings <em>(These settings may be overridden by blog owners)</em>') ?></h3>
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<?php
|
<?php
|
||||||
$lang_files = array();
|
$languages = get_available_languages();
|
||||||
if ( is_dir( ABSPATH . LANGDIR ) && $dh = opendir( ABSPATH . LANGDIR ) )
|
|
||||||
while( ( $lang_file = readdir( $dh ) ) !== false )
|
|
||||||
if ( substr( $lang_file, -3 ) == '.mo' )
|
|
||||||
$lang_files[] = $lang_file;
|
|
||||||
$lang = get_site_option('WPLANG');
|
$lang = get_site_option('WPLANG');
|
||||||
if ( !empty($lang_files) ) {
|
if ( !empty($languages) ) {
|
||||||
?>
|
?>
|
||||||
<tr valign="top">
|
<tr valign="top">
|
||||||
<th width="33%"><?php _e('Default Language') ?></th>
|
<th width="33%"><?php _e('Default Language') ?></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="WPLANG" id="WPLANG">
|
<select name="WPLANG" id="WPLANG">
|
||||||
<?php mu_dropdown_languages( $lang_files, get_site_option('WPLANG') ); ?>
|
<?php mu_dropdown_languages( $languages, get_site_option('WPLANG') ); ?>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -484,4 +484,30 @@ function &get_translations_for_domain( $domain ) {
|
||||||
function translate_user_role( $name ) {
|
function translate_user_role( $name ) {
|
||||||
return translate_with_gettext_context( before_last_bar($name), 'User role' );
|
return translate_with_gettext_context( before_last_bar($name), 'User role' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all available languages based on the presence of *.mo files in a given directory. The default directory is WP_LANG_DIR.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*
|
||||||
|
* @param string $dir A directory in which to search for language files. The default directory is WP_LANG_DIR.
|
||||||
|
* @return array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.
|
||||||
|
*/
|
||||||
|
function get_available_languages( $dir = null ) {
|
||||||
|
$languages = array();
|
||||||
|
|
||||||
|
if ( empty($dir) )
|
||||||
|
$dir = WP_LANG_DIR;
|
||||||
|
|
||||||
|
if ( is_dir( $dir ) && $dh = opendir( $dir ) ) {
|
||||||
|
while ( ( $lang_file = readdir( $dh ) ) !== false ) {
|
||||||
|
if ( substr( $lang_file, -3 ) == '.mo' )
|
||||||
|
$languages[] = basename($lang_file, '.mo');
|
||||||
|
}
|
||||||
|
closedir($dh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $languages;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue