6

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

3
  • facing the same issue..have you got a solution meanwhile? Commented Mar 5, 2018 at 17:30
  • Tried but didn't found the proper solution. Don't waste much time, try any other quick fix. I did fixed using jquery. @MihaiZamfir Commented Mar 6, 2018 at 16:11
  • Thanks. I ended with a custom solution as well, but I thought I would have been nicer to have an native solution Commented Mar 7, 2018 at 13:36

2 Answers 2

2

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

import locale
locale.setlocale(locale.LC_TIME, "ru_RU.utf-8")
Sign up to request clarification or add additional context in comments.

Comments

0

For localizing the dates, you need to use the django-babel package that can easily be integrated with the django locale middleware.

Check the documentation below. http://django-babel.readthedocs.io/en/latest/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.