mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[4.0.x] Fixed #33070 -- Fixed loading translations with language subtags in admin's Select2 widget.
Backport of 8eb5693091 from main
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							3c751f008f
						
					
				
				
					commit
					a077f10df4
				
			| @@ -388,6 +388,7 @@ class AutocompleteMixin: | |||||||
|         self.db = using |         self.db = using | ||||||
|         self.choices = choices |         self.choices = choices | ||||||
|         self.attrs = {} if attrs is None else attrs.copy() |         self.attrs = {} if attrs is None else attrs.copy() | ||||||
|  |         self.i18n_name = SELECT2_TRANSLATIONS.get(get_language()) | ||||||
|  |  | ||||||
|     def get_url(self): |     def get_url(self): | ||||||
|         return reverse(self.url_name % self.admin_site.name) |         return reverse(self.url_name % self.admin_site.name) | ||||||
| @@ -413,6 +414,7 @@ class AutocompleteMixin: | |||||||
|             'data-theme': 'admin-autocomplete', |             'data-theme': 'admin-autocomplete', | ||||||
|             'data-allow-clear': json.dumps(not self.is_required), |             'data-allow-clear': json.dumps(not self.is_required), | ||||||
|             'data-placeholder': '',  # Allows clearing of the input. |             'data-placeholder': '',  # Allows clearing of the input. | ||||||
|  |             'lang': self.i18n_name, | ||||||
|             'class': attrs['class'] + (' ' if attrs['class'] else '') + 'admin-autocomplete', |             'class': attrs['class'] + (' ' if attrs['class'] else '') + 'admin-autocomplete', | ||||||
|         }) |         }) | ||||||
|         return attrs |         return attrs | ||||||
| @@ -449,8 +451,7 @@ class AutocompleteMixin: | |||||||
|     @property |     @property | ||||||
|     def media(self): |     def media(self): | ||||||
|         extra = '' if settings.DEBUG else '.min' |         extra = '' if settings.DEBUG else '.min' | ||||||
|         i18n_name = SELECT2_TRANSLATIONS.get(get_language()) |         i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % self.i18n_name,) if self.i18n_name else () | ||||||
|         i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % i18n_name,) if i18n_name else () |  | ||||||
|         return forms.Media( |         return forms.Media( | ||||||
|             js=( |             js=( | ||||||
|                 'admin/js/vendor/jquery/jquery%s.js' % extra, |                 'admin/js/vendor/jquery/jquery%s.js' % extra, | ||||||
|   | |||||||
| @@ -72,7 +72,8 @@ class AutocompleteMixinTests(TestCase): | |||||||
|             'data-app-label': 'admin_widgets', |             'data-app-label': 'admin_widgets', | ||||||
|             'data-field-name': 'band', |             'data-field-name': 'band', | ||||||
|             'data-model-name': 'album', |             'data-model-name': 'album', | ||||||
|             'data-placeholder': '' |             'data-placeholder': '', | ||||||
|  |             'lang': 'en', | ||||||
|         }) |         }) | ||||||
|  |  | ||||||
|     def test_build_attrs_no_custom_class(self): |     def test_build_attrs_no_custom_class(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user