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