22from django .template import Lexer , TOKEN_TEXT , TOKEN_VAR , TOKEN_BLOCK
33from django .utils .translation .trans_real import (
44 inline_re , block_re , endblock_re , plural_re , constant_re )
5+ from django .utils .encoding import smart_unicode
56
67
78def extract_django (fileobj , keywords , comment_tags , options ):
@@ -34,10 +35,18 @@ def extract_django(fileobj, keywords, comment_tags, options):
3435 pluralmatch = plural_re .match (t .contents )
3536 if endbmatch :
3637 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+ []
3944 else :
40- yield lineno , None , unicode ('' .join (singular )), []
45+ yield (
46+ lineno ,
47+ None ,
48+ smart_unicode (u'' .join (singular )),
49+ [])
4150 intrans = False
4251 inplural = False
4352 singular = []
@@ -68,22 +77,22 @@ def extract_django(fileobj, keywords, comment_tags, options):
6877 g = g .strip ('"' )
6978 elif g [0 ] == "'" :
7079 g = g .strip ("'" )
71- yield lineno , None , unicode (g ), []
80+ yield lineno , None , smart_unicode (g ), []
7281 elif bmatch :
7382 for fmatch in constant_re .findall (t .contents ):
74- yield lineno , None , unicode (fmatch ), []
83+ yield lineno , None , smart_unicode (fmatch ), []
7584 intrans = True
7685 inplural = False
7786 singular = []
7887 plural = []
7988 elif cmatches :
8089 for cmatch in cmatches :
81- yield lineno , None , unicode (cmatch ), []
90+ yield lineno , None , smart_unicode (cmatch ), []
8291 elif t .token_type == TOKEN_VAR :
8392 parts = t .contents .split ('|' )
8493 cmatch = constant_re .match (parts [0 ])
8594 if cmatch :
86- yield lineno , None , unicode (cmatch .group (1 )), []
95+ yield lineno , None , smart_unicode (cmatch .group (1 )), []
8796 for p in parts [1 :]:
8897 if p .find (':_(' ) >= 0 :
8998 p1 = p .split (':' , 1 )[1 ]
@@ -95,4 +104,4 @@ def extract_django(fileobj, keywords, comment_tags, options):
95104 p1 = p1 .strip ("'" )
96105 elif p1 [0 ] == '"' :
97106 p1 = p1 .strip ('"' )
98- yield lineno , None , unicode (p1 ), []
107+ yield lineno , None , smart_unicode (p1 ), []
0 commit comments