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} {
20 append res \\u[format %04.4x $c]
26 set output_directory "."
31 for {set i 1} {$i < $argc} {incr i} {
32 set arg [lindex $argv $i]
33 if {$arg == "--statistics" || $arg == "--tcl"} {
38 set lang [lindex $argv $i]
43 set tmp [lindex $argv $i]
44 regsub "\[^/\]$" $tmp "&/" output_directory
51 global msgid msgstr mode lang out
53 if {![info exists msgid] || $mode == ""} {
59 set prefix "set ::msgcat::header"
61 set prefix "::msgcat::mcset $lang \"[u2a $msgid]\""
64 puts $out "$prefix \"[u2a $msgstr]\""
68 regsub "^.*/\(\[^/\]*\)\.po$" $file "$output_directory\\1.msg" outfile
69 set in [open $file "r"]
70 fconfigure $in -encoding utf-8
71 set out [open $outfile "w"]
74 while {[gets $in line] >= 0} {
75 if {[regexp "^#" $line]} {
78 } elseif {[regexp "^msgid \"(.*)\"$" $line dummy match]} {
82 } elseif {[regexp "^msgstr \"(.*)\"$" $line dummy match]} {
85 } elseif {$line == ""} {
87 } elseif {[regexp "^\"(.*)\"$" $line dummy match]} {
88 if {$mode == "msgid"} {
90 } elseif {$mode == "msgstr"} {
93 puts stderr "I do not know what to do: $match"
96 puts stderr "Cannot handle $line"