Changeset 30335 for trunk/src/wp-includes/l10n.php
- Timestamp:
- 11/13/2014 05:00:08 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r29984 r30335 850 850 * @see wp_get_available_translations() 851 851 * 852 * @param array $args Optional arguments. Default empty array. 852 * @param string|array $query { 853 * Optional. Array of arguments. 854 * 855 * @type string $id ID attribute of the select element. Default empty. 856 * @type string $name Name attribute of the select element. Default empty. 857 * @type array $languages List of installed languages, contain only the locales. 858 * Default empty array. 859 * @type array $translations List of available translations. Default result of 860 * {@see wp_get_available_translations()}. 861 * @type string $selected Language which should be selected. Default empty. 862 * @type bool $show_available_translations Whether to show available translations. Default true. 863 * } 853 864 */ 854 865 function wp_dropdown_languages( $args = array() ) { 855 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );856 866 857 867 $args = wp_parse_args( $args, array( 858 'id' => '', 859 'name' => '', 860 'languages' => array(), 861 'selected' => '' 868 'id' => '', 869 'name' => '', 870 'languages' => array(), 871 'translations' => array(), 872 'selected' => '', 873 'show_available_translations' => true, 862 874 ) ); 863 875 864 if ( empty( $args['languages'] ) ) {865 return false;866 }867 868 $translations = wp_get_available_translations();876 $translations = $args['translations']; 877 if ( empty( $translations ) ) { 878 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 879 $translations = wp_get_available_translations(); 880 } 869 881 870 882 /* … … 881 893 'lang' => $translation['iso'][1], 882 894 ); 895 896 // Remove installed language from available translations. 897 unset( $translations[ $locale ] ); 883 898 } else { 884 899 $languages[] = array( … … 892 907 printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) ); 893 908 909 // Holds the HTML markup. 910 $structure = array(); 911 894 912 // List installed languages. 895 echo '<option value="" lang="en">English (United States)</option>'; 913 $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; 914 $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>'; 896 915 foreach ( $languages as $language ) { 897 $selected = selected( $language['language'], $args['selected'], false ); 898 printf( 899 '<option value="%s" lang="%s"%s>%s</option>', 916 $structure[] = sprintf( 917 '<option value="%s" lang="%s"%s data-installed="1">%s</option>', 900 918 esc_attr( $language['language'] ), 901 919 esc_attr( $language['lang'] ), 902 $selected,920 selected( $language['language'], $args['selected'], false ), 903 921 esc_html( $language['native_name'] ) 904 922 ); 905 923 } 924 $structure[] = '</optgroup>'; 925 926 // List available translations. 927 if ( ! empty( $translations ) && $args['show_available_translations'] ) { 928 $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">'; 929 foreach ( $translations as $translation ) { 930 $structure[] = sprintf( 931 '<option value="%s" lang="%s"%s>%s</option>', 932 esc_attr( $translation['language'] ), 933 esc_attr( $translation['iso'][1] ), 934 selected( $translation['language'], $args['selected'], false ), 935 esc_html( $translation['native_name'] ) 936 ); 937 } 938 $structure[] = '</optgroup>'; 939 } 940 941 echo join( "\n", $structure ); 906 942 907 943 echo '</select>';
Note: See TracChangeset
for help on using the changeset viewer.