blob: 6a71f64c1b27bc2e0df568513685b94882502f0a (
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
|
#!/usr/bin/tclsh
#
# We check each tranlated message against its original,
# making certain consistency checks.
# In theory this would be easy: we could read the .po file
# directly. But the format of the .po file is not documented.
# Looking at the source code for the po parser in GNU gettext,
# the syntax is complicated with a wide variety of escapes.
#
# So I would prefer to reuse the gettext parser. That means getting
# the output from gettext in some other format. Most of the gettext
# utilities output in annoying formats. The least annoying seems
# to be to use msgfmt to generate a tcl file (!)
# usage:
# cd po4a
# ./pairwise-potcheck [LANG]
proc badusage {} {
puts stderr "usage: ./pairwise-pocheck [LANG]"
exit 1
}
set lang *
set bad 0
proc bad {emsg} {
global po for_emsg bad
puts stderr "$po: $emsg $for_emsg"
incr bad
}
proc check_equal {desc script} {
upvar 1 m m
foreach is {id str} {
set m [uplevel 1 [list set msg$is]]
set m$is $m
set r$is [uplevel 1 $script]
}
if {![string compare $rid $rstr]} { return 0 }
bad "mismatch $rid != $rstr $desc"
}
# called directly by msgfmt output
namespace eval ::msgcat {
proc mcset {lang msgid msgstr} {
check_msg $msgid $msgstr
}
}
proc check_msg {msgid msgstr} {
global for_emsg
set for_emsg "msgid=[list $msgid] msgstr=[list $msgstr]"
check_equal "un-escaped non-pod < count (missing B or I?)" {
regexp -all {(?!\b[IBCLEFSXZ])\<} $m
}
}
proc check {} {
# msgfmt --tcl wants to use a pretty much fixed filename:
# you get to specify part of it but it has to look like a
# locale. But we can specify ya directory to use, so
# one directory per po it is!
global po
set vexdir ".$po.pwpc.tmp"
set vexleaf xx.msg
set vexfile $vexdir/$vexleaf
file mkdir $vexdir
file delete $vexfile
exec msgfmt -d$vexdir -lxx --tcl $po
# and then we execute it!
source $vexfile
}
proc parseargs {} {
global argv lang
switch -glob [llength $argv].$argv {
0. { }
1.-* { badusage }
1.* { set lang [lindex $argv 0] }
* { badusage }
}
}
proc iterate {} {
global po lang
foreach po [lsort [glob -nocomplain *.$lang.po]] {
check
puts "pairwise-pocheck $po ok."
}
}
proc report {} {
global bad
if {$bad} {
puts stderr "pairwise-pocheck: $bad errors"
exit 1
}
}
parseargs
iterate
report
|