{{{
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.
* needs_better_patch: => 0
* needs_docs: => 0
* version: 1.8 => master
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
We could copy this line from the `gettext` module in `__init__`:
`self.plural = lambda n: int(n != 1) # germanic plural by default`
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:1>
Comment (by theju):
A patch along with test is available at
https://github.com/theju/django/tree/ticket_26705
I have also attached a pull request at
https://github.com/django/django/pull/6717
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:4>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"c8d2120b06e1b82cb0db896aa0f9767b2f14256c" c8d2120b]:
{{{
#!CommitTicketReference repository=""
revision="c8d2120b06e1b82cb0db896aa0f9767b2f14256c"
Fixed #26705 -- Fixed plural versions of languages not supported by
Django.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:6>