diff options
author | sebres <sebres@users.sourceforge.net> | 2017-01-11 16:35:41 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-01-11 16:35:41 (GMT) |
commit | 0be426fec21fe7b763b7486ec2c6d11d17fb19e3 (patch) | |
tree | 0f1cded106450d71420894e849f14d1a962d32b5 /library | |
parent | 7013db7f737f3f8279a9f313e53c8dc467162cf3 (diff) | |
download | tcl-0be426fec21fe7b763b7486ec2c6d11d17fb19e3.zip tcl-0be426fec21fe7b763b7486ec2c6d11d17fb19e3.tar.gz tcl-0be426fec21fe7b763b7486ec2c6d11d17fb19e3.tar.bz2 |
code review: small optimization of msgcat::mcget, prevents infinite loop if at all no translation
Diffstat (limited to 'library')
-rw-r--r-- | library/msgcat/msgcat.tcl | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 1260139..f9f57db 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -245,8 +245,6 @@ proc msgcat::mc {src args} { # format command. proc msgcat::mcget {ns loc args} { - variable Msgs - if {$loc eq {C}} { set loclist [PackagePreferences $ns] set loc [lindex $loclist 0] @@ -270,18 +268,20 @@ proc msgcat::mcget {ns loc args} { # search translation for each locale (regarding parent namespaces) for {set nscur $ns} {$nscur != ""} {set nscur [namespace parent $nscur]} { foreach loc $loclist { - if {[dict exists $Msgs $nscur $loc $src]} { - if {[llength $args] > 1} { - return [format [dict get $Msgs $nscur $loc $src] \ - {*}[lrange $args 1 end]] - } else { - return [dict get $Msgs $nscur $loc $src] + set msgs [mcget $nscur $loc] + if {![catch { set val [dict get $msgs $src] }]} { + if {[llength $args] == 1} { + return $val } + return [format $val {*}[lrange $args 1 end]] } } } - # get with package default locale - mcget $ns [lindex $loclist 0] {*}$args + # no translation : + if {[llength $args] == 1} { + return $src + } + return [format $src {*}[lrange $args 1 end]] } # msgcat::mcexists -- @@ -942,8 +942,10 @@ proc msgcat::Merge {ns locales} { set mrgcat [dict merge $mrgcat [dict get $Msgs $ns $loc]] } } else { - catch { + if {[catch { set mrgcat [dict get $Msgs $ns $loc] + }]} { + set mrgcat [dict create] } } dict set Merged $ns $loc $mrgcat |