mirror of
				https://github.com/SectorLabs/django-localized-fields.git
				synced 2025-10-30 18:48:56 +03:00 
			
		
		
		
	Add support for LOCALIZED_FIELDS_FALLBACKS
This commit is contained in:
		| @@ -1,6 +1,5 @@ | |||||||
| import collections | import collections | ||||||
|  |  | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.utils import translation | from django.utils import translation | ||||||
|  |  | ||||||
| @@ -104,13 +103,19 @@ class LocalizedValue(dict): | |||||||
|         back to the primary language if there's no value |         back to the primary language if there's no value | ||||||
|         in the current language.""" |         in the current language.""" | ||||||
|  |  | ||||||
|         value = self.get(translation.get_language()) |         fallbacks = getattr(settings, 'LOCALIZED_FIELDS_FALLBACKS', {}) | ||||||
|  |  | ||||||
|         if not value: |         language = translation.get_language() or settings.LANGUAGE_CODE | ||||||
|             value = self.get(settings.LANGUAGE_CODE) |         languages = fallbacks.get(language, [settings.LANGUAGE_CODE])[:] | ||||||
|  |         languages.insert(0, language) | ||||||
|  |  | ||||||
|  |         for lang_code in languages: | ||||||
|  |             value = self.get(lang_code) | ||||||
|  |             if value: | ||||||
|                 return value or '' |                 return value or '' | ||||||
|  |  | ||||||
|  |         return '' | ||||||
|  |  | ||||||
|     def __eq__(self, other): |     def __eq__(self, other): | ||||||
|         """Compares :paramref:self to :paramref:other for |         """Compares :paramref:self to :paramref:other for | ||||||
|         equality. |         equality. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user