Hi,

You got it right.
Please note that an accept language is by no mean a location.
en-US is 4 or 5 timezones (don’t remember and limited internet connection, 
you’ll correct), let alone russian.
Amazingly France spans 11 timezones (iirc, no april fool) so pretty hard for 
fr-FR to set a TZ.

That put apart the default behavior would be to return the timezone 
informations so your client can do the translation by itself.
I remember an API (written with DRF) that was returning the ISO string (so UTC) 
and angular converted it to the local timezone (CET by that time) shift 
appropriately the time.
My bet here, you don’t provide TZ information so your JS client may not perform 
the correct translation.

Regards,
Xavier Ordoquy,
Linovia.

> Le 31 mars 2017 à 19:30, [email protected] a écrit :
> 
> Hi,
> 
>  I'm learning Django Rest Framework but otherwise I'm quite proficient with 
> Django.
> 
> I have a website which uses translations, the usual stuff: {% trans %}, {% 
> blocktrans %}, but also JavaScriptCatalog for xhr. So far, so good. 
> Everything is translated into one of the website's languages, English and 
> Polish.
> 
> However, I also have asynchronous pagination using rest framework and xhr. 
> The dates returned by my xhr / REST requests are not translated, even with 
> Accept-Language set in request header.
> 
> models.py:
> 
>     pub_date = models.DateTimeField(_("Publication date"), auto_now_add=True)
>     mod_date = models.DateTimeField(_("Modification date"), auto_now=True)
> 
> in views.py: generics.ListAPIView
> 
> serializers.py: (serializers.ModelSerializer)
> 
>     pub_date = serializers.DateTimeField(format='%d %b %Y')
>     mod_date = serializers.DateTimeField(format='%d %b %Y')
> 
> request, using the commandline tool httpie:
> 
> http http://10.7.90.5:8000/karty/api/ Accept:application/json 
> Accept-Language:pl
> 
> I've tried setting it to both 'en' end 'pl'. In the user-facing view I get 
> either Polish or English depending on the header, that's how I know the 
> syntax is correct. But in the API views the date is always in english.
> 
> Language code is not specified in settings.py, so it uses default. 
> LocaleMiddleware is enabled and works for the rest of the website. It's a toy 
> / exercise project so most settings are on their default values.
> 
> Am I missing something ? I read the 'internationalization' chapter of the 
> rest framework documentation, and I don't see anything. Actually, the opening 
> paragraph and the choice of examples implies that error messages are the only 
> thing you may want to translate. So it looks like an omission in design to me.
> 
> Cheers,
> Marek Onuszko
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to