SectorLabs/django-localized-fields

Feature: ContextManager returning translated values

sbor23 opened this issue · 1 comments

I would be cool if there was a utility ContextManager that would evaluate every LocalizedValue directly to the active language (or an override language if specified) to it's translated value.

So the usage could be something like this:

def collect_fields():
    # collect some data from different models with LocalizedFields
    pass

with LocalizedValue.get_translations(optional_language_string):
    my_fields = collect_fields()

This is inspired by the Django translation override ContextManager:
https://docs.djangoproject.com/en/3.0/ref/utils/#django.utils.translation.override

This already works with Django's django.utils.translation.override. There should be no need for a separate contect manager.