|
2001-04-05
| ||
| 07:56 | • Closed ticket [219053ffff]: ::msgcat::mc only checks the current namespace for r... artifact: 567901c0df user: dgp | |
| 07:55 | • Open ticket [219053ffff]. artifact: 28c0ed9627 user: dgp | |
|
2000-10-26
| ||
| 08:34 | • Closed ticket [219053ffff]. artifact: 2a2dccd002 user: welch | |
| 01:09 | • New ticket [219053ffff]. artifact: af1504daa7 user: nobody | |
::msgcat::mc only checks the current namespace for resolving
Closed / Fixed219053ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:09:57
OriginalBugID: 4158 Bug
Version: 8.3
SubmitDate: '2000-02-11'
LastModified: '2000-04-11'
Severity: CRIT
Status: Released
Submitter: sven
ChangedBy: ericm
RelatedBugIDs: 2211
OS: All
FixedDate: '2000-04-11'
FixedInVersion: 8.3.1
ClosedDate: '2000-10-25'
When using ::msgcat::mc, strings are only resolved by looking at catalog files that have been loaded from inside the current namespace. This means that we need a message catalog directory for each namespace (or have a lot of redundancy by loading the shared catalog file into each namespace).
Expected behavior:
It would be nice if we could make the ::msgcat::mc command reslove the string by looking at alternative namespaces too. One possibility would be to check the root namespace :: if the string can not be resolved locally, another approach would be to go up the namespace chain, and check on each level.
If we are to do this, it should check the local namespace and then
the global namespace, making it the same as proc and variable name
resolution.
-- 04/03/2000 hobbs
I have a solution that checks all the parent namespaces and then the global namespace. It is not that often that people have namespaces deeper than 2 or 3, so I don't think it's a big deal to check all of them, but we can take that out if people want... My solution also enables msgcat to do string formatting rather for you. For example,
::msgcat::mcset en badUserGroupCombo {Expected \"%1$s\" to be a user and \"%2$s\" to be a group.}
::msgcat::mc badUserGroupCombo userA userB
==> Expected "userA" to be a user and "userB" to be a group.
# msgcat::mc --
#
#Find the translation for the given string based on the current
#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:
#srcThe string to translate.
#argsArgs passed the format command.
#
# Results:
#Returns the translated string.
#Propages 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.
set ns [uplevel {namespace current}]
while {![string equal $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 format [list $::msgcat::msgs($loc,$ns,$src)] $args]
}
}
}
set ns [namespace parent $ns]
}
# we have not found the translation
return [uplevel 1 [list [namespace origin mcunknown] $::msgcat::locale $src]]
}
-- 04/07/2000 hershey
I applied this patch and added tests and docs for it (shame on you for not submitting tests and docs yourself!). The fix is in CVS now and will go out with 8.3.1.
- eric
-- 04/11/2000 ericm
welch Closed ticket [219053ffff].
[History diff]2000-10-26 08:34:06
dgp Open ticket [219053ffff].
[History diff]2001-04-05 07:55:31
dgp Closed ticket [219053ffff].
[History diff]2001-04-05 07:56:45
Log in (anonymous is fine) to add a comment.