2
2
from django .template import Lexer , TOKEN_TEXT , TOKEN_VAR , TOKEN_BLOCK
3
3
from django .utils .translation .trans_real import (
4
4
inline_re , block_re , endblock_re , plural_re , constant_re )
5
+ from django .utils .encoding import smart_unicode
5
6
6
7
7
8
def extract_django (fileobj , keywords , comment_tags , options ):
@@ -34,10 +35,18 @@ def extract_django(fileobj, keywords, comment_tags, options):
34
35
pluralmatch = plural_re .match (t .contents )
35
36
if endbmatch :
36
37
if inplural :
37
- yield lineno , 'ngettext' , (unicode ('' .join (singular )),
38
- unicode ('' .join (plural ))), []
38
+ yield (
39
+ lineno ,
40
+ 'ngettext' ,
41
+ (smart_unicode (u'' .join (singular )),
42
+ smart_unicode (u'' .join (plural ))),
43
+ []
39
44
else :
40
- yield lineno , None , unicode ('' .join (singular )), []
45
+ yield (
46
+ lineno ,
47
+ None ,
48
+ smart_unicode (u'' .join (singular )),
49
+ [])
41
50
intrans = False
42
51
inplural = False
43
52
singular = []
@@ -68,22 +77,22 @@ def extract_django(fileobj, keywords, comment_tags, options):
68
77
g = g .strip ('"' )
69
78
elif g [0 ] == "'" :
70
79
g = g .strip ("'" )
71
- yield lineno , None , unicode (g ), []
80
+ yield lineno , None , smart_unicode (g ), []
72
81
elif bmatch :
73
82
for fmatch in constant_re .findall (t .contents ):
74
- yield lineno , None , unicode (fmatch ), []
83
+ yield lineno , None , smart_unicode (fmatch ), []
75
84
intrans = True
76
85
inplural = False
77
86
singular = []
78
87
plural = []
79
88
elif cmatches :
80
89
for cmatch in cmatches :
81
- yield lineno , None , unicode (cmatch ), []
90
+ yield lineno , None , smart_unicode (cmatch ), []
82
91
elif t .token_type == TOKEN_VAR :
83
92
parts = t .contents .split ('|' )
84
93
cmatch = constant_re .match (parts [0 ])
85
94
if cmatch :
86
- yield lineno , None , unicode (cmatch .group (1 )), []
95
+ yield lineno , None , smart_unicode (cmatch .group (1 )), []
87
96
for p in parts [1 :]:
88
97
if p .find (':_(' ) >= 0 :
89
98
p1 = p .split (':' , 1 )[1 ]
@@ -95,4 +104,4 @@ def extract_django(fileobj, keywords, comment_tags, options):
95
104
p1 = p1 .strip ("'" )
96
105
elif p1 [0 ] == '"' :
97
106
p1 = p1 .strip ('"' )
98
- yield lineno , None , unicode (p1 ), []
107
+ yield lineno , None , smart_unicode (p1 ), []
0 commit comments