| 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 |
|
|---|
| 6 | import sys
|
|---|
| 7 | import glob
|
|---|
| 8 |
|
|---|
| 9 | from yum.misc import to_utf8
|
|---|
| 10 |
|
|---|
| 11 | def 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 |
|
|---|
| 19 | for 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, """\
|
|---|
| 69 | ERROR: Can't find all the msg id's in %s
|
|---|
| 70 | is_this_ok %s
|
|---|
| 71 | yes %s
|
|---|
| 72 | y %s
|
|---|
| 73 | no %s
|
|---|
| 74 | n %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, """\
|
|---|
| 89 | ERROR: yes/no translations don't match in: %s
|
|---|
| 90 | is_this_ok %5s: %s
|
|---|
| 91 | yes %5s: %s
|
|---|
| 92 | y %5s: %s
|
|---|
| 93 | no %5s: %s
|
|---|
| 94 | n %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, """\
|
|---|
| 101 | ERROR: yes/y translations don't match in: %s
|
|---|
| 102 | yes %5s: %s
|
|---|
| 103 | y %5s: %s
|
|---|
| 104 | """ % (fname,
|
|---|
| 105 | yes, syes, y, sy)
|
|---|
| 106 | if sno[0] != sn:
|
|---|
| 107 | print >>sys.stderr, """\
|
|---|
| 108 | ERROR: no/n translations don't match in: %s
|
|---|
| 109 | no %5s: %s
|
|---|
| 110 | n %5s: %s
|
|---|
| 111 | """ % (fname,
|
|---|
| 112 | no, sno, n, sn)
|
|---|