Ticket #5672: list_separator_translatable-2.diff

File list_separator_translatable-2.diff, 3.0 KB (added by Claude Paroz, 14 years ago)

Patch including tests

  • django/conf/locale/ar/LC_MESSAGES/django.po

    diff --git a/django/conf/locale/ar/LC_MESSAGES/django.mo b/django/conf/locale/ar/LC_MESSAGES/django.mo
    index 77bc44d..9234d63 100644
    Binary files a/django/conf/locale/ar/LC_MESSAGES/django.mo and b/django/conf/locale/ar/LC_MESSAGES/django.mo differ
    diff --git a/django/conf/locale/ar/LC_MESSAGES/django.po b/django/conf/locale/ar/LC_MESSAGES/django.po
    index 28e2153..2095a35 100644
    a b msgstr "ديسمبر"  
    50225022msgid "or"
    50235023msgstr "أو"
    50245024
     5025#. Translators: This string is used as a separator between list elements
     5026#: utils/text.py:153
     5027msgid ", "
     5028msgstr "، "
     5029
    50255030#: utils/timesince.py:21
    50265031msgid "year"
    50275032msgid_plural "years"
  • django/utils/text.py

    diff --git a/django/utils/text.py b/django/utils/text.py
    index b054604..d5b3fce 100644
    a b  
    11import re
    22from django.utils.encoding import force_unicode
    33from django.utils.functional import allow_lazy
    4 from django.utils.translation import ugettext_lazy
     4from django.utils.translation import ugettext_lazy, ugettext as _
    55from htmlentitydefs import name2codepoint
    66
    77# Capitalizes the first letter of a string.
    def get_text_list(list_, last_word=ugettext_lazy(u'or')):  
    148148    """
    149149    if len(list_) == 0: return u''
    150150    if len(list_) == 1: return force_unicode(list_[0])
    151     return u'%s %s %s' % (', '.join([force_unicode(i) for i in list_][:-1]), force_unicode(last_word), force_unicode(list_[-1]))
     151    return u'%s %s %s' % (
     152        # Translators: This string is used as a separator between list elements
     153        _(', ').join([force_unicode(i) for i in list_][:-1]),
     154        force_unicode(last_word),
     155        force_unicode(list_[-1]))
    152156get_text_list = allow_lazy(get_text_list, unicode)
    153157
    154158def normalize_newlines(text):
  • tests/regressiontests/text/tests.py

    diff --git a/tests/regressiontests/text/tests.py b/tests/regressiontests/text/tests.py
    index fd02036..3036f8e 100644
    a b from django.test import TestCase  
    44from django.utils.text import *
    55from django.utils.http import urlquote, urlquote_plus, cookie_date, http_date
    66from django.utils.encoding import iri_to_uri
     7from django.utils.translation import activate, deactivate
    78
    89class TextTests(TestCase):
    910    """
    1011    Tests for stuff in django.utils.text and other text munging util functions.
    1112    """
    1213
     14    def test_get_text_list(self):
     15        self.assertEqual(get_text_list(['a', 'b', 'c', 'd']), u'a, b, c or d')
     16        self.assertEqual(get_text_list(['a', 'b', 'c'], 'and'), u'a, b and c')
     17        self.assertEqual(get_text_list(['a', 'b'], 'and'), u'a and b')
     18        self.assertEqual(get_text_list(['a']), u'a')
     19        self.assertEqual(get_text_list([]), u'')
     20        activate('ar')
     21        self.assertEqual(get_text_list(['a', 'b', 'c']), u"a، b أو c")
     22        deactivate()
     23
    1324    def test_smart_split(self):
    1425
    1526        self.assertEquals(list(smart_split(r'''This is "a person" test.''')),
Back to Top