Debian Codegraph @

translation-canary/translation_canary/translatable/test_markup.py

raw
1 # Check that a string does not contain unnecessary Pango markup
2 #
3 # Copyright (C) 2015 Red Hat, Inc.
4 #
5 # This copyrighted material is made available to anyone wishing to use,
6 # modify, copy, or redistribute it subject to the terms and conditions of
7 # the GNU Lesser General Public License v.2, or (at your option) any later
8 # version. This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY expressed or implied, including the implied
10 # warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 # the GNU Lesser General Public License for more details. You should have
12 # received a copy of the GNU Lesser General Public License along with this
13 # program; if not, write to the Free Software Foundation, Inc., 51 Franklin
14 # Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat trademarks
15 # that are incorporated in the source code or documentation are not subject
16 # to the GNU Lesser General Public License and may only be used or
17 # replicated with the express permission of Red Hat, Inc.
18 #
19 # Red Hat Author(s): David Shea <[email protected]>
20
21 from pocketlint.pangocheck import is_markup, markup_necessary
22 import xml.etree.ElementTree as ET
23
24 def test_markup(poentry):
25 # Unnecessary markup is markup applied to an entire string, such as
26 # _("<b>Bold Text</b>"). This could be instead be translated as
27 # "<b>%s</b>" % _("Bold Text"), and then the translator doesn't have to see
28 # the markup at all.
29
30 if is_markup(poentry.msgid):
31 # Wrap the string in <markup> nodes, parse it, test it
32 # The markup is unescaped on purpose
33 # pylint: disable=unescaped-markup
34 tree = ET.fromstring("<markup>%s</markup>" % poentry.msgid)
35 if not markup_necessary(tree):
36 raise AssertionError("Unnecessary markup")