Changeset 29630 for trunk/src/wp-includes/l10n.php
- Timestamp:
- 08/26/2014 07:58:33 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r29163 r29630 25 25 */ 26 26 function get_locale() { 27 global $locale ;27 global $locale, $wp_local_package; 28 28 29 29 if ( isset( $locale ) ) { … … 38 38 } 39 39 40 // WPLANG is defined in wp-config. 41 if ( defined( 'WPLANG' ) ) 40 if ( isset( $wp_local_package ) ) { 41 $locale = $wp_local_package; 42 } 43 44 // WPLANG was defined in wp-config. 45 if ( defined( 'WPLANG' ) ) { 42 46 $locale = WPLANG; 47 } 43 48 44 49 // If multisite, check options. 45 50 if ( is_multisite() ) { 46 51 // Don't check blog option when installing. 47 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) 48 $ms_locale = get_site_option('WPLANG'); 49 50 if ( $ms_locale !== false ) 52 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { 53 $ms_locale = get_site_option( 'WPLANG' ); 54 } 55 56 if ( $ms_locale !== false ) { 51 57 $locale = $ms_locale; 52 } elseif ( ! defined( 'WP_INSTALLING' ) ) { 58 } 59 } else { 53 60 $db_locale = get_option( 'WPLANG' ); 54 if ( $db_locale ) {61 if ( $db_locale !== false ) { 55 62 $locale = $db_locale; 56 63 } 57 64 } 58 65 59 if ( empty( $locale ) ) 66 if ( empty( $locale ) ) { 60 67 $locale = 'en_US'; 68 } 61 69 62 70 /** This filter is documented in wp-includes/l10n.php */ … … 524 532 * 525 533 * @since 1.5.0 526 */ 527 function load_default_textdomain() { 528 $locale = get_locale(); 529 530 load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); 534 * 535 * @param string $locale Optional. Locale to load. Defaults to get_locale(). 536 */ 537 function load_default_textdomain( $locale = null ) { 538 if ( null === $locale ) { 539 $locale = get_locale(); 540 } 541 542 // Unload previously loaded strings so we can switch translations. 543 unload_textdomain( 'default' ); 544 545 $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); 531 546 532 547 if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { 533 548 load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); 534 return ;535 } 536 537 if ( is_admin() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) )549 return $return; 550 } 551 552 if ( is_admin() || defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { 538 553 load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); 554 } 539 555 540 556 if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) 541 557 load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); 542 558 559 return $return; 543 560 } 544 561 … … 819 836 820 837 /** 821 * Language selector. More to come.838 * Language selector. 822 839 * 823 840 * @since 4.0.0 824 841 * 825 842 * @see get_available_languages() 843 * @see wp_get_available_translations() 826 844 * 827 845 * @param array $args Optional arguments. Default empty array. 828 846 */ 829 847 function wp_dropdown_languages( $args = array() ) { 830 if ( isset( $args['languages'] ) ) { 831 $languages = $args['languages']; 832 } else { 833 $languages = get_available_languages(); 848 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 849 850 $args = wp_parse_args( $args, array( 851 'id' => '', 852 'name' => '', 853 'languages' => array(), 854 'selected' => '' 855 ) ); 856 857 if ( empty( $args['languages'] ) ) { 858 return false; 859 } 860 861 $translations = wp_get_available_translations(); 862 863 /* 864 * $args['languages'] should only contain the locales. Find the locale in 865 * $translations to get the native name. Fall back to locale. 866 */ 867 $languages = array(); 868 foreach ( $args['languages'] as $locale ) { 869 if ( isset( $translations[ $locale ] ) ) { 870 $translation = $translations[ $locale ]; 871 $languages[] = array( 872 'language' => $translation['language'], 873 'native_name' => $translation['native_name'], 874 'lang' => $translation['iso'][1], 875 ); 876 } else { 877 $languages[] = array( 878 'language' => $locale, 879 'native_name' => $locale, 880 'lang' => '', 881 ); 882 } 834 883 } 835 884 836 885 printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) ); 837 echo '<option value="">en_US</option>'; 886 887 // List installed languages. 888 echo '<option value="" lang="en">English (United States)</option>'; 838 889 foreach ( $languages as $language ) { 839 $selected = selected( $language, $args['selected'], false ); 840 echo '<option value="' . esc_attr( $language ) .'"' . $selected . '>' . $language . '</option>'; 841 } 890 $selected = selected( $language['language'], $args['selected'], false ); 891 printf( 892 '<option value="%s" lang="%s"%s>%s</option>', 893 esc_attr( $language['language'] ), 894 esc_attr( $language['lang'] ), 895 $selected, 896 esc_html( $language['native_name'] ) 897 ); 898 } 899 842 900 echo '</select>'; 843 901 }
Note: See TracChangeset
for help on using the changeset viewer.