Preferred Languages - Version 1.2.0

Version Description

  • Fixed: Other English locales can now be added again.
  • Fixed: Prevented some errors when adding all available locales.
Download this release

Release Info

Developer swissspidy
Plugin Icon Preferred Languages
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

css/preferred-languages-rtl.css CHANGED
@@ -1 +1 @@
1
- .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 0 1em 1em;clear:both;float:right}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (max-width:782px){.inactive-locales-controls .button{height:40px}}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);color:rgba(51,51,51,.5);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 8px 0 0;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-list-empty-message{background:transparent;text-align:center;height:auto;cursor:default}.inactive-locales{clear:both}.inactive-locales select{width:100%}
1
+ .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 0 1em 1em;clear:both;float:right}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 8px 0 0;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:-webkit-box;display:flex;-webkit-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}
css/preferred-languages.css CHANGED
@@ -1 +1 @@
1
- .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 1em 1em 0;clear:both;float:left}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (max-width:782px){.inactive-locales-controls .button{height:40px}}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);color:rgba(51,51,51,.5);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 0 0 8px;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-list-empty-message{background:transparent;text-align:center;height:auto;cursor:default}.inactive-locales{clear:both}.inactive-locales select{width:100%}
1
+ .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 1em 1em 0;clear:both;float:left}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 0 0 8px;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:-webkit-box;display:flex;-webkit-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}
inc/functions.php CHANGED
@@ -228,7 +228,7 @@ function preferred_languages_register_scripts() {
228
  'jquery-ui-sortable',
229
  'wp-a11y',
230
  ),
231
- '20171002',
232
  true
233
  );
234
 
@@ -251,7 +251,7 @@ function preferred_languages_register_scripts() {
251
  'preferred-languages',
252
  plugin_dir_url( dirname( __FILE__ ) ) . 'css/preferred-languages' . $rtl_suffix . '.css',
253
  array(),
254
- '20171006',
255
  'screen'
256
  );
257
  }
@@ -350,6 +350,26 @@ function preferred_languages_display_form( $args = array() ) {
350
  <input type="hidden" name="preferred_languages" value="<?php echo esc_attr( implode( ',', $args['selected'] ) ); ?>"/>
351
  <p><?php _e( 'Choose languages for displaying WordPress in, in order of preference.', 'preferred-languages' ); ?></p>
352
  <div class="active-locales">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  <ul
354
  role="listbox"
355
  aria-labelledby="preferred-languages-label"
@@ -366,18 +386,6 @@ function preferred_languages_display_form( $args = array() ) {
366
  <?php echo esc_html( $language['native_name'] ); ?>
367
  </li>
368
  <?php endforeach; ?>
369
- <li class="<?php echo ! empty( $preferred_languages ) ? 'hidden' : ''; ?>" id="active-locales-list-empty-message">
370
- <?php _e( 'Nothing set.', 'preferred-languages' ); ?>
371
- <br>
372
- <?php
373
- if ( true === $args['show_option_site_default'] ) {
374
- _e( 'Falling back to Site Default.', 'preferred-languages' );
375
- } else {
376
- /* translators: %s: English (United States) */
377
- printf( __( 'Falling back to %s.', 'preferred-languages' ), 'English (United States)' );
378
- }
379
- ?>
380
- </li>
381
  </ul>
382
  <div class="active-locales-controls">
383
  <ul>
228
  'jquery-ui-sortable',
229
  'wp-a11y',
230
  ),
231
+ '20171011',
232
  true
233
  );
234
 
251
  'preferred-languages',
252
  plugin_dir_url( dirname( __FILE__ ) ) . 'css/preferred-languages' . $rtl_suffix . '.css',
253
  array(),
254
+ '20171010',
255
  'screen'
256
  );
257
  }
350
  <input type="hidden" name="preferred_languages" value="<?php echo esc_attr( implode( ',', $args['selected'] ) ); ?>"/>
351
  <p><?php _e( 'Choose languages for displaying WordPress in, in order of preference.', 'preferred-languages' ); ?></p>
352
  <div class="active-locales">
