2 # Tcl ignores the next line -*- tcl -*- \
3 exec tclsh
"$0" -- "$@"
5 # This is a really stupid program, which serves as an alternative to
6 # msgfmt. It _only_ translates to Tcl mode, does _not_ validate the
7 # input, and does _not_ output any statistics.
11 foreach i
[split $s ""] {
14 # escape '[', '\', '$' and ']'
15 if {$c == 0x5b ||
$c == 0x5d ||
$c == 0x24} {
20 append res
\\u
[format
%04.4x
$c]
26 set output_directory
"."
32 for {set i
0} {$i < $argc} {incr i
} {
33 set arg
[lindex
$argv $i]
34 if {$arg == "--statistics"} {
38 if {$arg == "--tcl"} {
44 set lang
[lindex
$argv $i]
49 set tmp
[lindex
$argv $i]
50 regsub
"\[^/\]$" $tmp "&/" output_directory
57 global msgid msgstr mode lang out fuzzy
58 global translated_count fuzzy_count not_translated_count
60 if {![info exists msgid
] ||
$mode == ""} {
71 set prefix
"set ::msgcat::header"
74 incr not_translated_count
77 set prefix
"::msgcat::mcset $lang \"[u2a $msgid]\""
81 puts
$out "$prefix \"[u2a $msgstr]\""
85 set translated_count
0
87 set not_translated_count
0
89 regsub
"^.*/\(\[^/\]*\)\.po$" $file "$output_directory\\1.msg" outfile
90 set in [open
$file "r"]
91 fconfigure
$in -encoding utf-8
92 set out
[open
$outfile "w"]
95 while {[gets
$in line
] >= 0} {
96 if {[regexp
"^#" $line]} {
97 if {[regexp
", fuzzy" $line]} {
103 } elseif
{[regexp
"^msgid \"(.*)\"$" $line dummy match
]} {
107 } elseif
{[regexp
"^msgstr \"(.*)\"$" $line dummy match
]} {
110 } elseif
{$line == ""} {
112 } elseif
{[regexp
"^\"(.*)\"$" $line dummy match
]} {
113 if {$mode == "msgid"} {
115 } elseif
{$mode == "msgstr"} {
118 puts stderr
"I do not know what to do: $match"
121 puts stderr
"Cannot handle $line"
129 if {$show_statistics} {
132 append str
"$translated_count translated message"
133 if {$translated_count != 1} {
137 if {$fuzzy_count > 1} {
138 append str
", $fuzzy_count fuzzy translation"
139 if {$fuzzy_count != 1} {
143 if {$not_translated_count > 0} {
144 append str
", $not_translated_count untranslated message"
145 if {$not_translated_count != 1} {