summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstanton <stanton>1998-12-04 18:52:40 (GMT)
committerstanton <stanton>1998-12-04 18:52:40 (GMT)
commit00546bc09f65878c8adae90f4a88dac432b5e47c (patch)
treee54abd8da73579f202f85da622c5015f0025b79e
parente17613ce38cd6b16720832aa8e4d70e211ed5938 (diff)
downloadtcl-00546bc09f65878c8adae90f4a88dac432b5e47c.zip
tcl-00546bc09f65878c8adae90f4a88dac432b5e47c.tar.gz
tcl-00546bc09f65878c8adae90f4a88dac432b5e47c.tar.bz2
* library/msgcat1.0/msgcat.tcl:
* library/msgcat1.0/pkgIndex.tcl: Added initial implementaion of Tcl message catalog package contributed by Mark Harrison.
-rw-r--r--library/msgcat/msgcat.tcl92
-rw-r--r--library/msgcat/pkgIndex.tcl1
-rw-r--r--library/msgcat1.0/msgcat.tcl92
-rw-r--r--library/msgcat1.0/pkgIndex.tcl1
4 files changed, 186 insertions, 0 deletions
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]]