@matheusbsbs / matheus-bagliano / commits / cd38c86fd8
Fork 0

git-gui: add a simple msgfmt replacement

The program "msgfmt" was our only dependency on gettext. Since it is more than just a hassle to compile gettext on MinGW, here is a (very simple) drop-in replacement, which Works For Us. [sp: Changed Makefile to enable/disable po2msg.sh by the new NO_MSGFMT variable.] Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Johannes Schindelin committed Sep 24, 2007 at 23:24 UTC cd38c86fd8e8fbbc1d83b80f7d96cf19d8266196
2 files changed +113 -1
Makefile
+10 -1
@@ -2,6 +2,10 @@ all::
2
3 # Define V=1 to have a more verbose compile.
4 #
5 +# Define NO_MSGFMT if you do not have msgfmt from the GNU gettext
6 +# package and want to use our rough pure Tcl po->msg translator.
7 +# TCL_PATH must be vaild for this to work.
8 +#
9
10 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
11 @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -129,7 +133,12 @@ $(GITGUI_BUILT_INS): git-gui
133 $(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@
134
135 XGETTEXT ?= xgettext
132 -MSGFMT ?= msgfmt
136 +ifdef NO_MSGFMT
137 + MSGFMT ?= $(TCL_PATH) po/po2msg.sh
138 +else
139 + MSGFMT ?= msgfmt
140 +endif
141 +
142 msgsdir = $(gg_libdir)/msgs
143 msgsdir_SQ = $(subst ','\'',$(msgsdir))
144 PO_TEMPLATE = po/git-gui.pot
po/po2msg.sh new
+103
@@ -0,0 +1,103 @@
1 +#!/bin/sh
2 +# Tcl ignores the next line -*- tcl -*- \
3 +exec tclsh "$0" -- "$@"
4 +
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.
8 +
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 "\\"
17 + }
18 + append res $i
19 + } else {
20 + append res \\u[format %04.4x $c]
21 + }
22 + }
23 + return $res
24 +}
25 +
26 +set output_directory "."
27 +set lang "dummy"
28 +set files [list]
29 +
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
35 + }
36 + if {$arg == "-l"} {
37 + incr i
38 + set lang [lindex $argv $i]
39 + continue
40 + }
41 + if {$arg == "-d"} {
42 + incr i
43 + set tmp [lindex $argv $i]
44 + regsub "\[^/\]$" $tmp "&/" output_directory
45 + continue
46 + }
47 + lappend files $arg
48 +}
49 +
50 +proc flush_msg {} {
51 + global msgid msgstr mode lang out
52 +
53 + if {![info exists msgid] || $mode == ""} {
54 + return
55 + }
56 + set mode ""
57 +
58 + if {$msgid == ""} {
59 + set prefix "set ::msgcat::header"
60 + } else {
61 + set prefix "::msgcat::mcset $lang \"[u2a $msgid]\""
62 + }
63 +
64 + puts $out "$prefix \"[u2a $msgstr]\""
65 +}
66 +
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"]
72 +
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"
94 + }
95 + } else {
96 + puts stderr "Cannot handle $line"
97 + }
98 + }
99 + flush_msg
100 + close $in
101 + close $out
102 +}
103 +