Make WordPress Core

Changeset 12946


Ignore:
Timestamp:
02/04/2010 06:46:25 PM (15 years ago)
Author:
ryan
Message:

Introduce get_available_languages(). Validate WPLANG. fixes #11774

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/ms-edit.php

    r12945 r12946  
    2424            wp_die( __("You probably need to go back to the <a href='ms-options.php'>options page</a>") );
    2525
    26         if ( isset($_POST['WPLANG']) )
     26        if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array($_POST['WPLANG'], get_available_languages()) ) )
    2727            update_site_option( "WPLANG", $_POST['WPLANG'] );
    2828
  • trunk/wp-admin/ms-options.php

    r12911 r12946  
    253253        <table class="form-table">
    254254            <?php
    255             $lang_files = array();
    256             if ( is_dir( ABSPATH . LANGDIR ) && $dh = opendir( ABSPATH . LANGDIR ) )
    257                 while( ( $lang_file = readdir( $dh ) ) !== false )
    258                     if ( substr( $lang_file, -3 ) == '.mo' )
    259                         $lang_files[] = $lang_file;
     255            $languages = get_available_languages();
    260256            $lang = get_site_option('WPLANG');
    261             if ( !empty($lang_files) ) {
     257            if ( !empty($languages) ) {
    262258                ?>
    263259                <tr valign="top">
     
    265261                    <td>
    266262                        <select name="WPLANG" id="WPLANG">
    267                             <?php mu_dropdown_languages( $lang_files, get_site_option('WPLANG') ); ?>
     263                            <?php mu_dropdown_languages( $languages, get_site_option('WPLANG') ); ?>
    268264                        </select>
    269265                    </td>
  • trunk/wp-includes/l10n.php

    r12900 r12946  
    485485    return translate_with_gettext_context( before_last_bar($name), 'User role' );
    486486}
     487
     488/**
     489 * Get all available languages based on the presence of *.mo files in a given directory. The default directory is WP_LANG_DIR.
     490 *
     491 * @since 3.0.0
     492 *
     493 * @param string $dir A directory in which to search for language files. The default directory is WP_LANG_DIR.
     494 * @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.
     495 */
     496function get_available_languages( $dir = null ) {
     497    $languages = array();
     498
     499    if ( empty($dir) )
     500        $dir = WP_LANG_DIR;
     501
     502    if ( is_dir( $dir ) && $dh = opendir( $dir ) ) {
     503        while ( ( $lang_file = readdir( $dh ) ) !== false ) {
     504            if ( substr( $lang_file, -3 ) == '.mo' )
     505                $languages[] = basename($lang_file, '.mo');
     506        }
     507        closedir($dh);
     508    }
     509
     510    return $languages;
     511}
     512
    487513?>
Note: See TracChangeset for help on using the changeset viewer.