Version Description
This release adds full support for WordPress 5.0. Block editor support requires WordPress 5.0.3.
Download this release
Release Info
Developer | swissspidy |
Plugin | Preferred Languages |
Version | 1.6.0 |
Comparing to | |
See all releases |
Code changes from version 1.5.0 to 1.6.0
- CHANGELOG.md +5 -0
- css/preferred-languages-rtl.css +1 -1
- css/preferred-languages.css +1 -1
- inc/default-filters.php +2 -1
- inc/functions.php +41 -2
- js/preferred-languages.js +10 -4
- js/preferred-languages.min.js +1 -1
- preferred-languages.php +1 -1
- readme.txt +5 -41
CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
# Changelog
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
## 1.5.0
|
4 |
|
5 |
* Enhancement: Improved compatibility with multilingual plugins like Polylang.
|
1 |
# Changelog
|
2 |
|
3 |
+
## 1.6.0
|
4 |
+
|
5 |
+
* Enhancement: Added support for JavaScript internationalization as used in the new block editor in WordPress 5.0. Requires WordPress 5.0.3.
|
6 |
+
* Fixed: Fixes an issue where the preferred languages list wasn't updating after sorting via drag & drop.
|
7 |
+
|
8 |
## 1.5.0
|
9 |
|
10 |
* Enhancement: Improved compatibility with multilingual plugins like Polylang.
|
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 (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.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;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:flex;justify-content:center;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%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;left:50%;bottom:auto;margin-left:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;left:auto;right:50%;margin-right:-16px;bottom:100%;margin-bottom:6px}
|
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.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;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:flex;justify-content:center;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%}.preferred-languages .notice{display:inline-block}.js #WPLANG,.js .user-language-wrap,.js label[for=WPLANG],.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;left:50%;bottom:auto;margin-left:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;left:auto;right:50%;margin-right:-16px;bottom:100%;margin-bottom:6px}
|
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 (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.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;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:flex;justify-content:center;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%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;right:50%;bottom:auto;margin-right:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;right:auto;left:50%;margin-left:-16px;bottom:100%;margin-bottom:6px}
|
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.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;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:flex;justify-content:center;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%}.preferred-languages .notice{display:inline-block}.js #WPLANG,.js .user-language-wrap,.js label[for=WPLANG],.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;right:50%;bottom:auto;margin-right:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;right:auto;left:50%;margin-left:-16px;bottom:100%;margin-bottom:6px}
|
inc/default-filters.php
CHANGED
@@ -27,4 +27,5 @@ add_filter( 'update_user_metadata', 'preferred_languages_pre_update_user_meta',
|
|
27 |
add_filter( 'update_user_meta', 'preferred_languages_update_user_meta', 10, 4 );
|
28 |
add_filter( 'get_user_metadata', 'preferred_languages_filter_user_locale', 10, 3 );
|
29 |
add_filter( 'locale', 'preferred_languages_filter_locale', 5 ); // Before WP_Locale_Switcher.
|
30 |
-
add_filter( 'load_textdomain_mofile', 'preferred_languages_load_textdomain_mofile'
|
|
27 |
add_filter( 'update_user_meta', 'preferred_languages_update_user_meta', 10, 4 );
|
28 |
add_filter( 'get_user_metadata', 'preferred_languages_filter_user_locale', 10, 3 );
|
29 |
add_filter( 'locale', 'preferred_languages_filter_locale', 5 ); // Before WP_Locale_Switcher.
|
30 |
+
add_filter( 'load_textdomain_mofile', 'preferred_languages_load_textdomain_mofile' );
|
31 |
+
add_filter( 'load_script_translation_file', 'preferred_languages_load_script_translation_file' );
|
inc/functions.php
CHANGED
@@ -350,6 +350,44 @@ function preferred_languages_load_textdomain_mofile( $mofile ) {
|
|
350 |
return $mofile;
|
351 |
}
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
/**
|
354 |
* Registers the needed scripts and styles.
|
355 |
*
|
@@ -366,7 +404,7 @@ function preferred_languages_register_scripts() {
|
|
366 |
'jquery-ui-sortable',
|
367 |
'wp-a11y',
|
368 |
),
|
369 |
-
'
|
370 |
true
|
371 |
);
|
372 |
|
@@ -387,7 +425,7 @@ function preferred_languages_register_scripts() {
|
|
387 |
'preferred-languages',
|
388 |
plugin_dir_url( dirname( __FILE__ ) ) . 'css/preferred-languages.css',
|
389 |
array(),
|
390 |
-
'
|
391 |
'screen'
|
392 |
);
|
393 |
|
@@ -416,6 +454,7 @@ function preferred_languages_settings_field() {
|
|
416 |
'general',
|
417 |
'default',
|
418 |
array(
|
|
|
419 |
'selected' => preferred_languages_get_site_list(),
|
420 |
)
|
421 |
);
|
350 |
return $mofile;
|
351 |
}
|
352 |
|
353 |
+
/**
|
354 |
+
* Filters load_script_translation_file() calls to respect the list of preferred languages.
|
355 |
+
*
|
356 |
+
* @since 1.6.0
|
357 |
+
*
|
358 |
+
* @param string|false $file Path to the translation file to load. False if there isn't one.
|
359 |
+
*
|
360 |
+
* @return string The modified JSON file path.
|
361 |
+
*/
|
362 |
+
function preferred_languages_load_script_translation_file( $file ) {
|
363 |
+
if ( is_readable( $file ) ) {
|
364 |
+
return $file;
|
365 |
+
}
|
366 |
+
|
367 |
+
$preferred_locales = preferred_languages_get_list();
|
368 |
+
|
369 |
+
if ( empty( $preferred_locales ) ) {
|
370 |
+
return $file;
|
371 |
+
}
|
372 |
+
|
373 |
+
$current_locale = determine_locale();
|
374 |
+
|
375 |
+
// Locale has been filtered by something else.
|
376 |
+
if ( ! in_array( $current_locale, $preferred_locales, true ) ) {
|
377 |
+
return $file;
|
378 |
+
}
|
379 |
+
|
380 |
+
foreach ( $preferred_locales as $locale ) {
|
381 |
+
$preferred_file = str_replace( $current_locale, $locale, $file );
|
382 |
+
|
383 |
+
if ( is_readable( $preferred_file ) ) {
|
384 |
+
return $preferred_file;
|
385 |
+
}
|
386 |
+
}
|
387 |
+
|
388 |
+
return $file;
|
389 |
+
}
|
390 |
+
|
391 |
/**
|
392 |
* Registers the needed scripts and styles.
|
393 |
*
|
404 |
'jquery-ui-sortable',
|
405 |
'wp-a11y',
|
406 |
),
|
407 |
+
'20190107',
|
408 |
true
|
409 |
);
|
410 |
|
425 |
'preferred-languages',
|
426 |
plugin_dir_url( dirname( __FILE__ ) ) . 'css/preferred-languages.css',
|
427 |
array(),
|
428 |
+
'20190107',
|
429 |
'screen'
|
430 |
);
|
431 |
|
454 |
'general',
|
455 |
'default',
|
456 |
array(
|
457 |
+
'class' => 'site-preferred-languages-wrap',
|
458 |
'selected' => preferred_languages_get_site_list(),
|
459 |
)
|
460 |
);
|
js/preferred-languages.js
CHANGED
@@ -217,11 +217,11 @@
|
|
217 |
updateHiddenInput(); // 6. Announce to assistive technologies.
|
218 |
|
219 |
wp.a11y.speak(settings.l10n.localeAdded);
|
220 |
-
} //
|
221 |
|
222 |
|
223 |
-
$('.user-language-wrap').
|
224 |
-
$('#WPLANG').parent().parent().
|
225 |
|
226 |
$inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove(); // Change initial button state.
|
227 |
|
@@ -237,13 +237,19 @@
|
|
237 |
var $firstInactiveLocale = $inactiveLocales.find('option:not(.hidden):first');
|
238 |
$firstInactiveLocale.attr('selected', true);
|
239 |
$inactiveLocalesControls.val($firstInactiveLocale.val());
|
|
|
|
|
|
|
|
|
|
|
240 |
} // Enabling sorting locales using drag and drop.
|
241 |
|
242 |
|
243 |
$activeLocales.sortable({
|
244 |
axis: 'y',
|
245 |
cursor: 'move',
|
246 |
-
items: ':not(#active-locales-list-empty-message)'
|
|
|
247 |
}); // Active locales keyboard shortcuts.
|
248 |
|
249 |
$document.on('keydown', function (e) {
|
217 |
updateHiddenInput(); // 6. Announce to assistive technologies.
|
218 |
|
219 |
wp.a11y.speak(settings.l10n.localeAdded);
|
220 |
+
} // Replace original language settings.
|
221 |
|
222 |
|
223 |
+
$('.user-language-wrap').replaceWith($('.user-preferred-languages-wrap'));
|
224 |
+
$('#WPLANG').parent().parent().replaceWith($('.site-preferred-languages-wrap')); // Remove en_US as an option from the dropdown.
|
225 |
|
226 |
$inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove(); // Change initial button state.
|
227 |
|
237 |
var $firstInactiveLocale = $inactiveLocales.find('option:not(.hidden):first');
|
238 |
$firstInactiveLocale.attr('selected', true);
|
239 |
$inactiveLocalesControls.val($firstInactiveLocale.val());
|
240 |
+
}
|
241 |
+
|
242 |
+
function onSortableUpdate() {
|
243 |
+
updateHiddenInput();
|
244 |
+
changeButtonState($selectedLocale);
|
245 |
} // Enabling sorting locales using drag and drop.
|
246 |
|
247 |
|
248 |
$activeLocales.sortable({
|
249 |
axis: 'y',
|
250 |
cursor: 'move',
|
251 |
+
items: ':not(#active-locales-list-empty-message)',
|
252 |
+
update: onSortableUpdate
|
253 |
}); // Active locales keyboard shortcuts.
|
254 |
|
255 |
$document.on('keydown', function (e) {
|
js/preferred-languages.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
"use strict";(function(wp,settings,$){var $document=$(document);var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $emptyMessage=$("#active-locales-empty-message");var $inactiveLocalesWrap=$(".inactive-locales-list");var $inactiveLocales=$inactiveLocalesWrap.find("select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $inputField=$('input[name="preferred_languages"]');var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var KEY_UP=38;var KEY_DOWN=40;var KEY_BACKSPACE=8;var KEY_A=65;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"));$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale($locale){var selected=$locale.attr("aria-selected");var newState="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;$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="'.concat(locale,'"]')).removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var locale=option.val()||"en_US";var $newLocale=$("<li/>",{text:option.text(),role:"option","aria-selected":false,id:locale,class:"active-locale"});var $successor;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("#".concat(locale)).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").
|
1 |
+
"use strict";(function(wp,settings,$){var $document=$(document);var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $emptyMessage=$("#active-locales-empty-message");var $inactiveLocalesWrap=$(".inactive-locales-list");var $inactiveLocales=$inactiveLocalesWrap.find("select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $inputField=$('input[name="preferred_languages"]');var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var KEY_UP=38;var KEY_DOWN=40;var KEY_BACKSPACE=8;var KEY_A=65;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"));$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale($locale){var selected=$locale.attr("aria-selected");var newState="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;$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="'.concat(locale,'"]')).removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var locale=option.val()||"en_US";var $newLocale=$("<li/>",{text:option.text(),role:"option","aria-selected":false,id:locale,class:"active-locale"});var $successor;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("#".concat(locale)).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").replaceWith($(".user-preferred-languages-wrap"));$("#WPLANG").parent().parent().replaceWith($(".site-preferred-languages-wrap"));$inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove();changeButtonState($selectedLocale);if($inputField.val().length){$.each($inputField.val().split(","),function(index,value){value="en_US"===value?"":value;var $option=$inactiveLocales.find('[value="'.concat(value,'"]'));$option.removeAttr("selected").addClass("hidden")});var $firstInactiveLocale=$inactiveLocales.find("option:not(.hidden):first");$firstInactiveLocale.attr("selected",true);$inactiveLocalesControls.val($firstInactiveLocale.val())}function onSortableUpdate(){updateHiddenInput();changeButtonState($selectedLocale)}$activeLocales.sortable({axis:"y",cursor:"move",items:":not(#active-locales-list-empty-message)",update:onSortableUpdate});$document.on("keydown",function(e){if(!document.querySelector(".preferred-languages").contains(document.activeElement)){return}switch(e.which){case KEY_UP:if(e.altKey){moveLocaleUp()}else if($selectedLocale.prev().length){toggleLocale($selectedLocale.prev())}else{$activeLocales.focus()}e.preventDefault();break;case KEY_DOWN:if(e.altKey){moveLocaleDown()}else if($selectedLocale.next().length){toggleLocale($selectedLocale.next())}else{$activeLocales.focus()}e.preventDefault();break;case KEY_A:if(e.altKey){makeLocaleActive($inactiveLocales.find("option:selected"))}e.preventDefault();break;case KEY_BACKSPACE:makeLocaleInactive();e.preventDefault();break}});$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.
|
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.6.0
|
7 |
* Author: Pascal Birchler
|
8 |
* Author URI: https://pascalbirchler.com
|
9 |
* License: GPL-2.0+
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: swissspidy
|
3 |
Tags: internationalization, i18n, localization, l10n, language, locale, translation
|
4 |
Requires at least: 4.9
|
5 |
-
Tested up to:
|
6 |
Requires PHP: 5.2
|
7 |
Stable tag: 1.5.0
|
8 |
License: GPLv2 or later
|
@@ -31,49 +31,13 @@ If you want to get involved, check out [open issues](https://github.com/swissspi
|
|
31 |
|
32 |
== Changelog ==
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
* Enhancement: Improved compatibility with multilingual plugins like Polylang.
|
37 |
-
* Fixed: Fixes an issue with keyboard navigation.
|
38 |
-
* Fixed: Make sure the correct languages are retrieved when updating the settings.
|
39 |
-
|
40 |
-
= 1.4.0 =
|
41 |
-
|
42 |
-
* New: Keyboard navigation improvements.
|
43 |
-
* New: Tooltips now show the available keyboard shortcuts.
|
44 |
-
* New: Missing translations are now downloaded even when no changes were made.
|
45 |
-
* New: A warning is shown when some of the preferred languages aren't installed.
|
46 |
-
* New: Settings form is now hidden when JavaScript is disabled.
|
47 |
-
* Fixed: Improved setting the current locale.
|
48 |
-
* Fixed: CSS is no longer enqueued on the front end.
|
49 |
-
|
50 |
-
= 1.3.0 =
|
51 |
-
|
52 |
-
* New: Users can now choose English (United States) again as a preferred locale.
|
53 |
-
* New: Users with the right capabilities can now install languages in their user profile as well.
|
54 |
-
|
55 |
-
= 1.2.0 =
|
56 |
|
57 |
-
|
58 |
-
* Fixed: Prevented some errors when adding all available locales.
|
59 |
-
|
60 |
-
= 1.1.0 =
|
61 |
-
|
62 |
-
* New: Support for just-in-time loading of translations.
|
63 |
-
* New: Keyboard shortcut for making inactive locales active.
|
64 |
-
* Fixed: Responsive design improvements.
|
65 |
-
* Fixed: Worked around a few edge cases with the various controls.
|
66 |
-
* Fixed: Added missing text domains.
|
67 |
-
|
68 |
-
= 1.0.1 =
|
69 |
-
|
70 |
-
* Fixed: Fixed a bug that prevented saving changes.
|
71 |
-
|
72 |
-
= 1.0.0 =
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
77 |
|
78 |
= 1.5.0 =
|
79 |
|
2 |
Contributors: swissspidy
|
3 |
Tags: internationalization, i18n, localization, l10n, language, locale, translation
|
4 |
Requires at least: 4.9
|
5 |
+
Tested up to: 5.0
|
6 |
Requires PHP: 5.2
|
7 |
Stable tag: 1.5.0
|
8 |
License: GPLv2 or later
|
31 |
|
32 |
== Changelog ==
|
33 |
|
34 |
+
For the plugin's changelog, please head over to [the GitHub repository](https://github.com/swissspidy/preferred-languages).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
== Upgrade Notice ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
= 1.6.0 =
|
39 |
|
40 |
+
This release adds full support for WordPress 5.0. Block editor support requires WordPress 5.0.3.
|
41 |
|
42 |
= 1.5.0 =
|
43 |
|