Index: openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl,v diff -u -N -r1.42.2.1 -r1.42.2.2 --- openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl 18 Mar 2004 09:07:46 -0000 1.42.2.1 +++ openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl 18 Mar 2004 10:12:37 -0000 1.42.2.2 @@ -583,31 +583,39 @@ # A quoted percent sign append formated_message "%" } else { - set variable_key [string range $percent_match 1 end-1] + set variable_string [string range $percent_match 1 end-1] if { [llength $value_array_list] > 0 } { # A substitution list is provided, the key should be in there - if { [lsearch -exact $value_array_keys $variable_key] == -1 } { - ns_log Warning "lang::message::format: The value_array_list \"$value_array_list\" does not contain the variable name $variable_key found in the message: $localized_message" + if { [lsearch -exact $value_array_keys $variable_string] == -1 } { + ns_log Warning "lang::message::format: The value_array_list \"$value_array_list\" does not contain the variable name $variable_string found in the message: $localized_message" # There is no value available to do the substitution with # so don't substitute at all append formated_message $percent_match } else { # Do the substitution - append formated_message [lindex [array get value_array $variable_key] 1] + append formated_message [lindex [array get value_array $variable_string] 1] } } else { + regexp {^([^.]+)(?:\.([^.]+))?$} $variable_string match variable_name array_key + # No substitution list provided - attempt to fetch variable value # from scope calling lang::message::lookup - upvar $upvar_level $variable_key variable_value + upvar $upvar_level $variable_name local_variable - if { [info exists variable_value] } { - append formated_message $variable_value + if { [info exists local_variable] } { + if { ![exists_and_not_null array_key] } { + # Normal Tcl variable + append formated_message $local_variable + } else { + # Array variable + append formated_message $local_variable($array_key) + } } else { - error "Message contains a variable named '$variable_key' which doesn't exist in the caller's environment: message $localized_message" + error "Message contains a variable named '$variable_name' which doesn't exist in the caller's environment: message $localized_message" } } } Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v diff -u -N -r1.15.2.1 -r1.15.2.2 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 18 Mar 2004 09:07:46 -0000 1.15.2.1 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 18 Mar 2004 10:12:38 -0000 1.15.2.2 @@ -680,8 +680,13 @@ set subst_message [lang::message::format $localized_message $value_list] set expected_message "The frog jumped across the fence. About 50% of the time, he stumbled, or maybe it was %20 %times%." - aa_true "the frog should jump across the fence" [string equal $subst_message \ - $expected_message] + aa_equals "the frog should jump across the fence" $subst_message $expected_message + + set my_var(my_key) foo + set localized_message "A text with an array variable %my_var.my_key% in it" + set subst_message [lang::message::format $localized_message {} 1] + set expected_message "A text with an array variable foo in it" + aa_equals "embedded array variable" $subst_message $expected_message } aa_register_case \