Skip to content

Commit

Permalink
Support 'Language' header field of PO files (python-babel#76)
Browse files Browse the repository at this point in the history
GNU gettext has support for the 'Language' field in header entry since
version 0.18 (May 2010). This commit adds support for the field and
addresses python-babel#76.
  • Loading branch information
felixonmars committed Aug 5, 2015
1 parent 5c073d7 commit d62ea34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ def _get_mime_headers(self):
else:
headers.append(('PO-Revision-Date', self.revision_date))
headers.append(('Last-Translator', self.last_translator))
if self.locale is not None:
headers.append(('Language', str(self.locale)))
if (self.locale is not None) and ('LANGUAGE' in self.language_team):
headers.append(('Language-Team',
self.language_team.replace('LANGUAGE',
Expand Down
1 change: 1 addition & 0 deletions tests/messages/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def test_catalog_mime_headers_set_locale():
('POT-Creation-Date', '1990-04-01 15:30+0000'),
('PO-Revision-Date', '1990-08-03 12:00+0000'),
('Last-Translator', 'John Doe <[email protected]>'),
('Language', 'de_DE'),
('Language-Team', 'de_DE <[email protected]>'),
('Plural-Forms', 'nplurals=2; plural=(n != 1)'),
('MIME-Version', '1.0'),
Expand Down
9 changes: 9 additions & 0 deletions tests/messages/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def test_with_output_dir(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -409,6 +410,7 @@ def test_keeps_catalog_non_fuzzy(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -459,6 +461,7 @@ def test_correct_init_more_than_2_plurals(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: lv_LV\n"
"Language-Team: lv_LV <[email protected]>\n"
"Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :"
" 2)\n"
Expand Down Expand Up @@ -511,6 +514,7 @@ def test_correct_init_singular_plural_forms(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja_JP\n"
"Language-Team: ja_JP <[email protected]>\n"
"Plural-Forms: nplurals=1; plural=0\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -568,6 +572,7 @@ def test_supports_no_wrap(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -626,6 +631,7 @@ def test_supports_width(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -884,6 +890,7 @@ def test_init_with_output_dir(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -934,6 +941,7 @@ def test_init_singular_plural_forms(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja_JP\n"
"Language-Team: ja_JP <[email protected]>\n"
"Plural-Forms: nplurals=1; plural=0\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -980,6 +988,7 @@ def test_init_more_than_2_plural_forms(self):
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"PO-Revision-Date: %(date)s\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: lv_LV\n"
"Language-Team: lv_LV <[email protected]>\n"
"Plural-Forms: nplurals=3; plural=(n%%10==1 && n%%100!=11 ? 0 : n != 0 ? 1 :"
" 2)\n"
Expand Down

0 comments on commit d62ea34

Please sign in to comment.