@@ -25,6 +25,7 @@ def extract_django(fileobj, keywords, comment_tags, options):
25
25
"""
26
26
intrans = False
27
27
inplural = False
28
+ message_context = None
28
29
singular = []
29
30
plural = []
30
31
lineno = 1
@@ -40,21 +41,41 @@ def extract_django(fileobj, keywords, comment_tags, options):
40
41
pluralmatch = plural_re .match (t .contents )
41
42
if endbmatch :
42
43
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
+ [])
49
60
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
+ [])
55
75
56
76
intrans = False
57
77
inplural = False
78
+ message_context = None
58
79
singular = []
59
80
plural = []
60
81
elif pluralmatch :
@@ -93,9 +114,12 @@ def extract_django(fileobj, keywords, comment_tags, options):
93
114
[smart_text (message_context ), smart_text (g )],
94
115
[],
95
116
)
117
+ message_context = None
96
118
else :
97
119
yield lineno , None , smart_text (g ), []
98
120
elif bmatch :
121
+ if bmatch .group (2 ):
122
+ message_context = bmatch .group (2 )[1 :- 1 ]
99
123
for fmatch in constant_re .findall (t .contents ):
100
124
yield lineno , None , smart_text (fmatch ), []
101
125
intrans = True
0 commit comments