summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2002-04-20 00:35:19 (GMT)
committerdgp <dgp@users.sourceforge.net>2002-04-20 00:35:19 (GMT)
commit715d8ed46f9b0792841536a10be48c362dddbc05 (patch)
tree815b64c91e0bae641f89f388fb192ae8fa1c8df7
parent2bdca9dfc1dd3565672960643e6e860330bd10fe (diff)
downloadtcl-715d8ed46f9b0792841536a10be48c362dddbc05.zip
tcl-715d8ed46f9b0792841536a10be48c362dddbc05.tar.gz
tcl-715d8ed46f9b0792841536a10be48c362dddbc05.tar.bz2
* [mcmax] wasn't using the caller's
namespace when determining the max translated length. Also made revisions for better use of namespace variables and more efficient [uplevel]s.
-rw-r--r--ChangeLog5
-rw-r--r--library/msgcat/msgcat.tcl50
2 files changed, 34 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index b8e7021..b596399 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2002-04-19 Don Porter <dgp@users.sourceforge.net>
+ * library/msgcat/msgcat.tcl: [mcmax] wasn't using the caller's
+ namespace when determining the max translated length. Also
+ made revisions for better use of namespace variables and more
+ efficient [uplevel]s.
+
* doc/msgcat.n:
* library/msgcat/msgcat.tcl:
* library/msgcat/pkgIndex.tcl: Added [mcload] to the export list
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl
index e1dbd16..7299004 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.12 2002/04/19 23:09:37 dgp Exp $
+# RCS: @(#) $Id: msgcat.tcl,v 1.13 2002/04/20 00:35:19 dgp Exp $
package require Tcl 8.2
package provide msgcat 1.2.3
@@ -51,25 +51,28 @@ proc msgcat::mc {src args} {
# Check for the src in each namespace starting from the local and
# ending in the global.
+ variable msgs
+ variable loclist
+ variable locale
+
set ns [uplevel 1 [list ::namespace current]]
while {$ns != ""} {
- foreach loc $::msgcat::loclist {
- if {[info exists ::msgcat::msgs($loc,$ns,$src)]} {
+ foreach loc $loclist {
+ if {[info exists msgs($loc,$ns,$src)]} {
if {[llength $args] == 0} {
- return $::msgcat::msgs($loc,$ns,$src)
+ return $msgs($loc,$ns,$src)
} else {
- return [eval \
- [list format $::msgcat::msgs($loc,$ns,$src)] \
- $args]
+ return [uplevel 1 \
+ [linsert $args 0 ::format $msgs($loc,$ns,$src)]]
}
}
}
set ns [namespace parent $ns]
}
# we have not found the translation
- return [uplevel 1 [list [::namespace origin mcunknown] \
- $::msgcat::locale $src] $args]
+ return [uplevel 1 \
+ [linsert $args 0 [::namespace origin mcunknown] $locale $src]]
}
# msgcat::mclocale --
@@ -85,23 +88,24 @@ proc msgcat::mc {src args} {
# Returns the current locale.
proc msgcat::mclocale {args} {
+ variable loclist
+ variable locale
set len [llength $args]
if {$len > 1} {
error {wrong # args: should be "mclocale ?newLocale?"}
}
- set args [string tolower $args]
if {$len == 1} {
- set ::msgcat::locale $args
- set ::msgcat::loclist {}
+ set locale [string tolower [lindex $args 0]]
+ set loclist {}
set word ""
- foreach part [split $args _] {
+ foreach part [split $locale _] {
set word [string trimleft "${word}_${part}" _]
- set ::msgcat::loclist [linsert $::msgcat::loclist 0 $word]
+ set loclist [linsert $loclist 0 $word]
}
}
- return $::msgcat::locale
+ return $locale
}
# msgcat::mcpreferences --
@@ -116,7 +120,8 @@ proc msgcat::mclocale {args} {
# Returns an ordered list of the locales preferred by the user.
proc msgcat::mcpreferences {} {
- return $::msgcat::loclist
+ variable loclist
+ return $loclist
}
# msgcat::mcload --
@@ -132,7 +137,7 @@ proc msgcat::mcpreferences {} {
proc msgcat::mcload {langdir} {
set x 0
- foreach p [::msgcat::mcpreferences] {
+ foreach p [mcpreferences] {
set langfile [file join $langdir $p.msg]
if {[file exists $langfile]} {
incr x
@@ -159,13 +164,14 @@ proc msgcat::mcload {langdir} {
# Returns the new locale.
proc msgcat::mcset {locale src {dest ""}} {
+ variable msgs
if {[string equal $dest ""]} {
set dest $src
}
set ns [uplevel 1 [list ::namespace current]]
- set ::msgcat::msgs([string tolower $locale],$ns,$src) $dest
+ set msgs([string tolower $locale],$ns,$src) $dest
return $dest
}
@@ -181,6 +187,7 @@ proc msgcat::mcset {locale src {dest ""}} {
# Returns the number of pairs processed
proc msgcat::mcmset {locale pairs } {
+ variable msgs
set length [llength $pairs]
if {$length % 2} {
@@ -191,7 +198,7 @@ proc msgcat::mcmset {locale pairs } {
set ns [uplevel 1 [list ::namespace current]]
foreach {src dest} $pairs {
- set ::msgcat::msgs($locale,$ns,$src) $dest
+ set msgs($locale,$ns,$src) $dest
}
return $length
@@ -216,7 +223,7 @@ proc msgcat::mcmset {locale pairs } {
proc msgcat::mcunknown {locale src args} {
if {[llength $args]} {
- return [eval [list format $src] $args]
+ return [uplevel 1 [linsert $args 0 ::format $src]]
} else {
return $src
}
@@ -236,7 +243,8 @@ proc msgcat::mcunknown {locale src args} {
proc msgcat::mcmax {args} {
set max 0
foreach string $args {
- set len [string length [msgcat::mc $string]]
+ set translated [uplevel 1 [list [namespace origin mc] $string]]
+ set len [string length $translated]
if {$len>$max} {
set max $len
}