353
+ <?php
354
+ if ( true === $args['show_option_site_default'] ) {
355
+ $screen_reader_text = __( 'No languages selected. Falling back to Site Default.', 'preferred-languages' );
356
+ } else {
357
+ /* translators: %s: English (United States) */
358
+ $screen_reader_text = sprintf( __( 'No languages selected. Falling back to %s.', 'preferred-languages' ), 'English (United States)' );
359
+ }
360
+ ?>
361
+ <div class="<?php echo ! empty( $preferred_languages ) ? 'hidden' : ''; ?>" id="active-locales-empty-message" data-a11y-message="<?php echo esc_attr( $screen_reader_text ); ?>">
362
+ <?php _e( 'Nothing set.', 'preferred-languages' ); ?>
363
+ <br>
364
+ <?php
365
+ if ( true === $args['show_option_site_default'] ) {
366
+ _e( 'Falling back to Site Default.', 'preferred-languages' );
367
+ } else {
368
+ /* translators: %s: English (United States) */
369
+ printf( __( 'Falling back to %s.', 'preferred-languages' ), 'English (United States)' );
370
+ }
371
+ ?>
372
+ </div>
373
  <ul
374
  role="listbox"
375
  aria-labelledby="preferred-languages-label"
386
  <?php echo esc_html( $language['native_name'] ); ?>
387
  </li>
388
  <?php endforeach; ?>
 
 
 
 
 
 
 
 
 
 
 
 
389
  </ul>
390
  <div class="active-locales-controls">
391
  <ul>
