source: yum/trunk/test/check-po-yes-no.py@ 1569

Last change on this file since 1569 was 2, checked in by Yuri Dario, 15 years ago

Initial import for vendor code.

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1#! /usr/bin/python -tt
2
3# This is a simple command to check that "Is this ok [y/N]: " and yes and no
4# have either all been translated or none have been translated.
5
6import sys
7import glob
8
9from yum.misc import to_utf8
10
11def trans(msg, default):
12 if msg == 'msgstr ""\n':
13 return unicode(default, encoding='utf-8')
14 if msg.startswith('msgstr "'):
15 msg = msg[len('msgstr "'):]
16 msg = msg[:-2]
17 return unicode(msg, encoding='utf-8')
18
19for fname in glob.glob("po/*.po"):
20 next = None
21 is_this_ok = None
22 sis_this_ok = None
23 yes = None
24 syes = None
25 y = None
26 sy = None
27 no = None
28 sno = None
29 n = None
30 sn = None
31 for line in file(fname):
32 if next is not None:
33 if next == 'is_this_ok':
34 sis_this_ok = line
35 if line == 'msgstr ""\n' or line.find('[y/N]') != -1:
36 is_this_ok = False
37 else:
38 is_this_ok = True
39 if next == 'yes':
40 syes = line
41 yes = line != 'msgstr ""\n'
42 if next == 'y':
43 sy = line
44 y = line != 'msgstr ""\n'
45 if next == 'no':
46 sno = line
47 no = line != 'msgstr ""\n'
48 if next == 'n':
49 sn = line
50 n = line != 'msgstr ""\n'
51 next = None
52 continue
53 if line == 'msgid "Is this ok [y/N]: "\n':
54 next = 'is_this_ok'
55 if line == 'msgid "yes"\n':
56 next = 'yes'
57 if line == 'msgid "y"\n':
58 next = 'y'
59 if line == 'msgid "no"\n':
60 next = 'no'
61 if line == 'msgid "n"\n':
62 next = 'n'
63 if (is_this_ok is None or
64 yes is None or
65 y is None or
66 no is None or
67 n is None):
68 print >>sys.stderr, """\
69ERROR: Can't find all the msg id's in %s
70is_this_ok %s
71yes %s
72y %s
73no %s
74n %s
75""" % (fname,
76 is_this_ok is None,
77 yes is None,
78 y is None,
79 no is None,
80 n is None)
81 sys.exit(1)
82 syes = trans(syes, "yes")
83 sy = trans(sy, "y")
84 sno = trans(sno, "no")
85 sn = trans(sn, "n")
86 if (is_this_ok != yes or
87 is_this_ok != no):
88 print >>sys.stderr, """\
89ERROR: yes/no translations don't match in: %s
90is_this_ok %5s: %s
91yes %5s: %s
92y %5s: %s
93no %5s: %s
94n %5s: %s
95""" % (fname,
96 to_utf8(is_this_ok), to_utf8(sis_this_ok),
97 to_utf8(yes), to_utf8(syes), to_utf8(y), to_utf8(sy),
98 to_utf8(no), to_utf8(sno), to_utf8(n), to_utf8(sn))
99 if syes[0] != sy:
100 print >>sys.stderr, """\
101ERROR: yes/y translations don't match in: %s
102yes %5s: %s
103y %5s: %s
104""" % (fname,
105 yes, syes, y, sy)
106 if sno[0] != sn:
107 print >>sys.stderr, """\
108ERROR: no/n translations don't match in: %s
109no %5s: %s
110n %5s: %s
111""" % (fname,
112 no, sno, n, sn)
Note: See TracBrowser for help on using the repository browser.