#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+--------------------
     Reporter:  theju                 |      Owner:  nobody
         Type:  Bug                   |     Status:  new
    Component:  Internationalization  |    Version:  1.8
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 When you activate a language that is not supported by django, an error is
 raised during the internationalization. Here is a test to reproduce the
 error:

 {{{
 import datetime

 from django.utils.translation import activate
 from django.utils.timesince import timesince
 from django.test import TestCase
 from django.conf import settings

 # Create your tests here.
 class TmpTestCase(TestCase):
     def test_lang(self):
         today = datetime.datetime.now()
         yesterday = today - datetime.timedelta(minutes=5)

         tt = timesince(yesterday, now=today)
         self.assertEqual(tt, u"5\xa0minutes")

         activate("hi")
         tt = timesince(yesterday, now=today)
         self.assertEqual(tt, u"5\xa0minutes")

         activate("as")
         tt = timesince(yesterday, now=today)
         self.assertEqual(tt, u"5\xa0minutes")
 }}}

 `as` is Assamese, a language that is currently not in django.

 The error is

 {{{
 AttributeError                            Traceback (most recent call
 last)
 <ipython-input-22-e5b829f6150e> in <module>()
 ----> 1 capfirst(ngettext(u"test", u"tests", 2))

 /home/ubuntu/wg_env/local/lib/python2.7/site-
 packages/django/utils/translation/__init__.pyc in ngettext(singular,
 plural, number)
      78
      79 def ngettext(singular, plural, number):
 ---> 80     return _trans.ngettext(singular, plural, number)
      81
      82

 /home/ubuntu/wg_env/local/lib/python2.7/site-
 packages/django/utils/translation/trans_real.pyc in ngettext(singular,
 plural, number)
     369     Returns a string on Python 3 and an UTF-8-encoded bytestring
 on Python 2.
     370     """
 --> 371     return do_ntranslate(singular, plural, number, 'ngettext')
     372
     373 if six.PY3:

 /home/ubuntu/wg_env/local/lib/python2.7/site-
 packages/django/utils/translation/trans_real.pyc in
 do_ntranslate(singular, plural, number, translation_function)
     356     t = getattr(_active, "value", None)
     357     if t is not None:
 --> 358         return getattr(t, translation_function)(singular, plural,
 number)
     359     if _default is None:
     360         _default = translation(settings.LANGUAGE_CODE)

 /usr/lib/python2.7/gettext.pyc in ngettext(self, msgid1, msgid2, n)
     368     def ngettext(self, msgid1, msgid2, n):
     369         try:
 --> 370             tmsg = self._catalog[(msgid1, self.plural(n))]
     371             if self._output_charset:
     372                 return tmsg.encode(self._output_charset)

 AttributeError: DjangoTranslation instance has no attribute 'plural'
 }}}

 Ideally, there shouldn't be an error.

--
Ticket URL: <https://code.djangoproject.com/ticket/26705>
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.9a4391bbf05f5b178c695c71c2be04bb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to