Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use request.LANGUAGE_CODE in API #23

Open
georgedorn opened this issue Dec 22, 2017 · 1 comment
Open

Use request.LANGUAGE_CODE in API #23

georgedorn opened this issue Dec 22, 2017 · 1 comment

Comments

@georgedorn
Copy link

I'm writing an API that needs to return a field localized for the request.

I'm using Django's LocaleMiddleware, which negotiates the HTTP Accept-language header against settings.LANGUAGE_CODES and sets the result as request.LANGUAGE_CODE. Is there a pattern or mixin I should be using on my ViewSets to activate that language for the response?

@vdboor
Copy link
Contributor

vdboor commented Jan 2, 2018

Not that I'm aware of.. Django's LocaleMiddleware also calls translation.activate() so the current Django language will be set. django-parler uses django.utils.translation.get_language() by default when objects are fetched from the database.

You can set the language explicitly off course, using Model.objects.language(..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants