Ticket #29892: 29892.2.patch
| File 29892.2.patch, 3.1 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/l10n.php
744 744 } 745 745 746 746 /** 747 * Get all available languages based on the presence of *.mo files in a given directory. 747 * Get all available core languages based on the presence of *.mo/*.po files in 748 * a given directory. 748 749 * 749 750 * The default directory is WP_LANG_DIR. 750 751 * 751 752 * @since 3.0.0 752 753 * 754 * @see wp_get_installed_translations() 755 * 753 756 * @param string $dir A directory to search for language files. 754 757 * Default WP_LANG_DIR. 755 * @return array An 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. 758 * @return array An array of language codes or an empty array if no languages are present. 759 * Language codes are formed by stripping the extension from the language file names. 756 760 */ 757 761 function get_available_languages( $dir = null ) { 758 $ languages = array();762 $translations = wp_get_installed_translations( 'core', $dir ); 759 763 760 foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) { 761 $lang_file = basename($lang_file, '.mo'); 762 if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && 763 0 !== strpos( $lang_file, 'admin-' )) 764 $languages[] = $lang_file; 764 if ( empty( $translations['default'] ) ) { 765 return array(); 765 766 } 766 767 767 return $languages;768 return array_keys( $translations['default'] ); 768 769 } 769 770 770 771 /** … … 775 776 * 776 777 * @since 3.7.0 777 778 * 778 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. 779 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. 780 * @param string $lang_dir A directory to search for language files. Default WP_LANG_DIR. 779 781 * @return array Array of language data. 780 782 */ 781 function wp_get_installed_translations( $type ) {783 function wp_get_installed_translations( $type, $lang_dir = null ) { 782 784 if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) 783 785 return array(); 784 786 787 $lang_dir = is_null( $lang_dir ) ? WP_LANG_DIR : $lang_dir; 785 788 $dir = 'core' === $type ? '' : "/$type"; 786 789 787 if ( ! is_dir( WP_LANG_DIR ) )790 if ( ! is_dir( $lang_dir ) ) { 788 791 return array(); 792 } 789 793 790 if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )794 if ( $dir && ! is_dir( $lang_dir . $dir ) ) { 791 795 return array(); 796 } 792 797 793 $files = scandir( WP_LANG_DIR. $dir );794 if ( ! $files ) 798 $files = scandir( $lang_dir . $dir ); 799 if ( ! $files ) { 795 800 return array(); 801 } 796 802 797 803 $language_data = array(); 798 804 … … 814 820 if ( '' === $textdomain ) { 815 821 $textdomain = 'default'; 816 822 } 817 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); 823 824 if ( 'core' === $type && ! in_array( $textdomain, array( 'default', 'admin', 'admin-network', 'continents-cities' ) ) ) { 825 continue; 826 } 827 828 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $lang_dir . "$dir/$file" ); 818 829 } 819 830 return $language_data; 820 831 }