Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4796. Fixed a problem when using i18n support for the first ti…

…me -- in

particular when string_concat() was the first call made. Thanks, Andy Durdin.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6446 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fa546d797e4b7c627c91ec3740b0f104aa30549d 1 parent 1046647
Malcolm Tredinnick authored October 03, 2007
14  django/utils/translation/__init__.py
@@ -2,6 +2,7 @@
2 2
 Internationalization support.
3 3
 """
4 4
 from django.utils.functional import lazy
  5
+from django.utils.encoding import force_unicode
5 6
 
6 7
 __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
7 8
         'ngettext_lazy', 'string_concat', 'activate', 'deactivate',
@@ -39,7 +40,7 @@ def delayed_loader(*args, **kwargs):
39 40
             g['real_%s' % name] = getattr(trans, name)
40 41
 
41 42
     # Make the originally requested function call on the way out the door.
42  
-    return g[caller](*args, **kwargs)
  43
+    return g['real_%s' % caller](*args, **kwargs)
43 44
 
44 45
 g = globals()
45 46
 for name in __all__:
@@ -63,14 +64,10 @@ def ugettext(message):
63 64
 def ungettext(singular, plural, number):
64 65
     return real_ungettext(singular, plural, number)
65 66
 
66  
-def string_concat(*strings):
67  
-    return real_string_concat(*strings)
68  
-
69 67
 ngettext_lazy = lazy(ngettext, str)
70 68
 gettext_lazy = lazy(gettext, str)
71 69
 ungettext_lazy = lazy(ungettext, unicode)
72 70
 ugettext_lazy = lazy(ugettext, unicode)
73  
-string_concat = lazy(string_concat, unicode)
74 71
 
75 72
 def activate(language):
76 73
     return real_activate(language)
@@ -108,3 +105,10 @@ def templatize(src):
108 105
 def deactivate_all():
109 106
     return real_deactivate_all()
110 107
 
  108
+def string_concat(*strings):
  109
+    """"
  110
+    Lazy variant of string concatenation, needed for translations that are
  111
+    constructed from multiple parts.
  112
+    """
  113
+    return u''.join([force_unicode(s) for s in strings])
  114
+string_concat = lazy(string_concat, unicode)
1  django/utils/translation/trans_null.py
@@ -13,7 +13,6 @@ def ngettext(singular, plural, number):
13 13
 def ungettext(singular, plural, number):
14 14
     return force_unicode(ngettext(singular, plural, number))
15 15
 
16  
-string_concat = lambda *strings: u''.join([force_unicode(el) for el in strings])
17 16
 activate = lambda x: None
18 17
 deactivate = deactivate_all = install = lambda: None
19 18
 get_language = lambda: settings.LANGUAGE_CODE
6  django/utils/translation/trans_real.py
@@ -516,9 +516,3 @@ def templatize(src):
516 516
                 out.write(blankout(t.contents, 'X'))
517 517
     return out.getvalue()
518 518
 
519  
-def string_concat(*strings):
520  
-    """"
521  
-    Lazy variant of string concatenation, needed for translations that are
522  
-    constructed from multiple parts.
523  
-    """
524  
-    return u''.join([force_unicode(s) for s in strings])
8  tests/regressiontests/i18n/tests.py
@@ -30,4 +30,12 @@
30 30
 >>> s4 = ugettext_lazy('Some other string')
31 31
 >>> s == s4
32 32
 False
  33
+
  34
+unicode(string_concat(...)) should not raise a TypeError - #4796
  35
+
  36
+>>> import django.utils.translation
  37
+>>> reload(django.utils.translation)
  38
+<module 'django.utils.translation' from ...>
  39
+>>> unicode(django.utils.translation.string_concat("dja", "ngo"))
  40
+u'django'
33 41
 """

0 notes on commit fa546d7

Please sign in to comment.
Something went wrong with that request. Please try again.