0

I literally copy-pasted this from the docs:

class CustomerAdmin(ExportActionMixin, admin.ModelAdmin):
     def mail(self, request, queryset): 
         with translation.override('nl'):
             print(_('Hello'))

still prints Hello instead of Hallo Docs state this should work regardless of what settings or middleware you've got enabled.

I tried nl, de, and dk, it's always English.

I'm on Django 3.6

Samoht
  • 39
  • 6
  • You need to store the translation (.po and .mo) https://docs.djangoproject.com/en/4.0/topics/i18n/translation/#how-django-discovers-translations – rahul.m Dec 10 '21 at 12:40
  • Have you provided translation files for those languages? – ChrisGPT was on strike Dec 10 '21 at 12:42
  • Samoht this will help you https://stackoverflow.com/questions/20467626/whats-the-correct-way-to-set-up-django-translation – rahul.m Dec 10 '21 at 12:42
  • I thought there was an array of common words automatically translated. Say if I wanted to send a mail to an administrator when a customer registers and send the day this happened, I have to put Monday to Sunday in that translation file?? – Samoht Dec 10 '21 at 12:50
  • 1
    @Samoht, yes. Django's translation feature isn't magic. It lets _you_ translate your application and provides a mechanism to load the correct strings for each language. I suggest you start with [the feature overview](https://docs.djangoproject.com/en/stable/topics/i18n/translation/). – ChrisGPT was on strike Dec 10 '21 at 12:56
  • In that case, something like `_(date = strftime("%A %d %B %y", gmtime()))` is impossible? Since I can only put strings in the .po and not variables... – Samoht Dec 10 '21 at 13:01
  • @Samoht, correct. The translation feature is for translating strings. However `%A` and `%B` are already locale-aware. What are you trying to accomplish here? Maybe you are actually looking for [_localization_](https://docs.djangoproject.com/en/stable/topics/i18n/formatting/) instead of translation? – ChrisGPT was on strike Dec 10 '21 at 16:18
  • @Chris I want the weekday's name to be translated to dutch. Apparently when I use `_date(datetime.now(), "l j F 'y")` its dutch on production but english on development... – Samoht Dec 13 '21 at 15:13

0 Answers0