diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
index c5e460a..db286fd 100644
|
|
|
|
| 1116 | 1116 | * @param string|array $args { |
| 1117 | 1117 | * Optional. Array or string of arguments for outputting the language selector. |
| 1118 | 1118 | * |
| 1119 | | * @type string $id ID attribute of the select element. Default empty. |
| 1120 | | * @type string $name Name attribute of the select element. Default empty. |
| | 1119 | * @type string $id ID attribute of the select element. Default 'locale'. |
| | 1120 | * @type string $name Name attribute of the select element. Default 'locale'. |
| 1121 | 1121 | * @type array $languages List of installed languages, contain only the locales. |
| 1122 | 1122 | * Default empty array. |
| 1123 | 1123 | * @type array $translations List of available translations. Default result of |
| … |
… |
|
| 1132 | 1132 | */ |
| 1133 | 1133 | function wp_dropdown_languages( $args = array() ) { |
| 1134 | 1134 | |
| 1135 | | $args = wp_parse_args( $args, array( |
| 1136 | | 'id' => '', |
| 1137 | | 'name' => '', |
| | 1135 | $r = wp_parse_args( $args, array( |
| | 1136 | 'id' => 'locale', |
| | 1137 | 'name' => 'locale', |
| 1138 | 1138 | 'languages' => array(), |
| 1139 | 1139 | 'translations' => array(), |
| 1140 | 1140 | 'selected' => '', |
| … |
… |
|
| 1143 | 1143 | 'show_option_site_default' => false, |
| 1144 | 1144 | ) ); |
| 1145 | 1145 | |
| 1146 | | // English (United States) uses an empty string for the value attribute. |
| 1147 | | if ( 'en_US' === $args['selected'] ) { |
| 1148 | | $args['selected'] = ''; |
| | 1146 | // Bail if no ID or no name. |
| | 1147 | if ( empty( $r['id'] ) || empty( $r['name'] ) ) { |
| | 1148 | return; |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | | $translations = $args['translations']; |
| | 1151 | // English (United States) uses an empty string for the value attribute. |
| | 1152 | if ( 'en_US' === $r['selected'] ) { |
| | 1153 | $r['selected'] = ''; |
| | 1154 | } |
| | 1155 | |
| | 1156 | $translations = $r['translations']; |
| 1152 | 1157 | if ( empty( $translations ) ) { |
| 1153 | 1158 | require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
| 1154 | 1159 | $translations = wp_get_available_translations(); |
| 1155 | 1160 | } |
| 1156 | 1161 | |
| 1157 | 1162 | /* |
| 1158 | | * $args['languages'] should only contain the locales. Find the locale in |
| | 1163 | * $r['languages'] should only contain the locales. Find the locale in |
| 1159 | 1164 | * $translations to get the native name. Fall back to locale. |
| 1160 | 1165 | */ |
| 1161 | 1166 | $languages = array(); |
| 1162 | | foreach ( $args['languages'] as $locale ) { |
| | 1167 | foreach ( $r['languages'] as $locale ) { |
| 1163 | 1168 | if ( isset( $translations[ $locale ] ) ) { |
| 1164 | 1169 | $translation = $translations[ $locale ]; |
| 1165 | 1170 | $languages[] = array( |
| … |
… |
|
| 1179 | 1184 | } |
| 1180 | 1185 | } |
| 1181 | 1186 | |
| 1182 | | $translations_available = ( ! empty( $translations ) && $args['show_available_translations'] ); |
| 1183 | | |
| 1184 | | $output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) ); |
| | 1187 | $translations_available = ( ! empty( $translations ) && $r['show_available_translations'] ); |
| 1185 | 1188 | |
| 1186 | 1189 | // Holds the HTML markup. |
| 1187 | 1190 | $structure = array(); |
| … |
… |
|
| 1191 | 1194 | $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; |
| 1192 | 1195 | } |
| 1193 | 1196 | |
| 1194 | | if ( $args['show_option_site_default'] ) { |
| | 1197 | // Site default. |
| | 1198 | if ( $r['show_option_site_default'] ) { |
| 1195 | 1199 | $structure[] = sprintf( |
| 1196 | 1200 | '<option value="site-default" data-installed="1"%s>%s</option>', |
| 1197 | | selected( 'site-default', $args['selected'], false ), |
| | 1201 | selected( 'site-default', $r['selected'], false ), |
| 1198 | 1202 | _x( 'Site Default', 'default site language' ) |
| 1199 | 1203 | ); |
| 1200 | 1204 | } |
| 1201 | 1205 | |
| | 1206 | // Always show English. |
| 1202 | 1207 | $structure[] = sprintf( |
| 1203 | 1208 | '<option value="" lang="en" data-installed="1"%s>English (United States)</option>', |
| 1204 | | selected( '', $args['selected'], false ) |
| | 1209 | selected( '', $r['selected'], false ) |
| 1205 | 1210 | ); |
| 1206 | 1211 | |
| | 1212 | // List installed languages. |
| 1207 | 1213 | foreach ( $languages as $language ) { |
| 1208 | 1214 | $structure[] = sprintf( |
| 1209 | 1215 | '<option value="%s" lang="%s"%s data-installed="1">%s</option>', |
| 1210 | 1216 | esc_attr( $language['language'] ), |
| 1211 | 1217 | esc_attr( $language['lang'] ), |
| 1212 | | selected( $language['language'], $args['selected'], false ), |
| | 1218 | selected( $language['language'], $r['selected'], false ), |
| 1213 | 1219 | esc_html( $language['native_name'] ) |
| 1214 | 1220 | ); |
| 1215 | 1221 | } |
| | 1222 | |
| 1216 | 1223 | if ( $translations_available ) { |
| 1217 | 1224 | $structure[] = '</optgroup>'; |
| 1218 | | } |
| 1219 | 1225 | |
| 1220 | | // List available translations. |
| 1221 | | if ( $translations_available ) { |
| | 1226 | // List available translations. |
| 1222 | 1227 | $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">'; |
| 1223 | 1228 | foreach ( $translations as $translation ) { |
| 1224 | 1229 | $structure[] = sprintf( |
| 1225 | 1230 | '<option value="%s" lang="%s"%s>%s</option>', |
| 1226 | 1231 | esc_attr( $translation['language'] ), |
| 1227 | 1232 | esc_attr( current( $translation['iso'] ) ), |
| 1228 | | selected( $translation['language'], $args['selected'], false ), |
| | 1233 | selected( $translation['language'], $r['selected'], false ), |
| 1229 | 1234 | esc_html( $translation['native_name'] ) |
| 1230 | 1235 | ); |
| 1231 | 1236 | } |
| 1232 | 1237 | $structure[] = '</optgroup>'; |
| 1233 | 1238 | } |
| 1234 | 1239 | |
| | 1240 | // Combine the output string. |
| | 1241 | $output = sprintf( '<select name="%s" id="%s">', esc_attr( $r['name'] ), esc_attr( $r['id'] ) ); |
| 1235 | 1242 | $output .= join( "\n", $structure ); |
| 1236 | | |
| 1237 | 1243 | $output .= '</select>'; |
| 1238 | 1244 | |
| 1239 | | if ( $args['echo'] ) { |
| | 1245 | if ( $r['echo'] ) { |
| 1240 | 1246 | echo $output; |
| 1241 | 1247 | } |
| 1242 | 1248 | |