[Django] #26705: DjangoTranslation instance has no attribute 'plural'

Visto 23 veces
Saltar al primer mensaje no leído

Django

no leída,
3 jun 2016, 13:50:333/6/16
a django-...@googlegroups.com
#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.

Django

no leída,
3 jun 2016, 15:01:433/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------

Reporter: theju | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* 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>

Django

no leída,
4 jun 2016, 4:06:444/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------

Reporter: theju | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

no leída,
4 jun 2016, 4:07:214/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------

Reporter: theju | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by theju):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:3>

Django

no leída,
5 jun 2016, 15:19:355/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------

Reporter: theju | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:4>

Django

no leída,
7 jun 2016, 9:50:027/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------

Reporter: theju | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26705#comment:5>

Django

no leída,
8 jun 2016, 16:18:018/6/16
a django-...@googlegroups.com
#26705: DjangoTranslation instance has no attribute 'plural'
--------------------------------------+------------------------------------
Reporter: theju | Owner: nobody
Type: Bug | Status: closed
Component: Internationalization | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos