Index: openacs-4/packages/ams/tcl/address-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/address-widget-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ams/tcl/address-widget-procs.tcl 21 Oct 2004 01:53:49 -0000 1.2 +++ openacs-4/packages/ams/tcl/address-widget-procs.tcl 18 May 2005 17:11:48 -0000 1.3 @@ -44,7 +44,29 @@ {postal_type {}} } { # MGEDDERT TODO, convert country code to country name via cached proc - set country $country_code + if { [ad_conn isconnected] } { + # We are in an HTTP connection (request) so use that locale + set locale [ad_conn locale] + } else { + # There is no HTTP connection - resort to system locale + set locale [lang::system::locale] + } + set key "ams.country_${country_code}" + if { [string is true [lang::message::message_exists_p $locale $key]] } { + set country [lang::message::lookup $locale $key] + } else { + # cache the country codes + template::util::address::country_options_not_cached -locale $locale + + if { [string is true [lang::message::message_exists_p $locale $key]] } { + set country [lang::message::lookup $locale $key] + } else { + # we get the default en_US key which was created with the + # template::util::address::country_options_not_cached proc + set country [lang::message::lookup "en_US" $key] + } + } + set address "$delivery_address $municipality, $region $postal_code $country" @@ -69,13 +91,51 @@ ad_proc -public template::util::address::country_options {} { Returns the country list. Cached. } { - return [util_memoize [list template::util::address::country_options_not_cached]] + if { [ad_conn isconnected] } { + # We are in an HTTP connection (request) so use that locale + set locale [ad_conn locale] + } else { + # There is no HTTP connection - resort to system locale + set locale [lang::system::locale] + } + return [util_memoize [list template::util::address::country_options_not_cached -locale $locale]] } -ad_proc -public template::util::address::country_options_not_cached {} { +ad_proc -public template::util::address::country_options_not_cached { + {-locale "en_US"} +} { Returns the country list. } { - return [db_list_of_lists get_countries {}] + set country_list [db_list_of_lists get_countries {}] + set return_country_list [list] + foreach country $country_list { + set this_locale $locale + set country_name_db [lindex $country 0] + set country_code_db [lindex $country 1] + set package_key "ams" + set message_key "country_${country_code_db}" + set key "${package_key}.${message_key}" + if { [string is false [lang::message::message_exists_p $locale $key]] } { + if { [string is false [lang::message::message_exists_p "en_US" $key]] } { + lang::message::register $locale $package_key $message_key $country_name_db + } else { + set this_locale "en_US" + } + } + # mgeddert customization for mbbs + if { [lsearch [list US CA] $country_code_db] < 0 } { + # the reason not to use the "list" command here is because a curly bracket + # needs to be used in the list for countries with a single word name + # so that alphabetizing (via lsort) works later on in this proc + lappend return_country_list "{[lang::message::lookup $this_locale $key]} {$country_code_db}" + } + } + set country_code [list] + lappend country_code [list "United States" US] + lappend country_code [list "Canada" CA] + lappend country_code [list "--" ""] + append country_code " [lsort $return_country_list]" + return $country_code } ad_proc -public template::data::validate::address { value_ref message_ref } { @@ -249,10 +309,12 @@ set country_code [template::util::address::get_property country_code $address_list] set additional_text [template::util::address::get_property additional_text $address_list] set postal_type [template::util::address::get_property postal_type $address_list] - return [template::util::address::html_view $delivery_address $postal_code $municipality $region $country_code $additional_text $postal_type] + return [template::util::address::html_view $delivery_address $municipality $region $postal_code $country_code $additional_text $postal_type] } default { - error "Parameter supplied to util::address::get_property 'what' must be one of: 'delivery_address', 'postal_code', 'municipality', 'region', 'country_code', 'additional_text', 'postal_type'. You specified: '$what'." + error "Parameter supplied to template::util::address::get_property 'what' must be one of: 'delivery_address', 'postal_code', 'municipality', 'region', 'country_code', 'additional_text', 'postal_type'. You specified: '$what'." + ns_log "AMS Address Widget Error: on page [ad_conn url] template::util::address::get_property asked for $what" + return "" } } @@ -294,25 +356,26 @@ if { [string equal $element(mode) "edit"] } { - set attributes(id) \"address__$element(form_id)__$element(id)\" +# set attributes(id) "address__$element(form_id)__$element(id)" + set attributes(class) "address-widget-country-code" append output " - +
- + - - - + + + - - - + + +
[_ ams.delivery_address]
      
[_ ams.municipality][_ ams.region][_ ams.postal_code][_ ams.municipality][_ ams.region][_ ams.postal_code]
[menu $element(id).country_code [template::util::address::country_options] $country_code attributes]