git-gui: Fix bind errors when switching repository chooser panels
[git/jnareb-git.git] / po / po2msg.sh
blobda0765dd8020af359c1f47e8f2ae2e4e72a9ce5b
1 #!/bin/sh
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.
9 proc u2a {s} {
10 set res ""
11 foreach i [split $s ""] {
12 scan $i %c c
13 if {$c<128} {
14 # escape '[', '\' and ']'
15 if {$c == 0x5b || $c == 0x5d} {
16 append res "\\"
18 append res $i
19 } else {
20 append res \\u[format %04.4x $c]
23 return $res
26 set output_directory "."
27 set lang "dummy"
28 set files [list]
30 # parse options
31 for {set i 1} {$i < $argc} {incr i} {
32 set arg [lindex $argv $i]
33 if {$arg == "--statistics" || $arg == "--tcl"} {
34 continue
36 if {$arg == "-l"} {
37 incr i
38 set lang [lindex $argv $i]
39 continue
41 if {$arg == "-d"} {
42 incr i
43 set tmp [lindex $argv $i]
44 regsub "\[^/\]$" $tmp "&/" output_directory
45 continue
47 lappend files $arg
50 proc flush_msg {} {
51 global msgid msgstr mode lang out
53 if {![info exists msgid] || $mode == ""} {
54 return
56 set mode ""
58 if {$msgid == ""} {
59 set prefix "set ::msgcat::header"
60 } else {
61 set prefix "::msgcat::mcset $lang \"[u2a $msgid]\""
64 puts $out "$prefix \"[u2a $msgstr]\""
67 foreach file $files {
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"]
73 set mode ""
74 while {[gets $in line] >= 0} {
75 if {[regexp "^#" $line]} {
76 flush_msg
77 continue
78 } elseif {[regexp "^msgid \"(.*)\"$" $line dummy match]} {
79 flush_msg
80 set msgid $match
81 set mode "msgid"
82 } elseif {[regexp "^msgstr \"(.*)\"$" $line dummy match]} {
83 set msgstr $match
84 set mode "msgstr"
85 } elseif {$line == ""} {
86 flush_msg
87 } elseif {[regexp "^\"(.*)\"$" $line dummy match]} {
88 if {$mode == "msgid"} {
89 append msgid $match
90 } elseif {$mode == "msgstr"} {
91 append msgstr $match
92 } else {
93 puts stderr "I do not know what to do: $match"
95 } else {
96 puts stderr "Cannot handle $line"
99 flush_msg
100 close $in
101 close $out