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