@@ -25,6 +25,7 @@ def extract_django(fileobj, keywords, comment_tags, options):
2525 """
2626 intrans = False
2727 inplural = False
28+ message_context = None
2829 singular = []
2930 plural = []
3031 lineno = 1
@@ -40,21 +41,41 @@ def extract_django(fileobj, keywords, comment_tags, options):
4041 pluralmatch = plural_re .match (t .contents )
4142 if endbmatch :
4243 if inplural :
43- yield (
44- lineno ,
45- 'ngettext' ,
46- (smart_text (u'' .join (singular )),
47- smart_text (u'' .join (plural ))),
48- [])
44+ if message_context :
45+ yield (
46+ lineno ,
47+ 'npgettext' ,
48+ [smart_text (message_context ),
49+ smart_text (u'' .join (singular )),
50+ smart_text (u'' .join (plural ))],
51+ [],
52+ )
53+ else :
54+ yield (
55+ lineno ,
56+ 'ngettext' ,
57+ (smart_text (u'' .join (singular )),
58+ smart_text (u'' .join (plural ))),
59+ [])
4960 else :
50- yield (
51- lineno ,
52- None ,
53- smart_text (u'' .join (singular )),
54- [])
61+ if message_context :
62+ yield (
63+ lineno ,
64+ 'pgettext' ,
65+ [smart_text (message_context ),
66+ smart_text (u'' .join (singular ))],
67+ [],
68+ )
69+ else :
70+ yield (
71+ lineno ,
72+ None ,
73+ smart_text (u'' .join (singular )),
74+ [])
5575
5676 intrans = False
5777 inplural = False
78+ message_context = None
5879 singular = []
5980 plural = []
6081 elif pluralmatch :
@@ -93,9 +114,12 @@ def extract_django(fileobj, keywords, comment_tags, options):
93114 [smart_text (message_context ), smart_text (g )],
94115 [],
95116 )
117+ message_context = None
96118 else :
97119 yield lineno , None , smart_text (g ), []
98120 elif bmatch :
121+ if bmatch .group (2 ):
122+ message_context = bmatch .group (2 )[1 :- 1 ]
99123 for fmatch in constant_re .findall (t .contents ):
100124 yield lineno , None , smart_text (fmatch ), []
101125 intrans = True
0 commit comments