Ticket #29892: 29892.3.patch
| File 29892.3.patch, 3.2 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'] ) || empty( $translations['admin'] ) ) { 765 return array(); 765 766 } 766 767 768 $languages = array(); 769 foreach ( $translations['default'] as $language => $data ) { 770 if ( ! empty ( $translations['admin'][ $language ] ) ) { 771 $languages[] = $language; 772 } 773 } 774 767 775 return $languages; 768 776 } 769 777 … … 775 783 * 776 784 * @since 3.7.0 777 785 * 778 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. 786 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. 787 * @param string $lang_dir A directory to search for language files. Default WP_LANG_DIR. 779 788 * @return array Array of language data. 780 789 */ 781 function wp_get_installed_translations( $type ) {790 function wp_get_installed_translations( $type, $lang_dir = null ) { 782 791 if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) 783 792 return array(); 784 793 794 $lang_dir = is_null( $lang_dir ) ? WP_LANG_DIR : $lang_dir; 785 795 $dir = 'core' === $type ? '' : "/$type"; 786 796 787 if ( ! is_dir( WP_LANG_DIR ) )797 if ( ! is_dir( $lang_dir ) ) { 788 798 return array(); 799 } 789 800 790 if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )801 if ( $dir && ! is_dir( $lang_dir . $dir ) ) { 791 802 return array(); 803 } 792 804 793 $files = scandir( WP_LANG_DIR. $dir );794 if ( ! $files ) 805 $files = scandir( $lang_dir . $dir ); 806 if ( ! $files ) { 795 807 return array(); 808 } 796 809 797 810 $language_data = array(); 798 811 … … 814 827 if ( '' === $textdomain ) { 815 828 $textdomain = 'default'; 816 829 } 817 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); 830 831 if ( 'core' === $type && ! in_array( $textdomain, array( 'default', 'admin', 'admin-network', 'continents-cities' ) ) ) { 832 continue; 833 } 834 835 $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $lang_dir . "$dir/$file" ); 818 836 } 819 837 return $language_data; 820 838 }