From 00546bc09f65878c8adae90f4a88dac432b5e47c Mon Sep 17 00:00:00 2001 From: stanton Date: Fri, 4 Dec 1998 18:52:40 +0000 Subject: * library/msgcat1.0/msgcat.tcl: * library/msgcat1.0/pkgIndex.tcl: Added initial implementaion of Tcl message catalog package contributed by Mark Harrison. --- library/msgcat/msgcat.tcl | 92 ++++++++++++++++++++++++++++++++++++++++++ library/msgcat/pkgIndex.tcl | 1 + library/msgcat1.0/msgcat.tcl | 92 ++++++++++++++++++++++++++++++++++++++++++ library/msgcat1.0/pkgIndex.tcl | 1 + 4 files changed, 186 insertions(+) create mode 100644 library/msgcat/msgcat.tcl create mode 100644 library/msgcat/pkgIndex.tcl create mode 100644 library/msgcat1.0/msgcat.tcl create mode 100644 library/msgcat1.0/pkgIndex.tcl diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl new file mode 100644 index 0000000..cfe1fde --- /dev/null +++ b/library/msgcat/msgcat.tcl @@ -0,0 +1,92 @@ +# msgcat.tcl -- +# +# This file defines various procedures which implement a +# message catalog facility for Tcl programs. It should be +# loaded with the command "package require msgcat". +# +# Copyright (c) 1998 by Mark Harrison. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# $Id: msgcat.tcl,v 1.1.2.1 1998/12/04 18:52:40 stanton Exp $ +# + +#--------------------------------------------------------------- +# message catalog procedures +#--------------------------------------------------------------- + +namespace eval msgcat { + set _locale "" + set _loclist {} + + proc mc {src} { + set ns [uplevel {namespace current}] + foreach loc $::msgcat::_loclist { + if {[info exists ::msgcat::_msg($loc,$ns,$src)]} { + return $::msgcat::_msg($loc,$ns,$src) + } + } + # we have not found the translation + return [mcunknown $::msgcat::_locale $src] + } + + proc mclocale {args} { + set len [llength $args] + if {$len == 0} { + return $::msgcat::_locale + } elseif {$len == 1} { + set ::msgcat::_locale $args + set ::msgcat::_loclist {} + set word "" + foreach part [split $args _] { + set word [string trimleft "${word}_${part}" _] + set ::msgcat::_loclist \ + [linsert $::msgcat::_loclist 0 $word] + } + } else { + # incorrect argument count + error {called "mclocale" with too many arguments} + } + } + + proc mcpreferences {} { + return $::msgcat::_loclist + } + + proc mcload {langdir} { + foreach p [::msgcat::mcpreferences] { + set langfile $langdir/$p.msg + if {[file exists $langfile]} { + uplevel [list source $langfile] + } + } + } + + proc mcset {locale src {dest ""}} { + if {[string compare "" $dest] == 0} { + set dest $src + } + + set ns [uplevel {namespace current}] + + set ::msgcat::_msg($locale,$ns,$src) $dest + } + + proc mcunknown {locale src} { + return $src + } + + # set default locale try to get from environment + if {[info exists ::env(LANG)]} { + mclocale $::env(LANG) + } else { + mclocale "C" + } + + namespace export mc mcset mclocale mclocales mcunknown +} + +package provide msgcat 1.0 + +#eof: msgcat.tcl diff --git a/library/msgcat/pkgIndex.tcl b/library/msgcat/pkgIndex.tcl new file mode 100644 index 0000000..b40a4f3 --- /dev/null +++ b/library/msgcat/pkgIndex.tcl @@ -0,0 +1 @@ +package ifneeded msgcat 1.0 [list source [file join $dir msgcat.tcl]] diff --git a/library/msgcat1.0/msgcat.tcl b/library/msgcat1.0/msgcat.tcl new file mode 100644 index 0000000..cfe1fde --- /dev/null +++ b/library/msgcat1.0/msgcat.tcl @@ -0,0 +1,92 @@ +# msgcat.tcl -- +# +# This file defines various procedures which implement a +# message catalog facility for Tcl programs. It should be +# loaded with the command "package require msgcat". +# +# Copyright (c) 1998 by Mark Harrison. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# $Id: msgcat.tcl,v 1.1.2.1 1998/12/04 18:52:40 stanton Exp $ +# + +#--------------------------------------------------------------- +# message catalog procedures +#--------------------------------------------------------------- + +namespace eval msgcat { + set _locale "" + set _loclist {} + + proc mc {src} { + set ns [uplevel {namespace current}] + foreach loc $::msgcat::_loclist { + if {[info exists ::msgcat::_msg($loc,$ns,$src)]} { + return $::msgcat::_msg($loc,$ns,$src) + } + } + # we have not found the translation + return [mcunknown $::msgcat::_locale $src] + } + + proc mclocale {args} { + set len [llength $args] + if {$len == 0} { + return $::msgcat::_locale + } elseif {$len == 1} { + set ::msgcat::_locale $args + set ::msgcat::_loclist {} + set word "" + foreach part [split $args _] { + set word [string trimleft "${word}_${part}" _] + set ::msgcat::_loclist \ + [linsert $::msgcat::_loclist 0 $word] + } + } else { + # incorrect argument count + error {called "mclocale" with too many arguments} + } + } + + proc mcpreferences {} { + return $::msgcat::_loclist + } + + proc mcload {langdir} { + foreach p [::msgcat::mcpreferences] { + set langfile $langdir/$p.msg + if {[file exists $langfile]} { + uplevel [list source $langfile] + } + } + } + + proc mcset {locale src {dest ""}} { + if {[string compare "" $dest] == 0} { + set dest $src + } + + set ns [uplevel {namespace current}] + + set ::msgcat::_msg($locale,$ns,$src) $dest + } + + proc mcunknown {locale src} { + return $src + } + + # set default locale try to get from environment + if {[info exists ::env(LANG)]} { + mclocale $::env(LANG) + } else { + mclocale "C" + } + + namespace export mc mcset mclocale mclocales mcunknown +} + +package provide msgcat 1.0 + +#eof: msgcat.tcl diff --git a/library/msgcat1.0/pkgIndex.tcl b/library/msgcat1.0/pkgIndex.tcl new file mode 100644 index 0000000..b40a4f3 --- /dev/null +++ b/library/msgcat1.0/pkgIndex.tcl @@ -0,0 +1 @@ +package ifneeded msgcat 1.0 [list source [file join $dir msgcat.tcl]] -- cgit v0.12