Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / gettext / msgunfmt.tcl
blob11c1d6f837bba47cacd405f40c370611abad3bf1
1 # Reading tcl/msgcat .msg files.
2 # Copyright (C) 2002 Free Software Foundation, Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace eval msgcat {
18 namespace export mcset mcdump
19 variable header ""
22 proc msgcat::puts_po_string {str} {
23 # Replace " with \"
24 regsub -all "\"" $str "\\\"" str
25 # Replace \ with \\
26 regsub -all "\\\\" $str "\\\\\\" str
27 # Replace newline with \n
28 regsub -all [subst "\n"] $str "\\n" str
29 regsub -all [subst "\a"] $str "\\a" str
30 regsub -all [subst "\b"] $str "\\b" str
31 regsub -all [subst "\f"] $str "\\f" str
32 regsub -all [subst "\r"] $str "\\r" str
33 regsub -all [subst "\t"] $str "\\t" str
34 regsub -all [subst "\v"] $str "\\v" str
35 # Output it.
36 puts -nonewline "\"$str\""
39 proc msgcat::write_po_message {msgid msgstr} {
40 puts -nonewline "msgid "
41 puts_po_string $msgid
42 puts ""
43 puts -nonewline "msgstr "
44 puts_po_string $msgstr
45 puts ""
46 puts ""
49 # This gets called once for each message in the .msg catalog.
50 proc msgcat::mcset {locale src {dest ""}} {
51 msgcat::write_po_message $src $dest
54 # Main function.
55 proc msgcat::mcdump {langfile} {
56 if {[file exists $langfile]} {
57 # msgunfmt expects the output in UTF-8 encoding.
58 fconfigure stdout -encoding utf-8
60 set msgcat::header ""
62 set fd [open $langfile r]
63 # In newer tcl versions, the .msg files are in UTF-8 encoding.
64 fconfigure $fd -encoding utf-8
65 eval [read $fd]
66 close $fd
68 if {$msgcat::header == ""} {
69 # Provide a minimal header.
70 set msgcat::header [subst "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"]
72 msgcat::write_po_message "" $msgcat::header
73 } else {
74 # Tell msgunfmt to emit an internationalized error message.
75 exit 2
79 # Main code: call the main function on the first and only argument.
80 msgcat::mcdump [lindex $argv 0]
82 exit 0