summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2018-01-12 14:52:25 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2018-01-12 14:52:25 (GMT)
commite1ffd3f0057b68e75bce64f9c514b9993fb8a79c (patch)
treea850ba95d28d3e36a08daff8f08f1308ad8a103b /library
parent2cfe8bb5619eb9a1de655bda6a208e9e2fb8b81b (diff)
downloadtcl-e1ffd3f0057b68e75bce64f9c514b9993fb8a79c.zip
tcl-e1ffd3f0057b68e75bce64f9c514b9993fb8a79c.tar.gz
tcl-e1ffd3f0057b68e75bce64f9c514b9993fb8a79c.tar.bz2
Implement the "mcn" command as "mc" with explicit namespace.
Diffstat (limited to 'library')
-rw-r--r--library/msgcat/msgcat.tcl32
1 files changed, 28 insertions, 4 deletions
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl
index 66cedea..29ccf0a 100644
--- a/library/msgcat/msgcat.tcl
+++ b/library/msgcat/msgcat.tcl
@@ -17,7 +17,8 @@ package require Tcl 8.5-
package provide msgcat 1.6.2
namespace eval msgcat {
- namespace export mc mcexists mcload mclocale mcmax mcmset mcpreferences mcset\
+ namespace export mc mcn mcexists mcload mclocale mcmax\
+ mcmset mcpreferences mcset\
mcunknown mcflset mcflmset mcloadedlocales mcforgetpackage\
mcpackagenamespaceget mcpackageconfig mcpackagelocale
@@ -192,7 +193,30 @@ namespace eval msgcat {
# Returns the translated string. Propagates errors thrown by the
# format command.
-proc msgcat::mc {src args} {
+proc msgcat::mc {args} {
+ tailcall mcn [PackageNamespaceGet] {*}$args
+}
+
+# msgcat::mcn --
+#
+# Find the translation for the given string based on the current
+# locale setting. Check the passed 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.
+# If no catalog item is found, mcunknown is called in the caller frame
+# and its result is returned.
+#
+# Arguments:
+# ns Package namespace of the translation
+# src The string to translate.
+# args Args to pass to the format command
+#
+# Results:
+# Returns the translated string. Propagates errors thrown by the
+# format command.
+
+proc msgcat::mcn {ns src args} {
# Check for the src in each namespace starting from the local and
# ending in the global.
@@ -200,7 +224,6 @@ proc msgcat::mc {src args} {
variable Msgs
variable Loclist
- set ns [PackageNamespaceGet]
set loclist [PackagePreferences $ns]
set nscur $ns
@@ -1072,8 +1095,9 @@ proc msgcat::DefaultUnknown {locale src args} {
proc msgcat::mcmax {args} {
set max 0
+ set ns [PackageNamespaceGet]
foreach string $args {
- set translated [uplevel 1 [list [namespace origin mc] $string]]
+ set translated [uplevel 1 [list [namespace origin mcn] $ns $string]]
set len [string length $translated]
if {$len>$max} {
set max $len