<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[30335] trunk/src: Site Language: Install translations on the fly.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/30335">30335</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/30335","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-11-13 17:00:08 +0000 (Thu, 13 Nov 2014)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/29395">#29395</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincssformscss">trunk/src/wp-admin/css/forms.css</a></li>
<li><a href="#trunksrcwpadminnetworksettingsphp">trunk/src/wp-admin/network/settings.php</a></li>
<li><a href="#trunksrcwpadminoptionsgeneralphp">trunk/src/wp-admin/options-general.php</a></li>
<li><a href="#trunksrcwpadminoptionsphp">trunk/src/wp-admin/options.php</a></li>
<li><a href="#trunksrcwpincludesl10nphp">trunk/src/wp-includes/l10n.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincssformscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/forms.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/forms.css  2014-11-13 15:53:52 UTC (rev 30334)
+++ trunk/src/wp-admin/css/forms.css    2014-11-13 17:00:08 UTC (rev 30335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -611,9 +611,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        font-size: 13px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-table.form-table td .updated p { 
-       font-size: 13px; 
-       margin: 0.3em 0; 
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+table.form-table td .updated p {
+       font-size: 13px;
+       margin: 0.3em 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /*------------------------------------------------------------------------------
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -767,6 +767,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        margin: -3px 3px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.settings-php .language-install-spinner,
+.options-general-php .language-install-spinner {
+       display: inline-block;
+       float: none;
+       margin: -3px 5px 0;
+       vertical-align: middle;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* =Media Queries
</span><span class="cx" style="display: block; padding: 0 10px"> -------------------------------------------------------------- */
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpadminnetworksettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/network/settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/network/settings.php   2014-11-13 15:53:52 UTC (rev 30334)
+++ trunk/src/wp-admin/network/settings.php     2014-11-13 17:00:08 UTC (rev 30335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,6 +10,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /** Load WordPress Administration Bootstrap */
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( dirname( __FILE__ ) . '/admin.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/** WordPress Translation Install API */
+require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() )
</span><span class="cx" style="display: block; padding: 0 10px">        wp_die( __( 'Multisite support is not enabled.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,6 +22,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $title = __( 'Network Settings' );
</span><span class="cx" style="display: block; padding: 0 10px"> $parent_file = 'settings.php';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Display JavaScript on the page.
+ *
+ * @since 4.1.0
+*/
+function network_settings_add_js() {
+?>
+<script type="text/javascript">
+jQuery(document).ready( function($) {
+       var languageSelect = $( '#WPLANG' );
+       $( 'form' ).submit( function() {
+               // Don't show a spinner for English and installed languages,
+               // as there is nothing to download.
+               if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
+                       $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
+               }
+       });
+});
+</script>
+<?php
+}
+add_action( 'admin_head', 'network_settings_add_js' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> get_current_screen()->add_help_tab( array(
</span><span class="cx" style="display: block; padding: 0 10px">                'id'      => 'overview',
</span><span class="cx" style="display: block; padding: 0 10px">                'title'   => __('Overview'),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,6 +84,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'illegal_names', 'limited_email_domains', 'banned_email_domains', 'WPLANG', 'admin_email',
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Handle translation install.
+       if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) {  // @todo: Skip if already installed
+               $language = wp_download_language_pack( $_POST['WPLANG'] );
+               if ( $language ) {
+                       $_POST['WPLANG'] = $language;
+               }
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         foreach ( $options as $option_name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! isset($_POST[$option_name]) )
</span><span class="cx" style="display: block; padding: 0 10px">                        continue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -275,7 +309,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <?php
</span><span class="cx" style="display: block; padding: 0 10px">                $languages = get_available_languages();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $languages ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $translations = wp_get_available_translations();
+               if ( ! empty( $languages ) || ! empty( $translations ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <h3><?php _e( 'Language Settings' ); ?></h3>
</span><span class="cx" style="display: block; padding: 0 10px">                        <table class="form-table">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -289,10 +324,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                                wp_dropdown_languages( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        'name'      => 'WPLANG',
-                                                       'id'        => 'WPLANG',
-                                                       'selected'  => $lang,
-                                                       'languages' => $languages,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 'name'         => 'WPLANG',
+                                                       'id'           => 'WPLANG',
+                                                       'selected'     => $lang,
+                                                       'languages'    => $languages,
+                                                       'translations' => $translations,
+                                                       'show_available_translations' => wp_can_install_language_pack(),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                                                ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </td>
</span></span></pre></div>
<a id="trunksrcwpadminoptionsgeneralphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/options-general.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/options-general.php    2014-11-13 15:53:52 UTC (rev 30334)
+++ trunk/src/wp-admin/options-general.php      2014-11-13 17:00:08 UTC (rev 30335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,6 +9,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /** WordPress Administration Bootstrap */
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( dirname( __FILE__ ) . '/admin.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/** WordPress Translation Install API */
+require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! current_user_can( 'manage_options' ) )
</span><span class="cx" style="display: block; padding: 0 10px">        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -63,6 +66,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        date : format.val()
</span><span class="cx" style="display: block; padding: 0 10px">                                }, function(d) { format.siblings('.spinner').hide(); format.siblings('.example').text(d); } );
</span><span class="cx" style="display: block; padding: 0 10px">                });
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               var languageSelect = $( '#WPLANG' );
+               $( 'form' ).submit( function() {
+                       // Don't show a spinner for English and installed languages,
+                       // as there is nothing to download.
+                       if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
+                               $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
+                       }
+               });
</ins><span class="cx" style="display: block; padding: 0 10px">         });
</span><span class="cx" style="display: block; padding: 0 10px"> //]]>
</span><span class="cx" style="display: block; padding: 0 10px"> </script>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,10 +330,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> $languages = get_available_languages();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$translations = wp_get_available_translations();
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG && ! in_array( WPLANG, $languages ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">        $languages[] = WPLANG;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( $languages ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! empty( $languages ) || ! empty( $translations ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         ?>
</span><span class="cx" style="display: block; padding: 0 10px">        <tr>
</span><span class="cx" style="display: block; padding: 0 10px">                <th width="33%" scope="row"><label for="WPLANG"><?php _e( 'Site Language' ); ?></label></th>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -333,10 +346,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        wp_dropdown_languages( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'name'      => 'WPLANG',
-                               'id'        => 'WPLANG',
-                               'selected'  => $locale,
-                               'languages' => $languages,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'name'         => 'WPLANG',
+                               'id'           => 'WPLANG',
+                               'selected'     => $locale,
+                               'languages'    => $languages,
+                               'translations' => $translations,
+                               'show_available_translations' => ( ! is_multisite() || is_super_admin() ) && wp_can_install_language_pack(),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Add note about deprecated WPLANG constant.
</span></span></pre></div>
<a id="trunksrcwpadminoptionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/options.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/options.php    2014-11-13 15:53:52 UTC (rev 30334)
+++ trunk/src/wp-admin/options.php      2014-11-13 17:00:08 UTC (rev 30335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,8 +151,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $options = $whitelist_options[ $option_page ];
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Handle custom date/time formats.
</del><span class="cx" style="display: block; padding: 0 10px">         if ( 'general' == $option_page ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Handle custom date/time formats.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
</span><span class="cx" style="display: block; padding: 0 10px">                        $_POST['date_format'] = $_POST['date_format_custom'];
</span><span class="cx" style="display: block; padding: 0 10px">                if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,6 +163,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
</span><span class="cx" style="display: block; padding: 0 10px">                        $_POST['timezone_string'] = '';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Handle translation install.
+               if ( ! empty( $_POST['WPLANG'] ) && ( ! is_multisite() || is_super_admin() ) ) { // @todo: Skip if already installed
+                       require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
+
+                       if ( wp_can_install_language_pack() ) {
+                               $language = wp_download_language_pack( $_POST['WPLANG'] );
+                               if ( $language ) {
+                                       $_POST['WPLANG'] = $language;
+                               }
+                       }
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( $options ) {
</span></span></pre></div>
<a id="trunksrcwpincludesl10nphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/l10n.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/l10n.php    2014-11-13 15:53:52 UTC (rev 30334)
+++ trunk/src/wp-includes/l10n.php      2014-11-13 17:00:08 UTC (rev 30335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -849,24 +849,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @see get_available_languages()
</span><span class="cx" style="display: block; padding: 0 10px">  * @see wp_get_available_translations()
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $args Optional arguments. Default empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string|array $query {
+ *     Optional. Array of arguments.
+ *
+ *     @type string  $id                           ID attribute of the select element. Default empty.
+ *     @type string  $name                         Name attribute of the select element. Default empty.
+ *     @type array   $languages                    List of installed languages, contain only the locales.
+ *                                                 Default empty array.
+ *     @type array   $translations                 List of available translations. Default result of
+ *                                                 {@see wp_get_available_translations()}.
+ *     @type string  $selected                     Language which should be selected. Default empty.
+ *     @type bool    $show_available_translations  Whether to show available translations. Default true.
+ * }
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_dropdown_languages( $args = array() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $args = wp_parse_args( $args, array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'id'        => '',
-               'name'      => '',
-               'languages' => array(),
-               'selected'  => ''
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         'id'           => '',
+               'name'         => '',
+               'languages'    => array(),
+               'translations' => array(),
+               'selected'     => '',
+               'show_available_translations' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">         ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( empty( $args['languages'] ) ) {
-               return false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $translations = $args['translations'];
+       if ( empty( $translations ) ) {
+               require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
+               $translations = wp_get_available_translations();
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $translations = wp_get_available_translations();
-
</del><span class="cx" style="display: block; padding: 0 10px">         /*
</span><span class="cx" style="display: block; padding: 0 10px">         * $args['languages'] should only contain the locales. Find the locale in
</span><span class="cx" style="display: block; padding: 0 10px">         * $translations to get the native name. Fall back to locale.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -880,6 +892,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'native_name' => $translation['native_name'],
</span><span class="cx" style="display: block; padding: 0 10px">                                'lang'        => $translation['iso'][1],
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // Remove installed language from available translations.
+                       unset( $translations[ $locale ] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $languages[] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'language'    => $locale,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -891,18 +906,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Holds the HTML markup.
+       $structure = array();
+
</ins><span class="cx" style="display: block; padding: 0 10px">         // List installed languages.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        echo '<option value="" lang="en">English (United States)</option>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
+       $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
</ins><span class="cx" style="display: block; padding: 0 10px">         foreach ( $languages as $language ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $selected = selected( $language['language'], $args['selected'], false );
-               printf(
-                       '<option value="%s" lang="%s"%s>%s</option>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $structure[] = sprintf(
+                       '<option value="%s" lang="%s"%s data-installed="1">%s</option>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         esc_attr( $language['language'] ),
</span><span class="cx" style="display: block; padding: 0 10px">                        esc_attr( $language['lang'] ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $selected,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 selected( $language['language'], $args['selected'], false ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         esc_html( $language['native_name'] )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $structure[] = '</optgroup>';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // List available translations.
+       if ( ! empty( $translations ) && $args['show_available_translations'] ) {
+               $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">';
+               foreach ( $translations as $translation ) {
+                       $structure[] = sprintf(
+                               '<option value="%s" lang="%s"%s>%s</option>',
+                               esc_attr( $translation['language'] ),
+                               esc_attr( $translation['iso'][1] ),
+                               selected( $translation['language'], $args['selected'], false ),
+                               esc_html( $translation['native_name'] )
+                       );
+               }
+               $structure[] = '</optgroup>';
+       }
+
+       echo join( "\n", $structure );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         echo '</select>';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>