Skip to content

gh-130197: Test various encodings with pygettext #132244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/ascii.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: ascii.py:7
msgid "foo"
msgstr ""

#. non-ascii text
#: ascii.py:10
msgid "α β"
msgstr ""

10 changes: 10 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/ascii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: ascii -*-

from gettext import gettext as _


# ascii text
_('foo')

# non-ascii text
_('\u03b1 \u03b2')
27 changes: 27 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/ascii_escaped.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: ascii.py:7
msgid "foo"
msgstr ""

#. non-ascii text
#: ascii.py:10
msgid "\316\261 \316\262"
msgstr ""

32 changes: 32 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/latin1.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: latin1.py:7
msgid "foo"
msgstr ""

#. latin-1 text
#: latin1.py:10
msgid "Å ø"
msgstr ""

#. non-latin-1 text
#: latin1.py:13
msgid "α β"
msgstr ""

13 changes: 13 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/latin1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: latin-1 -*-

from gettext import gettext as _


# ascii text
_('foo')

# latin-1 text
_('Å ø')

# non-latin-1 text
_('\u03b1 \u03b2')
32 changes: 32 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/latin1_escaped.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: latin1.py:7
msgid "foo"
msgstr ""

#. latin-1 text
#: latin1.py:10
msgid "\303\205 \303\270"
msgstr ""

#. non-latin-1 text
#: latin1.py:13
msgid "\316\261 \316\262"
msgstr ""

32 changes: 32 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/windows1252.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: windows1252.py:7
msgid "foo"
msgstr ""

#. windows-1252 text
#: windows1252.py:10
msgid "€ ƒ"
msgstr ""

#. non-windows-1252 text
#: windows1252.py:13
msgid "α β"
msgstr ""

13 changes: 13 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/windows1252.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: windows-1252 -*-

from gettext import gettext as _


# ascii text
_('foo')

# windows-1252 text
_('€ ƒ')

# non-windows-1252 text
_('\u03b1 \u03b2')
32 changes: 32 additions & 0 deletions Lib/test/test_tools/i18n_data/encodings/windows1252_escaped.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"


#. ascii text
#: windows1252.py:7
msgid "foo"
msgstr ""

#. windows-1252 text
#: windows1252.py:10
msgid "\342\202\254 \306\222"
msgstr ""

#. non-windows-1252 text
#: windows1252.py:13
msgid "\316\261 \316\262"
msgstr ""

7 changes: 7 additions & 0 deletions Lib/test/test_tools/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ def extract_from_snapshots():
'escapes.py': ('--escape', '--add-comments='),
# Escape only ascii and let unicode pass through:
('escapes.py', 'ascii-escapes.pot'): ('--add-comments=',),
# Test input files with various encodings:
('encodings/ascii.py', 'encodings/ascii.pot'): ('--add-comments=',),
('encodings/ascii.py', 'encodings/ascii_escaped.pot'): ('--add-comments=', '--escape'),
('encodings/latin1.py', 'encodings/latin1.pot'): ('--add-comments=',),
('encodings/latin1.py', 'encodings/latin1_escaped.pot'): ('--add-comments=', '--escape'),
('encodings/windows1252.py', 'encodings/windows1252.pot'): ('--add-comments=',),
('encodings/windows1252.py', 'encodings/windows1252_escaped.pot'): ('--add-comments=', '--escape'),
}

for filename, args in snapshots.items():
Expand Down
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,7 @@ TESTSUBDIRS= idlelib/idle_test \
test/test_tomllib/data/valid/multiline-basic-str \
test/test_tools \
test/test_tools/i18n_data \
test/test_tools/i18n_data/encodings \
test/test_tools/msgfmt_data \
test/test_ttk \
test/test_unittest \
Expand Down
Loading