From 92a98868720da6d537d605a75e92e9640d5190aa Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 20 May 2021 16:23:38 +0200 Subject: [PATCH] misc: restore select2 translations (#54147) Also revert previous fix attempt of commit 0676783c. --- src/authentic2/attribute_kinds.py | 4 +++- .../authentic2/manager/js/select2_locale.js | 24 +++++++------------ src/authentic2/manager/widgets.py | 3 +++ src/authentic2/templates/select2_locale.html | 8 ------- 4 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 src/authentic2/templates/select2_locale.html diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index 9a0156cdf..b6aff863b 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -27,7 +27,7 @@ from django.core.exceptions import ValidationError from django.core.files.storage import default_storage from django.core.validators import RegexValidator from django.db.models import query -from django.urls import reverse +from django.urls import reverse, reverse_lazy from django.utils import formats, html from django.utils.functional import keep_lazy from django.utils.translation import pgettext_lazy @@ -118,6 +118,8 @@ class AddressAutocompleteInput(forms.Select): js = [ xstatic('jquery.js', 'jquery.min.js'), settings.SELECT2_JS, + 'authentic2/manager/js/select2_locale.js', + reverse_lazy('a2-manager-javascript-catalog'), 'authentic2/js/address_autocomplete.js', ] css = { diff --git a/src/authentic2/manager/static/authentic2/manager/js/select2_locale.js b/src/authentic2/manager/static/authentic2/manager/js/select2_locale.js index b7c85f501..f10f4b769 100644 --- a/src/authentic2/manager/static/authentic2/manager/js/select2_locale.js +++ b/src/authentic2/manager/static/authentic2/manager/js/select2_locale.js @@ -1,40 +1,32 @@ (function ($) { - $.extend($.fn.select2.defaults, { - formatMatches: function (matches) { - if (matches === 1) { - return gettext("One result is available, press enter to select it."); - } - return interpolate( - gettext("%s results are available, use up and down arrow keys to navigate."), - [matches]); - }, - formatNoMatches: function () { + $.fn.select2.defaults.set('language', { + noResults: function () { return gettext("No matches found"); }, - formatAjaxError: function (jqXHR, textStatus, errorThrown) { + errorLoading: function (jqXHR, textStatus, errorThrown) { return gettext("Loading failed"); }, - formatInputTooShort: function (input, min) { + inputTooShort: function (input, min) { var n = min - input.length; return interpolate( ngettext("Please enter %s or more character", "Please enter %s or more characters", n), [n]); }, - formatInputTooLong: function (input, max) { + inputTooLong: function (input, max) { var n = input.length - max; return interpolate( ngettext("Please delete %s character", "Please delete %s characters", n), [n]); }, - formatSelectionTooBig: function (limit) { + maximumSelected: function (limit) { return interpolate( ngettext("You can only select %s item", "You can only select %s items", limit), [limit]); }, - formatLoadMore: function (pageNumber) { + loadingMore: function (pageNumber) { return gettext("Loading more results…"); }, - formatSearching: function () { + searching: function () { return gettext("Searching…"); } }); diff --git a/src/authentic2/manager/widgets.py b/src/authentic2/manager/widgets.py index 879db45e7..1666c1503 100644 --- a/src/authentic2/manager/widgets.py +++ b/src/authentic2/manager/widgets.py @@ -48,6 +48,9 @@ class SplitTermMixin(object): class Select2Mixin(object): + class Media: + js = ('authentic2/manager/js/select2_locale.js',) + def build_attrs(self, *args, **kwargs): attrs = super(Select2Mixin, self).build_attrs(*args, **kwargs) field_data = { diff --git a/src/authentic2/templates/select2_locale.html b/src/authentic2/templates/select2_locale.html deleted file mode 100644 index 68c254f98..000000000 --- a/src/authentic2/templates/select2_locale.html +++ /dev/null @@ -1,8 +0,0 @@ -{% load i18n %} - -{# Translations of select2 autocompletion field hints #} -{% trans "Searching..." %} -{% trans "No matches found" %} -{% trans "Please enter more characters" %} -{% trans "Loading more results..." %} -{% trans "The results could not be loaded" %}