1

I have some issues while trying to translate in django (on the front end)

So I have a Contact model that has a bunch of messages. Each message has a "contact_date" field which I convert using humanize on the front end.

{{ message.contact_date | naturaltime }}

I have these in my settings.py

LANGUAGE_CODE = 'en-US'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

I kind of managed to make it work, but it involved changing my project's language code to the other language and removing the LocaleMiddleware. Then what happened is that my admin area changed into that language and I want it in English.

My goal is to leave everything in English and just convert the contact_date to the other language.

Any help would be appreciated, thanks!

Daniel
  • 131
  • 1
  • 9
  • For what it's worth, I don't think the problem is with humanize. When I switch to a different language on my site the humanized text is translated too. I think the issue you're running into has to do with how translation works in Django, and the fact that the admin is prepared for translation with gettext_lazy and generated .po files by default. That you are wanting two different languages active at the same time presents the problem. I guess you could go into the .po files for the language and delete all the msgstr "" except for the dates, but that seems hacky and not worth the effort. –  Dec 16 '18 at 20:57
  • I didn't think humanize was causing a problem. I just wanted to keep my language code 'en-US' and translate a few bits of text. I tried using the .po file solution but couldn't get it to work. – Daniel Dec 16 '18 at 21:03

0 Answers0