Skip to content

Commit

Permalink
Plural-Forms: Fix missing trailing semicolon
Browse files Browse the repository at this point in the history
Adds missing semicolon in the code that generates the header that
is Catalog.plural_forms as well as in plural.to_gettext function.
Also modifies all the concerning test cases as well as test data files.

Closes #836
  • Loading branch information
farhan5900 authored and akx committed Apr 8, 2022
1 parent d938794 commit 4a6e86f
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions babel/messages/catalog.py
Expand Up @@ -474,7 +474,7 @@ def _set_mime_headers(self, headers):
Last-Translator: John Doe <jd@example.com>
Language: de_DE
Language-Team: de_DE <de@example.com>
Plural-Forms: nplurals=2; plural=(n != 1)
Plural-Forms: nplurals=2; plural=(n != 1);
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Expand Down Expand Up @@ -524,12 +524,12 @@ def plural_forms(self):
"""Return the plural forms declaration for the locale.
>>> Catalog(locale='en').plural_forms
'nplurals=2; plural=(n != 1)'
'nplurals=2; plural=(n != 1);'
>>> Catalog(locale='pt_BR').plural_forms
'nplurals=2; plural=(n > 1)'
'nplurals=2; plural=(n > 1);'
:type: `str`"""
return 'nplurals=%s; plural=%s' % (self.num_plurals, self.plural_expr)
return 'nplurals=%s; plural=%s;' % (self.num_plurals, self.plural_expr)

def __contains__(self, id):
"""Return whether the catalog has a message with the specified ID."""
Expand Down
4 changes: 2 additions & 2 deletions babel/plural.py
Expand Up @@ -233,7 +233,7 @@ def to_gettext(rule):
technically limited to integers and returns indices rather than tags.
>>> to_gettext({'one': 'n is 1', 'two': 'n is 2'})
'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)'
'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2);'
:param rule: the rules as list or dict, or a `PluralRule` object
:raise RuleError: if the expression is malformed
Expand All @@ -247,7 +247,7 @@ def to_gettext(rule):
result = ['nplurals=%d; plural=(' % len(used_tags)]
for tag, ast in rule.abstract:
result.append('%s ? %d : ' % (_compile(ast), _get_index(tag)))
result.append('%d)' % _get_index(_fallback_tag))
result.append('%d);' % _get_index(_fallback_tag))
return ''.join(result)


Expand Down
Expand Up @@ -12,7 +12,7 @@ msgstr ""
"PO-Revision-Date: 2007-07-30 22:18+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de_DE <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/messages/data/project/i18n/de_DE/LC_MESSAGES/bar.po
Expand Up @@ -12,7 +12,7 @@ msgstr ""
"PO-Revision-Date: 2007-07-30 22:18+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de_DE <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/messages/data/project/i18n/de_DE/LC_MESSAGES/foo.po
Expand Up @@ -12,7 +12,7 @@ msgstr ""
"PO-Revision-Date: 2007-07-30 22:18+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de_DE <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Expand Up @@ -13,7 +13,7 @@ msgstr ""
"PO-Revision-Date: 2007-07-30 22:18+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de_DE <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Expand Up @@ -14,7 +14,7 @@ msgstr ""
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: ru_RU <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
6 changes: 3 additions & 3 deletions tests/messages/test_catalog.py
Expand Up @@ -386,7 +386,7 @@ def test_catalog_mime_headers_set_locale():
('Last-Translator', 'John Doe <jd@example.com>'),
('Language', 'de_DE'),
('Language-Team', 'de_DE <de@example.com>'),
('Plural-Forms', 'nplurals=2; plural=(n != 1)'),
('Plural-Forms', 'nplurals=2; plural=(n != 1);'),
('MIME-Version', '1.0'),
('Content-Type', 'text/plain; charset=utf-8'),
('Content-Transfer-Encoding', '8bit'),
Expand All @@ -407,9 +407,9 @@ def test_catalog_plural_expr():

