summaryrefslogtreecommitdiff
path: root/test/check-po-yes-no.py
blob: f5caa873da9c5dd0a7c1269060952bd63f2d6cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /usr/bin/python3 -tt

# This is a simple command to check that "Is this ok [y/N]: " and yes and no
# have either all been translated or none have been translated.

import sys
import glob

from yum.misc import to_utf8

def trans(msg, default):
    if msg == 'msgstr ""\n':
        return str(default, encoding='utf-8')
    if msg.startswith('msgstr "'):
        msg = msg[len('msgstr "'):]
        msg = msg[:-2]
    return str(msg, encoding='utf-8')

for fname in glob.glob("po/*.po"):
    next = None
    is_this_ok  = None
    sis_this_ok = None
    yes         = None
    syes        = None
    y           = None
    sy          = None
    no          = None
    sno         = None
    n           = None
    sn          = None
    for line in file(fname):
        if next is not None:
            if next == 'is_this_ok':
                sis_this_ok = line
                if line == 'msgstr ""\n' or line.find('[y/N]') != -1:
                    is_this_ok = False
                else:
                    is_this_ok = True
            if next == 'yes':
                syes = line
                yes  = line != 'msgstr ""\n'
            if next == 'y':
                sy   = line
                y    = line != 'msgstr ""\n'
            if next == 'no':
                sno  = line
                no   = line != 'msgstr ""\n'
            if next == 'n':
                sn   = line
                n    = line != 'msgstr ""\n'
            next = None
            continue
        if line == 'msgid "Is this ok [y/N]: "\n':
            next = 'is_this_ok'
        if line == 'msgid "yes"\n':
            next = 'yes'
        if line == 'msgid "y"\n':
            next = 'y'
        if line == 'msgid "no"\n':
            next = 'no'
        if line == 'msgid "n"\n':
            next = 'n'
    if (is_this_ok is None or
        yes is None or
        y   is None or
        no  is None or
        n   is None):
        print("""\
ERROR: Can't find all the msg id's in %s
is_this_ok %s
yes %s
y   %s
no  %s
n   %s
""" % (fname,
       is_this_ok is None,
       yes is None,
       y   is None,
       no  is None,
       n   is None), file=sys.stderr)
        sys.exit(1)
    syes = trans(syes, "yes")
    sy   = trans(sy,   "y")
    sno  = trans(sno,  "no")
    sn   = trans(sn,   "n")
    if (is_this_ok != yes or
        is_this_ok != no):
        print("""\
ERROR: yes/no translations don't match in: %s
is_this_ok %5s: %s
yes        %5s: %s
y          %5s: %s
no         %5s: %s
n          %5s: %s
""" % (fname,
       to_utf8(is_this_ok), to_utf8(sis_this_ok),
       to_utf8(yes), to_utf8(syes), to_utf8(y), to_utf8(sy),
       to_utf8(no), to_utf8(sno), to_utf8(n), to_utf8(sn)), file=sys.stderr)
    if syes[0] != sy:
        print("""\
ERROR: yes/y translations don't match in: %s
yes        %5s: %s
y          %5s: %s
""" % (fname,
       yes, syes, y, sy), file=sys.stderr)
    if sno[0] != sn:
        print("""\
ERROR: no/n translations don't match in: %s
no         %5s: %s
n          %5s: %s
""" % (fname,
       no, sno, n, sn), file=sys.stderr)