Not picking up Danish translations

35 views
Skip to first unread message

Jeppe Vesterbæk

unread,
Aug 31, 2016, 5:01:54 AM8/31/16
to Django REST framework
I'm sending requests with "Accept-Language: da". Translations originating from Django (eg. "This field is required.") and translations in my own apps work. Strings in rest framework always are always returned in english, eg. "This field may not be blank.". Looking into the locale folder of rest framework, I can see both "da" and "da_DK" where "da_DK" contains empty strings only. 

If I delete the da_DK folder in rest_framework, the Danish translations work.

I'm not sure how Django / gettext resolves a translation key, but it somehow seems to get confused by the empty string found in da_DK and instead use the key (english base).

Xavier Ordoquy

unread,
Aug 31, 2016, 5:07:12 AM8/31/16
to django-res...@googlegroups.com
Hi,
Thanks for reporting. Translations seems to be somewhat hard to get right.
Your issue may indicate that Danish translation has been claimed but not performed on transiflex.
DRF has a - small - common set of translatable strings with Django. Unfortunately in your case, DRF takes precedence over Django.
I though empty string would be considered as non existant by the Django translation engine.

The options are:
- we remove the danish translation from transifex
- someone performs the translation (via transiflex)

Regards,
Xavier,
Linovia.

Jeppe Vesterbæk

unread,
Aug 31, 2016, 5:30:07 AM8/31/16
to django-res...@googlegroups.com

Thanks for reporting. Translations seems to be somewhat hard to get right.
Your issue may indicate that Danish translation has been claimed but not performed on transiflex.
DRF has a - small - common set of translatable strings with Django. Unfortunately in your case, DRF takes precedence over Django.
I though empty string would be considered as non existant by the Django translation engine.

Danish "da" translations are there. Danish/Denmark "da_DK" translations file exists but contains empty strings only. From looking at the gettext documentation, it seems and empty value means use the key as value.

I also looked a bit into the internals of Django wrt. translation in trans_real.py and gettext.py in gettext. My current language is correctly set to "da". gettext finds da/LC_MESSAGES/django.mo, da_DK/LC_MESSAGES/django.mo based on the locale dir provided to it by Django. gettext chains the two files via a _fallback parameter. And returns this to Django. Django then merges the translations from the given app into one translation dict. 

I couldn't entirely understand if the problem with the empty values are from gettext parsing of the mo-files where it replaces empty value with key or it's from Django's merging of the translation objects. Bottom line is that if I remove the empty entries (i.e. delete the da_DK dir) it works.

Dirty hack in settings making this work when deploying to Heroku:

def tmp_remove_incorrect_translations():
    import rest_framework
    import shutil
    d = os.path.join(os.path.dirname(rest_framework.__file__), 'locale', 'da_DK')
    if os.path.exists(d):
        shutil.rmtree(d)
tmp_remove_incorrect_translations()


Reply all
Reply to author
Forward
0 new messages