summaryrefslogtreecommitdiffstats
path: root/library/msgcat/msgcat.tcl
diff options
context:
space:
mode:
authorericm <ericm>2000-04-11 21:16:17 (GMT)
committerericm <ericm>2000-04-11 21:16:17 (GMT)
commit6778b65f1b617527d2402c8b78b3419fb2a7c502 (patch)
tree389eff9702dc67f07d9f389d1d1412c6d33cca94 /library/msgcat/msgcat.tcl
parent4e6c3f6a1d64a7586316c4c78bf4322877b8f075 (diff)
downloadtcl-6778b65f1b617527d2402c8b78b3419fb2a7c502.zip
tcl-6778b65f1b617527d2402c8b78b3419fb2a7c502.tar.gz
tcl-6778b65f1b617527d2402c8b78b3419fb2a7c502.tar.bz2
* msgcat.n: Added docs for new behavior from patch in [Bug: 4158].
* msgcat.test: Added tests for new behavior from patch in [Bug: 4158]. * msgcat.tcl: Applied patch from [Bug: 4158], which enables msgcat::mc to search the entire namespace ancestry chain for message translations (ie, first it checks the current namespace, then the parent, then the parent's parent, etc). Also allows the specification of additional args for msgcat::mc; if extra args are given, the [format] command is used to substitute the additional args in the translated message.
Diffstat (limited to 'library/msgcat/msgcat.tcl')
-rw-r--r--library/msgcat/msgcat.tcl32
1 files changed, 25 insertions, 7 deletions
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl
index 7eb1f90..4619ae1 100644
--- a/library/msgcat/msgcat.tcl
+++ b/library/msgcat/msgcat.tcl
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: msgcat.tcl,v 1.3 1999/08/19 02:59:49 hobbs Exp $
+# RCS: @(#) $Id: msgcat.tcl,v 1.4 2000/04/11 21:16:18 ericm Exp $
package provide msgcat 1.0
@@ -32,20 +32,38 @@ namespace eval msgcat {
# msgcat::mc --
#
# Find the translation for the given string based on the current
-# locale setting.
+# locale setting. Check the local namespace first, then look in each
+# parent namespace until the source is found. If additional args are
+# specified, use the format command to work them into the traslated
+# string.
#
# Arguments:
# src The string to translate.
+# args Args to pass to the format command
#
# Results:
-# Returns the translatd string.
+# Returns the translatd string. Propagates errors thrown by the
+# format command.
+
+proc msgcat::mc {src args} {
+ # Check for the src in each namespace starting from the local and
+ # ending in the global.
-proc msgcat::mc {src} {
set ns [uplevel {namespace current}]
- foreach loc $::msgcat::loclist {
- if {[info exists ::msgcat::msgs($loc,$ns,$src)]} {
- return $::msgcat::msgs($loc,$ns,$src)
+
+ while {$ns != ""} {
+ foreach loc $::msgcat::loclist {
+ if {[info exists ::msgcat::msgs($loc,$ns,$src)]} {
+ if {[llength $args] == 0} {
+ return $::msgcat::msgs($loc,$ns,$src)
+ } else {
+ return [eval \
+ [list format $::msgcat::msgs($loc,$ns,$src)] \
+ $args]
+ }
+ }
}
+ set ns [namespace parent $ns]
}
# we have not found the translation
return [uplevel 1 [list [namespace origin mcunknown] \