jpayne@68: # Reading tcl/msgcat .msg files. jpayne@68: # Copyright (C) 2002 Free Software Foundation, Inc. jpayne@68: # jpayne@68: # This program is free software: you can redistribute it and/or modify jpayne@68: # it under the terms of the GNU General Public License as published by jpayne@68: # the Free Software Foundation; either version 3 of the License, or jpayne@68: # (at your option) any later version. jpayne@68: # jpayne@68: # This program is distributed in the hope that it will be useful, jpayne@68: # but WITHOUT ANY WARRANTY; without even the implied warranty of jpayne@68: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jpayne@68: # GNU General Public License for more details. jpayne@68: # jpayne@68: # You should have received a copy of the GNU General Public License jpayne@68: # along with this program. If not, see . jpayne@68: jpayne@68: namespace eval msgcat { jpayne@68: namespace export mcset mcdump jpayne@68: variable header "" jpayne@68: } jpayne@68: jpayne@68: proc msgcat::puts_po_string {str} { jpayne@68: # Replace " with \" jpayne@68: regsub -all "\"" $str "\\\"" str jpayne@68: # Replace \ with \\ jpayne@68: regsub -all "\\\\" $str "\\\\\\" str jpayne@68: # Replace newline with \n jpayne@68: regsub -all [subst "\n"] $str "\\n" str jpayne@68: regsub -all [subst "\a"] $str "\\a" str jpayne@68: regsub -all [subst "\b"] $str "\\b" str jpayne@68: regsub -all [subst "\f"] $str "\\f" str jpayne@68: regsub -all [subst "\r"] $str "\\r" str jpayne@68: regsub -all [subst "\t"] $str "\\t" str jpayne@68: regsub -all [subst "\v"] $str "\\v" str jpayne@68: # Output it. jpayne@68: puts -nonewline "\"$str\"" jpayne@68: } jpayne@68: jpayne@68: proc msgcat::write_po_message {msgid msgstr} { jpayne@68: puts -nonewline "msgid " jpayne@68: puts_po_string $msgid jpayne@68: puts "" jpayne@68: puts -nonewline "msgstr " jpayne@68: puts_po_string $msgstr jpayne@68: puts "" jpayne@68: puts "" jpayne@68: } jpayne@68: jpayne@68: # This gets called once for each message in the .msg catalog. jpayne@68: proc msgcat::mcset {locale src {dest ""}} { jpayne@68: msgcat::write_po_message $src $dest jpayne@68: } jpayne@68: jpayne@68: # Main function. jpayne@68: proc msgcat::mcdump {langfile} { jpayne@68: if {[file exists $langfile]} { jpayne@68: # msgunfmt expects the output in UTF-8 encoding. jpayne@68: fconfigure stdout -encoding utf-8 jpayne@68: jpayne@68: set msgcat::header "" jpayne@68: jpayne@68: set fd [open $langfile r] jpayne@68: # In newer tcl versions, the .msg files are in UTF-8 encoding. jpayne@68: fconfigure $fd -encoding utf-8 jpayne@68: eval [read $fd] jpayne@68: close $fd jpayne@68: jpayne@68: if {$msgcat::header == ""} { jpayne@68: # Provide a minimal header. jpayne@68: set msgcat::header [subst "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"] jpayne@68: } jpayne@68: msgcat::write_po_message "" $msgcat::header jpayne@68: } else { jpayne@68: # Tell msgunfmt to emit an internationalized error message. jpayne@68: exit 2 jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: # Main code: call the main function on the first and only argument. jpayne@68: msgcat::mcdump [lindex $argv 0] jpayne@68: jpayne@68: exit 0