Skip to content

Commit cb081b8

Browse files
committed
Merged revisions 81697 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r81697 | martin.v.loewis | 2010-06-04 20:04:42 +0200 (Fr, 04 Jun 2010) | 2 lines Issue #5464: Implement plural forms in msgfmt.py. ........
1 parent 0b99883 commit cb081b8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@ Tests
15481548
Tools/Demos
15491549
-----------
15501550

1551+
- Issue #5464: Implement plural forms in msgfmt.py.
1552+
15511553
- iobench (a file I/O benchmark) and ccbench (a concurrency benchmark) were
15521554
added to the `Tools/` directory. They were previously living in the
15531555
sandbox.

Tools/i18n/msgfmt.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,39 @@ def make(filename, outfile):
132132
if l[0] == '#':
133133
continue
134134
# Now we are in a msgid section, output previous section
135-
if l.startswith('msgid'):
135+
if l.startswith('msgid') and not l.startswith('msgid_plural'):
136136
if section == STR:
137137
add(msgid, msgstr, fuzzy)
138138
section = ID
139139
l = l[5:]
140140
msgid = msgstr = ''
141+
is_plural = False
142+
# This is a message with plural forms
143+
elif l.startswith('msgid_plural'):
144+
if section != ID:
145+
print('msgid_plural not preceeded by msgid on %s:%d' % (infile, lno),
146+
file=sys.stderr)
147+
sys.exit(1)
148+
l = l[12:]
149+
msgid += '\0' # separator of singular and plural
150+
is_plural = True
141151
# Now we are in a msgstr section
142152
elif l.startswith('msgstr'):
143153
section = STR
144-
l = l[6:]
154+
if l.startswith('msgstr['):
155+
if not is_plural:
156+
print(sys.stderr, 'plural without msgid_plural on %s:%d' % (infile, lno),
157+
file=sys.stderr)
158+
sys.exit(1)
159+
l = l.split(']', 1)[1]
160+
if msgstr:
161+
msgstr += '\0' # Separator of the various plural forms
162+
else:
163+
if is_plural:
164+
print(sys.stderr, 'indexed msgstr required for plural on %s:%d' % (infile, lno),
165+
file=sys.stderr)
166+
sys.exit(1)
167+
l = l[6:]
145168
# Skip empty lines
146169
l = l.strip()
147170
if not l:

0 commit comments

Comments
 (0)