js/preferred-languages.js CHANGED
@@ -3,6 +3,7 @@
3
  (function (wp, settings, $) {
4
  var $activeLocales = $('.active-locales-list');
5
  var $activeLocalesControls = $('.active-locales-controls');
 
6
  var $inactiveLocales = $('.inactive-locales-list select');
7
  var $inactiveLocalesControls = $('.inactive-locales-controls');
8
  var $selectedLocale = $activeLocales.find('li[aria-selected="true"]');
@@ -29,10 +30,10 @@
29
  *
30
  * @since 1.0.0
31
  *
32
- * @param {jQuery} locale Locale element.
33
  */
34
- function toggleLocale(locale) {
35
- var selected = locale.attr('aria-selected');
36
  var newState = '' === selected ? true : !!selected;
37
 
38
  // It's already the current locale, so nothing to do here.
@@ -42,15 +43,15 @@
42
 
43
  $selectedLocale.attr('aria-selected', false);
44
 
45
- locale.attr('aria-selected', newState);
46
 
47
  if (true === newState) {
48
- $selectedLocale = locale;
49
 
50
  $activeLocales.attr('aria-activedescendant', $selectedLocale.attr('id'));
51
  }
52
 
53
- changeButtonState(locale);
54
  }
55
 
56
  /**
@@ -111,22 +112,19 @@
111
  /**
112
  * Displays a message in case the list of active locales is empty.
113
  *
114
- * @since 1.0.0
115
  */
116
- function showEmptyListMessage() {
117
- $activeLocales.addClass('empty-list');
118
- $activeLocales.attr('aria-activedescendant', '');
119
- $activeLocales.find('#active-locales-list-empty-message').removeClass('hidden');
120
- }
 
 
 
121
 
122
- /**
123
- * Hides the empty list of locales message.
124
- *
125
- * @since 1.0.0
126
- */
127
- function hideEmptyListMessage() {
128
- $activeLocales.removeClass('empty-list');
129
- $activeLocales.find('#active-locales-list-empty-message').addClass('hidden');
130
  }
131
 
132
  /**
@@ -134,14 +132,14 @@
134
  *
135
  * @since 1.0.0
136
  */
137
- function removeActiveLocale() {
138
  var locale = $selectedLocale.attr('id');
139
  var $successor = void 0;
140
 
141
- $successor = $selectedLocale.prevAll(':visible:first');
142
 
143
  if (0 === $successor.length) {
144
- $successor = $selectedLocale.nextAll(':visible:first');
145
  }
146
 
147
  // 1. Remove selected locale.
@@ -151,11 +149,11 @@
151
  if ($successor.length) {
152
  toggleLocale($successor);
153
  } else {
154
- showEmptyListMessage();
155
  }
156
 
157
  // 3. Make visible in dropdown again.
158
- $inactiveLocales.find('select option[value="' + locale + '"]').removeClass('hidden');
159
  $inactiveLocales.attr('disabled', false);
160
 
161
  // 4. Update hidden input field.
@@ -176,26 +174,31 @@
176
  * @param {jQuery} option The locale element.
177
  */
178
  function makeLocaleActive(option) {
179
- var $newLocale = $('<li/>', { 'id': option.val(), text: option.text(), 'aria-selected': false, 'class': 'active-locale' });
180
  var $successor = void 0;
181
 
 
 
 
182
  $successor = option.prevAll(':not(.hidden):first');
183
 
184
  if (!$successor.length) {
185
  $successor = option.nextAll(':not(.hidden):first');
186
  }
187
 
 
 
 
 
 
188
  if (!$successor.length) {
189
  $inactiveLocales.attr('disabled', true);
190
  }
191
 
192
- // 1. Change selected value in dropdown.
193
  $successor.attr('selected', true);
194
  $inactiveLocalesControls.val($successor.val());
195
 
196
- // 2. Hide from dropdown.
197
- option.removeAttr('selected').addClass('hidden');
198
-
199
  // It's already in the list of active locales, stop here.
200
  if ($activeLocales.find('#' + option.val()).length) {
201
  return;
@@ -203,7 +206,7 @@
203
 
204
  // 3. Hide empty list message if present.
205
  if ($activeLocales.hasClass('empty-list')) {
206
- hideEmptyListMessage();
207
  }
208
 
209
  // 4. Add to list.
@@ -228,7 +231,7 @@
228
  $('#WPLANG').parent().parent().remove();
229
 
230
  // Remove en_US as an option from the dropdown.
231
- $inactiveLocales.find('[lang="en"]').remove();
232
 
233
  // Change initial button state.
234
  changeButtonState($selectedLocale);
@@ -236,8 +239,16 @@
236
  // Initially hide already active locales from dropdown.
237
  if ($inputField.val().length) {
238
  $.each($inputField.val().split(','), function (index, value) {
239
- makeLocaleActive($inactiveLocales.find('[value="' + value + '"]'));
 
 
 
240
  });
 
 
 
 
 
241
  }
242
 
243
  // Enabling sorting locales using drag and drop.
@@ -274,7 +285,7 @@
274
 
275
  // Backspace.
276
  if (8 === e.which) {
277
- removeActiveLocale();
278
  e.preventDefault();
279
  }
280
  });
@@ -307,5 +318,5 @@
307
  $activeLocalesControls.find('.locales-move-down').on('click', moveLocaleDown);
308
 
309
  // Remove locale from list.
310
- $activeLocalesControls.find('.locales-remove').on('click', removeActiveLocale);
311
  })(wp, preferredLanguages, jQuery);
3
  (function (wp, settings, $) {
4
  var $activeLocales = $('.active-locales-list');
5
  var $activeLocalesControls = $('.active-locales-controls');
6
+ var $emptyMessage = $('#active-locales-empty-message');
7
  var $inactiveLocales = $('.inactive-locales-list select');
8
  var $inactiveLocalesControls = $('.inactive-locales-controls');
9
  var $selectedLocale = $activeLocales.find('li[aria-selected="true"]');
30
  *
31
  * @since 1.0.0
32
  *
33
+ * @param {jQuery} $locale Locale element.
34
  */
35
+ function toggleLocale($locale) {
36
+ var selected = $locale.attr('aria-selected');
37
  var newState = '' === selected ? true : !!selected;
38
 
39
  // It's already the current locale, so nothing to do here.
43
 
44
  $selectedLocale.attr('aria-selected', false);
45
 
46
+ $locale.attr('aria-selected', newState);
47
 
48
  if (true === newState) {
49
+ $selectedLocale = $locale;
50
 
51
  $activeLocales.attr('aria-activedescendant', $selectedLocale.attr('id'));
52
  }
53
 
54
+ changeButtonState($locale);
55
  }
56
 
57
  /**
112
  /**
113
  * Displays a message in case the list of active locales is empty.
114
  *
115
+ * @since 1.1.1
116
  */
117
+ function toggleEmptyListMessage() {
118
+ if ($activeLocales.hasClass('empty-list')) {
119
+ $activeLocales.removeClass('empty-list');
120
+ $emptyMessage.addClass('hidden');
121
+ } else {
122
+ $activeLocales.addClass('empty-list');
123
+ $activeLocales.attr('aria-activedescendant', '');
124
+ $emptyMessage.removeClass('hidden');
125
 
126
+ wp.a11y.speak($emptyMessage.data('a11y-message'));
127
+ }
 
 
 
 
 
 
128
  }
129
 
130
  /**
132
  *
133
  * @since 1.0.0
134
  */
135
+ function makeLocaleInactive() {
136
  var locale = $selectedLocale.attr('id');
137
  var $successor = void 0;
138
 
139
+ $successor = $selectedLocale.prevAll(':first');
140
 
141
  if (0 === $successor.length) {
142
+ $successor = $selectedLocale.nextAll(':first');
143
  }
144
 
145
  // 1. Remove selected locale.
149
  if ($successor.length) {
150
  toggleLocale($successor);
151
  } else {
152
+ toggleEmptyListMessage();
153
  }
154
 
155
  // 3. Make visible in dropdown again.
156
+ $inactiveLocales.find('option[value="' + locale + '"]').removeClass('hidden');
157
  $inactiveLocales.attr('disabled', false);
158
 
159
  // 4. Update hidden input field.
174
  * @param {jQuery} option The locale element.
175
  */
176
  function makeLocaleActive(option) {
177
+ var $newLocale = $('<li/>', { text: option.text(), 'role': 'option', 'aria-selected': false, 'id': option.val(), 'class': 'active-locale' });
178
  var $successor = void 0;
179
 
180
+ // 1. Hide from dropdown.
181
+ option.removeAttr('selected').addClass('hidden');
182
+
183
  $successor = option.prevAll(':not(.hidden):first');
184
 
185
  if (!$successor.length) {
186
  $successor = option.nextAll(':not(.hidden):first');
187
  }
188
 
189
+ // Empty optgroup, just select the first option we can find.
190
+ if (!$successor.length) {
191
+ $successor = $inactiveLocales.find('option:not(.hidden):first');
192
+ }
193
+
194
  if (!$successor.length) {
195
  $inactiveLocales.attr('disabled', true);
196
  }
197
 
198
+ // 2. Change selected value in dropdown.
199
  $successor.attr('selected', true);
200
  $inactiveLocalesControls.val($successor.val());
201
 
 
 
 
202
  // It's already in the list of active locales, stop here.
203
  if ($activeLocales.find('#' + option.val()).length) {
204
  return;
206
 
207
  // 3. Hide empty list message if present.
208
  if ($activeLocales.hasClass('empty-list')) {
209
+ toggleEmptyListMessage();
210
  }
211
 
212
  // 4. Add to list.
231
  $('#WPLANG').parent().parent().remove();
232
 
233
  // Remove en_US as an option from the dropdown.
234
+ $inactiveLocales.find('[lang="en"][value=""]').remove();
235
 
236
  // Change initial button state.
237
  changeButtonState($selectedLocale);
239
  // Initially hide already active locales from dropdown.
240
  if ($inputField.val().length) {
241
  $.each($inputField.val().split(','), function (index, value) {
242
+ var $option = $inactiveLocales.find('[value="' + value + '"]');
243
+
244
+ // 2. Hide from dropdown.
245
+ $option.removeAttr('selected').addClass('hidden');
246
  });
247
+
248
+ var $firstInactiveLocale = $inactiveLocales.find('option:not(.hidden):first');
249
+
250
+ $firstInactiveLocale.attr('selected', true);
251
+ $inactiveLocalesControls.val($firstInactiveLocale.val());
252
  }
253
 
254
  // Enabling sorting locales using drag and drop.
285
 
286
  // Backspace.
287
  if (8 === e.which) {
288
+ makeLocaleInactive();
289
  e.preventDefault();
290
  }
291
  });
318
  $activeLocalesControls.find('.locales-move-down').on('click', moveLocaleDown);
319
 
320
  // Remove locale from list.
321
+ $activeLocalesControls.find('.locales-remove').on('click', makeLocaleInactive);
322
  })(wp, preferredLanguages, jQuery);
js/preferred-languages.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";(function(wp,settings,$){var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $inactiveLocales=$(".inactive-locales-list select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var $inputField=$('input[name="preferred_languages"]');function changeButtonState(activeLocale){var activeLocalesList=$activeLocales.find(".active-locale");$activeLocalesControls.find(".locales-move-up").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.first().is(activeLocale));$activeLocalesControls.find(".locales-move-down").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.last().is(activeLocale));$activeLocalesControls.find(".locales-remove").attr("disabled",$activeLocales.hasClass("empty-list")||!$selectedLocale.length);$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale(locale){var selected=locale.attr("aria-selected");var newState=""===selected?true:!!selected;if(true===selected){return}$selectedLocale.attr("aria-selected",false);locale.attr("aria-selected",newState);if(true===newState){$selectedLocale=locale;$activeLocales.attr("aria-activedescendant",$selectedLocale.attr("id"))}changeButtonState(locale)}function updateHiddenInput(){var locales=[];$activeLocales.children(".active-locale").each(function(index,el){locales.push($(el).attr("id"))});$inputField.val(locales.join(","))}function moveLocaleUp(){$selectedLocale.insertBefore($selectedLocale.prev());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedUp)}function moveLocaleDown(){$selectedLocale.insertAfter($selectedLocale.next());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedDown)}function showEmptyListMessage(){$activeLocales.addClass("empty-list");$activeLocales.attr("aria-activedescendant","");$activeLocales.find("#active-locales-list-empty-message").removeClass("hidden")}function hideEmptyListMessage(){$activeLocales.removeClass("empty-list");$activeLocales.find("#active-locales-list-empty-message").addClass("hidden")}function removeActiveLocale(){var locale=$selectedLocale.attr("id");var $successor=void 0;$successor=$selectedLocale.prevAll(":visible:first");if(0===$successor.length){$successor=$selectedLocale.nextAll(":visible:first")}$selectedLocale.remove();if($successor.length){toggleLocale($successor)}else{showEmptyListMessage()}$inactiveLocales.find('select option[value="'+locale+'"]').removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var $newLocale=$("<li/>",{id:option.val(),text:option.text(),"aria-selected":false,class:"active-locale"});var $successor=void 0;$successor=option.prevAll(":not(.hidden):first");if(!$successor.length){$successor=option.nextAll(":not(.hidden):first")}if(!$successor.length){$inactiveLocales.attr("disabled",true)}$successor.attr("selected",true);$inactiveLocalesControls.val($successor.val());option.removeAttr("selected").addClass("hidden");if($activeLocales.find("#"+option.val()).length){return}if($activeLocales.hasClass("empty-list")){hideEmptyListMessage()}$activeLocales.append($newLocale);toggleLocale($newLocale);$activeLocales.animate({scrollTop:$newLocale.offset().top-$activeLocales.offset().top+$activeLocales.scrollTop()});updateHiddenInput();wp.a11y.speak(settings.l10n.localeAdded)}$(".user-language-wrap").remove();$("#WPLANG").parent().parent().remove();$inactiveLocales.find('[lang="en"]').remove();changeButtonState($selectedLocale);if($inputField.val().length){$.each($inputField.val().split(","),function(index,value){makeLocaleActive($inactiveLocales.find('[value="'+value+'"]'))})}$activeLocales.sortable({axis:"y",cursor:"move",items:":not(#active-locales-list-empty-message)"});$activeLocales.on("keydown",function(e){if(38===e.which){if(e.altKey){moveLocaleUp()}else{$selectedLocale.prev().length&&toggleLocale($selectedLocale.prev())}e.preventDefault()}if(40===e.which){if(e.altKey){moveLocaleDown()}else{$selectedLocale.next().length&&toggleLocale($selectedLocale.next())}e.preventDefault()}if(8===e.which){removeActiveLocale();e.preventDefault()}});$inactiveLocales.on("keydown",function(e){if(65===e.which){if(e.altKey){makeLocaleActive($inactiveLocales.find("option:selected"))}e.preventDefault()}});$inactiveLocalesControls.find(".locales-add").on("click",function(){makeLocaleActive($inactiveLocales.find("option:selected"))});$activeLocales.on("click",".active-locale",function(e){toggleLocale($(e.currentTarget))});$activeLocalesControls.find(".locales-move-up").on("click",moveLocaleUp);$activeLocalesControls.find(".locales-move-down").on("click",moveLocaleDown);$activeLocalesControls.find(".locales-remove").on("click",removeActiveLocale)})(wp,preferredLanguages,jQuery);
1
+ "use strict";(function(wp,settings,$){var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $emptyMessage=$("#active-locales-empty-message");var $inactiveLocales=$(".inactive-locales-list select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var $inputField=$('input[name="preferred_languages"]');function changeButtonState(activeLocale){var activeLocalesList=$activeLocales.find(".active-locale");$activeLocalesControls.find(".locales-move-up").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.first().is(activeLocale));$activeLocalesControls.find(".locales-move-down").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.last().is(activeLocale));$activeLocalesControls.find(".locales-remove").attr("disabled",$activeLocales.hasClass("empty-list")||!$selectedLocale.length);$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale($locale){var selected=$locale.attr("aria-selected");var newState=""===selected?true:!!selected;if(true===selected){return}$selectedLocale.attr("aria-selected",false);$locale.attr("aria-selected",newState);if(true===newState){$selectedLocale=$locale;$activeLocales.attr("aria-activedescendant",$selectedLocale.attr("id"))}changeButtonState($locale)}function updateHiddenInput(){var locales=[];$activeLocales.children(".active-locale").each(function(index,el){locales.push($(el).attr("id"))});$inputField.val(locales.join(","))}function moveLocaleUp(){$selectedLocale.insertBefore($selectedLocale.prev());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedUp)}function moveLocaleDown(){$selectedLocale.insertAfter($selectedLocale.next());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedDown)}function toggleEmptyListMessage(){if($activeLocales.hasClass("empty-list")){$activeLocales.removeClass("empty-list");$emptyMessage.addClass("hidden")}else{$activeLocales.addClass("empty-list");$activeLocales.attr("aria-activedescendant","");$emptyMessage.removeClass("hidden");wp.a11y.speak($emptyMessage.data("a11y-message"))}}function makeLocaleInactive(){var locale=$selectedLocale.attr("id");var $successor=void 0;$successor=$selectedLocale.prevAll(":first");if(0===$successor.length){$successor=$selectedLocale.nextAll(":first")}$selectedLocale.remove();if($successor.length){toggleLocale($successor)}else{toggleEmptyListMessage()}$inactiveLocales.find('option[value="'+locale+'"]').removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var $newLocale=$("<li/>",{text:option.text(),role:"option","aria-selected":false,id:option.val(),class:"active-locale"});var $successor=void 0;option.removeAttr("selected").addClass("hidden");$successor=option.prevAll(":not(.hidden):first");if(!$successor.length){$successor=option.nextAll(":not(.hidden):first")}if(!$successor.length){$successor=$inactiveLocales.find("option:not(.hidden):first")}if(!$successor.length){$inactiveLocales.attr("disabled",true)}$successor.attr("selected",true);$inactiveLocalesControls.val($successor.val());if($activeLocales.find("#"+option.val()).length){return}if($activeLocales.hasClass("empty-list")){toggleEmptyListMessage()}$activeLocales.append($newLocale);toggleLocale($newLocale);$activeLocales.animate({scrollTop:$newLocale.offset().top-$activeLocales.offset().top+$activeLocales.scrollTop()});updateHiddenInput();wp.a11y.speak(settings.l10n.localeAdded)}$(".user-language-wrap").remove();$("#WPLANG").parent().parent().remove();$inactiveLocales.find('[lang="en"][value=""]').remove();changeButtonState($selectedLocale);if($inputField.val().length){$.each($inputField.val().split(","),function(index,value){var $option=$inactiveLocales.find('[value="'+value+'"]');$option.removeAttr("selected").addClass("hidden")});var $firstInactiveLocale=$inactiveLocales.find("option:not(.hidden):first");$firstInactiveLocale.attr("selected",true);$inactiveLocalesControls.val($firstInactiveLocale.val())}$activeLocales.sortable({axis:"y",cursor:"move",items:":not(#active-locales-list-empty-message)"});$activeLocales.on("keydown",function(e){if(38===e.which){if(e.altKey){moveLocaleUp()}else{$selectedLocale.prev().length&&toggleLocale($selectedLocale.prev())}e.preventDefault()}if(40===e.which){if(e.altKey){moveLocaleDown()}else{$selectedLocale.next().length&&toggleLocale($selectedLocale.next())}e.preventDefault()}if(8===e.which){makeLocaleInactive();e.preventDefault()}});$inactiveLocales.on("keydown",function(e){if(65===e.which){if(e.altKey){makeLocaleActive($inactiveLocales.find("option:selected"))}e.preventDefault()}});$inactiveLocalesControls.find(".locales-add").on("click",function(){makeLocaleActive($inactiveLocales.find("option:selected"))});$activeLocales.on("click",".active-locale",function(e){toggleLocale($(e.currentTarget))});$activeLocalesControls.find(".locales-move-up").on("click",moveLocaleUp);$activeLocalesControls.find(".locales-move-down").on("click",moveLocaleDown);$activeLocalesControls.find(".locales-remove").on("click",makeLocaleInactive)})(wp,preferredLanguages,jQuery);
preferred-languages.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Preferred Languages
4
  * Plugin URI: https://github.com/swissspidy/preferred-languages/
5
  * Description: Choose languages for displaying WordPress in, in order of preference.
6
- * Version: 1.1.0
7
  * Author: Pascal Birchler
8
  * Author URI: https://pascalbirchler.com
9
  * License: GPL-2.0+
3
  * Plugin Name: Preferred Languages
4
  * Plugin URI: https://github.com/swissspidy/preferred-languages/
5
  * Description: Choose languages for displaying WordPress in, in order of preference.
6
+ * Version: 1.2.0
7
  * Author: Pascal Birchler
8
  * Author URI: https://pascalbirchler.com
9
  * License: GPL-2.0+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: internationalization, i18n, localization, l10n, language, locale, translat
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
- Stable tag: 1.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -16,6 +16,14 @@ Thanks to language packs it's easier than ever before to change the main languag
16
 
17
  This feature project aims to change that by letting users choose multiple languages for displaying WordPress in. That way you can set some sort of "fallback chain" where WordPress tries to load translations in your preferred order.
18
 
 
 
 
 
 
 
 
 
19
  == Screenshots ==
20
 
21
  1. The new language section in 'Settings' -> 'General'
@@ -23,6 +31,11 @@ This feature project aims to change that by letting users choose multiple langua
23
 
24
  == Changelog ==
25
 
 
 
 
 
 
26
  = 1.1.0 =
27
 
28
  * New: Support for just-in-time loading of translations.
@@ -41,6 +54,10 @@ This feature project aims to change that by letting users choose multiple langua
41
 
42
  == Upgrade Notice ==
43
 
 
 
 
 
44
  = 1.1.0 =
45
 
46
  This release includes some accessibility and usability improvements, as well as support for just-in-time loading of translations.
4
  Requires at least: 4.7
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
+ Stable tag: 1.2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
16
 
17
  This feature project aims to change that by letting users choose multiple languages for displaying WordPress in. That way you can set some sort of "fallback chain" where WordPress tries to load translations in your preferred order.
18
 
19
+ Please help us test this plugin and let us know if something is not working as you think it should.
20
+
21
+ = Get Involved =
22
+
23
+ Active development is taking place on [GitHub](https://github.com/swissspidy/preferred-languages).
24
+
25
+ If you want to get involved, check out [open issues](https://github.com/swissspidy/preferred-languages/issues) and join the [#core-i18n](https://wordpress.slack.com/messages/core-i18n) channel on [Slack](https://wordpress.slack.com/). If you don't have a Slack account yet, you can sign up at [make.wordpress.org/chat/](https://make.wordpress.org/chat/).
26
+
27
  == Screenshots ==
28
 
29
  1. The new language section in 'Settings' -> 'General'
31
 
32
  == Changelog ==
33
 
34
+ = 1.2.0 =
35
+
36
+ * Fixed: Other English locales can now be added again.
37
+ * Fixed: Prevented some errors when adding all available locales.
38
+
39
  = 1.1.0 =
40
 
41
  * New: Support for just-in-time loading of translations.
54
 
55
  == Upgrade Notice ==
56
 
57
+ = 1.2.0 =
58
+
59
+ This release fixes various bugs when adding and removing multiple languages.
60
+
61
  = 1.1.0 =
62
 
63
  This release includes some accessibility and usability improvements, as well as support for just-in-time loading of translations.