#34602: Fail gettext when no translation file is found or when no msgid is 
found in
the given translation file
-------------------------------------+-------------------------------------
     Reporter:  Gergely Kalmár       |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:                       |                  Version:  4.2
  Internationalization               |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Gergely Kalmár):

 Sure, the case is very simple. Create a view like the one in the
 documentation (see
 https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#standard-
 translation):

 {{{
 from django.http import HttpResponse
 from django.utils.translation import gettext as _


 def my_view(request):
     output = _("Welcome to my site.")
     return HttpResponse(output)
 }}}

 Make sure that you use more than one language (e.g. set `LANGUAGES =
 [('en', 'English'), ('de', 'German')])` and configure translations like
 described in the documentation. Note that even if you display the view
 with the German language, you will see "Welcome to my site." and will not
 receive any error or warning about the fact that the German translation
 file doesn't even exist yet.

 Then create a translation catalog file and translate the sentence. Notice
 that the translated sentence appears now properly. Now change the output
 line to `output = _("Welcome to my updated site.")`. Notice how the
 translated sentence turns back into English even when using German as a
 language and you don't get any warning or error again.

 I'd much prefer if we received an exception (or at least a warning) in
 both cases. I understand that this would be a backwards-incompatible
 change, which is why I suggested to perhaps use a setting to control this
 (e.g. `RAISE_TRANSLATION_ERRORS`). Currently the translation system is
 really error-prone, it is totally possible for a developer to change a
 text in a view or a template and forget to update the translation files
 and thus break translation for the end users.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34602#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188777751ee-26721b73-8783-4848-bb3b-9332d094146b-000000%40eu-central-1.amazonses.com.

Reply via email to