def test_catalog_plural_forms():
assert (catalog.Catalog(locale='en').plural_forms
== 'nplurals=2; plural=(n != 1)')
== 'nplurals=2; plural=(n != 1);')
assert (catalog.Catalog(locale='pt_BR').plural_forms
== 'nplurals=2; plural=(n > 1)')
== 'nplurals=2; plural=(n > 1);')


def test_catalog_setitem():
Expand Down
12 changes: 6 additions & 6 deletions tests/messages/test_checkers.py
Expand Up @@ -50,7 +50,7 @@ def test_1_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: %(locale)s <LL@li.org>\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_2_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: %(locale)s <LL@li.org>\\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=utf-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_3_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: %(locale)s <LL@li.org>\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_4_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: %(locale)s <LL@li.org>\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_5_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: %(locale)s <LL@li.org>\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -324,7 +324,7 @@ def test_6_num_plurals_checkers(self):
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: %(locale)s <LL@li.org>\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s\n"
"Plural-Forms: nplurals=%(num_plurals)s; plural=%(plural_expr)s;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
18 changes: 9 additions & 9 deletions tests/messages/test_frontend.py
Expand Up @@ -404,7 +404,7 @@ def test_with_output_dir(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_keeps_catalog_non_fuzzy(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -509,7 +509,7 @@ def test_correct_init_more_than_2_plurals(self):
"Language: lv_LV\n"
"Language-Team: lv_LV <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :"
" 2)\n"
" 2);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_correct_init_singular_plural_forms(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja_JP\n"
"Language-Team: ja_JP <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -621,7 +621,7 @@ def test_supports_no_wrap(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -681,7 +681,7 @@ def test_supports_width(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -985,7 +985,7 @@ def test_init_with_output_dir(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def test_init_singular_plural_forms(self):
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja_JP\n"
"Language-Team: ja_JP <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def test_init_more_than_2_plural_forms(self):
"Language: lv_LV\n"
"Language-Team: lv_LV <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :"
" 2)\n"
" 2);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
8 changes: 4 additions & 4 deletions tests/messages/test_pofile.py
Expand Up @@ -58,7 +58,7 @@ def test_applies_specified_encoding_during_read(self):
"PO-Revision-Date: 2007-09-27 21:42-0700\\n"
"Last-Translator: John <cleese@bavaria.de>\\n"
"Language-Team: German Lang <de@babel.org>\\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=iso-8859-1\\n"
"Content-Transfer-Encoding: 8bit\\n"
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_header_entry(self):
"Last-Translator: John <cleese@bavaria.de>\n"
"Language: de\n"
"Language-Team: German Lang <de@babel.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-2\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_missing_plural(self):
buf = StringIO('''\
msgid ""
msgstr ""
"Plural-Forms: nplurals=3; plural=(n < 2) ? n : 2\n"
"Plural-Forms: nplurals=3; plural=(n < 2) ? n : 2;\n"
msgid "foo"
msgid_plural "foos"
Expand All @@ -412,7 +412,7 @@ def test_missing_plural_in_the_middle(self):
buf = StringIO('''\
msgid ""
msgstr ""
"Plural-Forms: nplurals=3; plural=(n < 2) ? n : 2\n"
"Plural-Forms: nplurals=3; plural=(n < 2) ? n : 2;\n"
msgid "foo"
msgid_plural "foos"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plural.py
Expand Up @@ -84,7 +84,7 @@ def test_to_python():

def test_to_gettext():
assert (plural.to_gettext({'one': 'n is 1', 'two': 'n is 2'})
== 'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)')
== 'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2);')


def test_in_range_list():
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_plural_within_rules():
" ? 'few' : (n == 1) ? 'one' : 'other'; })")
assert plural.to_gettext(p) == (
'nplurals=3; plural=(((n == 2) || (n == 4) || (n >= 7 && n <= 9))'
' ? 1 : (n == 1) ? 0 : 2)')
' ? 1 : (n == 1) ? 0 : 2);')
assert p(0) == 'other'
assert p(1) == 'one'
assert p(2) == 'few'
Expand Down

0 comments on commit 4a6e86f

Please sign in to comment.