Make WordPress Core


Ignore:
Timestamp:
11/13/2014 05:00:08 PM (10 years ago)
Author:
ocean90
Message:

Site Language: Install translations on the fly.

The language dropdown now includes installed languages and all available translations when the filesystem is writable by WordPress.
Go to wp-admin/options-general.php, select one of the available translations, submit the form and let WordPress handle the rest.
Works for Multisite's Default Language too.

see #29395.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-general.php

    r29963 r30335  
    99/** WordPress Administration Bootstrap */
    1010require_once( dirname( __FILE__ ) . '/admin.php' );
     11
     12/** WordPress Translation Install API */
     13require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    1114
    1215if ( ! current_user_can( 'manage_options' ) )
     
    6366                    date : format.val()
    6467                }, function(d) { format.siblings('.spinner').hide(); format.siblings('.example').text(d); } );
     68        });
     69
     70        var languageSelect = $( '#WPLANG' );
     71        $( 'form' ).submit( function() {
     72            // Don't show a spinner for English and installed languages,
     73            // as there is nothing to download.
     74            if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
     75                $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
     76            }
    6577        });
    6678    });
     
    319331<?php
    320332$languages = get_available_languages();
     333$translations = wp_get_available_translations();
    321334if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG && ! in_array( WPLANG, $languages ) ) {
    322335    $languages[] = WPLANG;
    323336}
    324 if ( $languages ) {
     337if ( ! empty( $languages ) || ! empty( $translations ) ) {
    325338    ?>
    326339    <tr>
     
    334347
    335348            wp_dropdown_languages( array(
    336                 'name'      => 'WPLANG',
    337                 'id'        => 'WPLANG',
    338                 'selected'  => $locale,
    339                 'languages' => $languages,
     349                'name'         => 'WPLANG',
     350                'id'           => 'WPLANG',
     351                'selected'     => $locale,
     352                'languages'    => $languages,
     353                'translations' => $translations,
     354                'show_available_translations' => ( ! is_multisite() || is_super_admin() ) && wp_can_install_language_pack(),
    340355            ) );
    341356
Note: See TracChangeset for help on using the changeset viewer.