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 2, or (at your option)
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, write to the Free Software Foundation,
16
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
namespace eval msgcat {
19
namespace export mcset mcdump
23
proc msgcat::puts_po_string {str} {
25
regsub -all "\"" $str "\\\"" str
27
regsub -all "\\\\" $str "\\\\\\" str
28
# Replace newline with \n
29
regsub -all [subst "\n"] $str "\\n" str
30
regsub -all [subst "\a"] $str "\\a" str
31
regsub -all [subst "\b"] $str "\\b" str
32
regsub -all [subst "\f"] $str "\\f" str
33
regsub -all [subst "\r"] $str "\\r" str
34
regsub -all [subst "\t"] $str "\\t" str
35
regsub -all [subst "\v"] $str "\\v" str
37
puts -nonewline "\"$str\""
40
proc msgcat::write_po_message {msgid msgstr} {
41
puts -nonewline "msgid "
44
puts -nonewline "msgstr "
45
puts_po_string $msgstr
50
# This gets called once for each message in the .msg catalog.
51
proc msgcat::mcset {locale src {dest ""}} {
52
msgcat::write_po_message $src $dest
56
proc msgcat::mcdump {langfile} {
57
if {[file exists $langfile]} {
58
# msgunfmt expects the output in UTF-8 encoding.
59
fconfigure stdout -encoding utf-8
63
set fd [open $langfile r]
64
# In newer tcl versions, the .msg files are in UTF-8 encoding.
65
fconfigure $fd -encoding utf-8
69
if {$msgcat::header == ""} {
70
# Provide a minimal header.
71
set msgcat::header [subst "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"]
73
msgcat::write_po_message "" $msgcat::header
75
# Tell msgunfmt to emit an internationalized error message.
80
# Main code: call the main function on the first and only argument.
81
msgcat::mcdump [lindex $argv 0]