#18128: use standard +NNNN timezone format in POT-Creation-Date header. · pythoncapi/cpython@2b78129 · GitHub
Skip to content

Commit 2b78129

Browse files
committed
python#18128: use standard +NNNN timezone format in POT-Creation-Date header.
Patch by Michael McFadden, with a few small style tweaks.
1 parent 29fbd21 commit 2b78129

5 files changed

Lines changed: 77 additions & 3 deletions

File tree

Doc/whatsnew/3.5.rst

Lines changed: 4 additions & 0 deletions

Lib/test/test_tools/test_i18n.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Tests to cover the Tools/i18n package"""
2+
3+
import os
4+
import unittest
5+
6+
from test.script_helper import assert_python_ok
7+
from test.test_tools import toolsdir
8+
from test.support import temp_cwd
9+
10+
class Test_pygettext(unittest.TestCase):
11+
"""Tests for the pygettext.py tool"""
12+
13+
script = os.path.join(toolsdir,'i18n', 'pygettext.py')
14+
15+
def get_header(self, data):
16+
""" utility: return the header of a .po file as a dictionary """
17+
headers = {}
18+
for line in data.split('\n'):
19+
if not line or line.startswith(('#', 'msgid','msgstr')):
20+
continue
21+
line = line.strip('"')
22+
key, val = line.split(':',1)
23+
headers[key] = val.strip()
24+
return headers
25+
26+
def test_header(self):
27+
"""Make sure the required fields are in the header, according to:
28+
http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
29+
"""
30+
with temp_cwd(None) as cwd:
31+
assert_python_ok(self.script)
32+
with open('messages.pot') as fp:
33+
data = fp.read()
34+
header = self.get_header(data)
35+
36+
self.assertIn("Project-Id-Version", header)
37+
self.assertIn("POT-Creation-Date", header)
38+
self.assertIn("PO-Revision-Date", header)
39+
self.assertIn("Last-Translator", header)
40+
self.assertIn("Language-Team", header)
41+
self.assertIn("MIME-Version", header)
42+
self.assertIn("Content-Type", header)
43+
self.assertIn("Content-Transfer-Encoding", header)
44+
self.assertIn("Generated-By", header)
45+
46+
# not clear if these should be required in POT (template) files
47+
#self.assertIn("Report-Msgid-Bugs-To", header)
48+
#self.assertIn("Language", header)
49+
50+
#"Plural-Forms" is optional
51+
52+
53+
def test_POT_Creation_Date(self):
54+
""" Match the date format from xgettext for POT-Creation-Date """
55+
from datetime import datetime
56+
with temp_cwd(None) as cwd:
57+
assert_python_ok(self.script)
58+
with open('messages.pot') as fp:
59+
data = fp.read()
60+
header = self.get_header(data)
61+
creationDate = header['POT-Creation-Date']
62+
63+
# peel off the escaped newline at the end of string
64+
if creationDate.endswith('\\n'):
65+
creationDate = creationDate[:-len('\\n')]
66+
67+
# This will raise if the date format does not exactly match.
68+
datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z')

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ Jack McCracken
911911
Rebecca McCreary
912912
Kirk McDonald
913913
Chris McDonough
914+
Michael McFadden
914915
Greg McFarlane
915916
Alan McIntyre
916917
Jessica McKellar

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ Tests
187187
Tools/Demos
188188
-----------
189189

190+
- Issue #18128: pygettext now uses standard +NNNN format in the
191+
POT-Creation-Date header.
192+
190193
- Issue #23935: Argument Clinic's understanding of format units
191194
accepting bytes, bytearrays, and buffers is now consistent with
192195
both the documentation and the implementation.

Tools/i18n/pygettext.py

Lines changed: 1 addition & 3 deletions

0 commit comments

Comments
 (0)