WordPress.org

Make WordPress Core


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

Introduce get_available_languages(). Validate WPLANG. fixes #11774

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.