Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internationalization for Dates in django rest framework?

I am trying to translate Dates in API's(Django rest framework), well as of now Internationalization and localization is working for all the other things but i am stuck at Dates.

There is only English and French language and also i have restarted server few times but not able to get dates in FR as you can see i have used Rosettaenter image description here

Example code :

@staticmethod
def get_start_date(obj):
    return obj.start_date.strftime("%d %B, %Y")

when lang code is en O/P is :

start_date": "01 January, 2016"

but when lang code is fr expected result:

start_date": "01 Janvier, 2016"

still it is showing in english

settings.py i have successfully added basic settings still for your information

MIDDLEWARE_CLASSES
'django.middleware.locale.LocaleMiddleware',

USE_L10N = True

Thanks in advance

like image 529
Kamlesh Avatar asked Nov 09 '22 13:11

Kamlesh


1 Answers

It's hack too, but helping. Add this in Rest view:

import locale
locale.setlocale(locale.LC_TIME, "ru_RU.utf-8")
like image 105
Atterratio Avatar answered Nov 14 '22 22:11

Atterratio