mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-24 19:32:53 +03:00
Add support for LOCALIZED_FIELDS_FALLBACKS
This commit is contained in:
parent
b10472d3e9
commit
16e23963cc
@ -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,12 +103,18 @@ 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)
|
||||||
|
|
||||||
return value or ''
|
for lang_code in languages:
|
||||||
|
value = self.get(lang_code)
|
||||||
|
if value:
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user