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 -r1.51 -r1.52 --- openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl 7 Jun 2008 20:28:55 -0000 1.51 +++ openacs-4/packages/acs-lang/tcl/lang-message-procs.tcl 27 Oct 2014 16:39:37 -0000 1.52 @@ -17,6 +17,79 @@ namespace eval lang::message {} +ad_proc -public lang::message::check { + locale + package_key + message_key + message +} { +

+ Check a message for semantic and sanity correctness (usually called just before a message is registered). + Throws an error when one of the checks fails. +

+} { + # Qualify the locale variable value with a country code if it is + # just a language + if { [string length $locale] == 2 } { + # It seems to be a language (iso codes are 2 characters) + # We don't do a more throughout check since this is not + # invoked by users. + # let's get the default locale for that language + set locale [lang::util::default_locale_from_lang $locale] + } + + # Create a globally (across packages) unique key for the cache + set key "${package_key}.${message_key}" + + # Check that non-en_US messages don't have invalid embedded variables + # Exclude the special case of datetime configuration messages in acs-lang. An alternative + # to treating those messages as a special case here would be to have those messages use + # quoted percentage signs (double percentage signs). + if { $locale ne "en_US" && ![regexp {^acs-lang\.localization-} $key] } { + set embedded_vars [get_embedded_vars $message] + set embedded_vars_en_us [get_embedded_vars [lang::message::lookup en_US $key {} {} 0]] + set missing_vars [util_get_subset_missing $embedded_vars $embedded_vars_en_us] + + if { [llength $missing_vars] > 0 } { + error "Message key '$key' in locale '$locale' has these embedded variables not present in the en_US locale:\ + [join $missing_vars ","]." + } + } + + # If a localization key from acs-lang... + if {[regexp {^acs-lang\.localization-(.*)$} $key match lc_key]} { + # + # ...number separators for decimal and thousands must be + # checked to ensure they are not equal, otherwise the + # localized number parsing will fail. + # + if {$lc_key in {decimal_point thousands_sep mon_thousands_sep}} { + # + # Fetch values in case there were already loaded. + # + foreach k {decimal_point thousands_sep mon_thousands_sep} { + set $k [expr {[lang::message::message_exists_p $locale acs-lang.localization-$k] ? + [lc_get -locale $locale $k] : ""}] + } + # + # Overwrite the fetched value with the provided one. + # + set $lc_key $message + + # + # We require, that the decimal_point was either provided + # or loaded before to be able to compare it with the + # thousands points. + # + if {$decimal_point ne "" && + [string first $decimal_point "$thousands_sep$mon_thousands_sep"] > -1} { + error "locale $locale, key: $key: Message keys for thousands and decimal separators must be different." + } + } + } +} + + ad_proc -public lang::message::register { {-update_sync:boolean} {-upgrade_status "no_upgrade"} @@ -98,29 +171,18 @@ error $error_message } } - - # Check that non-en_US messages don't have invalid embedded variables - # Exclude the special case of datetime configuration messages in acs-lang. An alternative - # to treating those messages as a special case here would be to have those messages use - # quoted percentage signs (double percentage signs). - if { $locale ne "en_US" && ![regexp {^acs-lang\.localization-} $key] } { - set embedded_vars [get_embedded_vars $message] - set embedded_vars_en_us [get_embedded_vars [lang::message::lookup en_US $key {} {} 0]] - set missing_vars [util_get_subset_missing $embedded_vars $embedded_vars_en_us] - - if { [llength $missing_vars] > 0 } { - error "Message key '$key' in locale '$locale' has these embedded variables not present in the en_US locale: [join $missing_vars ","]. Message has not been imported." - } - } + # Call semantic and sanity checks on the key before registering. + lang::message::check $locale $package_key $message_key $message + # Build up an array of columns to set array set cols [list] if { $update_sync_p } { set cols(sync_time) [db_map sync_time] } else { set cols(sync_time) "null" } - if { [empty_string_p [string trim $message]] } { + if { [string trim $message] eq "" } { set cols(message) "null" } else { set cols(message) [db_map message] @@ -168,7 +230,7 @@ $old_message_array(upgrade_status) # Trying to avoid hitting Oracle bug#2011927 - if { [empty_string_p [string trim $message]] } { + if { [string trim $message] eq "" } { db_dml lang_message_null_update {} } else { set cols(message) [db_map message] @@ -197,7 +259,7 @@ } # avoiding bug#2011927 from Oracle. - if { [empty_string_p [string trim $message]] } { + if { [string trim $message] eq "" } { db_dml lang_message_insert_null_msg {} } else { db_dml lang_message_insert {} -clobs [list $message] @@ -480,7 +542,7 @@ # Build any package and locale where clauses set where_clauses [list] foreach col {package_key locale} { - if { ![empty_string_p [set $col]] } { + if { [set $col] ne "" } { lappend where_clauses "$col = :${col}" } } @@ -588,7 +650,7 @@ if { [llength $value_array_list] > 0 } { # A substitution list is provided, the key should be in there - if { [lsearch -exact $value_array_keys $variable_string] == -1 } { + if {$variable_string ni $value_array_keys} { 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 @@ -607,7 +669,7 @@ upvar $upvar_level $variable_name local_variable if { [info exists local_variable] } { - if { ![exists_and_not_null array_key] } { + if { (![info exists array_key] || $array_key eq "") } { # Normal Tcl variable append formated_message $local_variable } else { @@ -832,9 +894,10 @@ set marker "XXYYZZXX. " set qmsg "$marker $msg" set url "http://babel.altavista.com/translate.dyn?doit=done&BabelFishFrontPage=yes&bblType=urltext&url=" - set babel_result [ns_httpget "$url&lp=$lang&urltext=[ns_urlencode $qmsg]"] + set babel_result [util::http::get -url "$url&lp=$lang&urltext=[ns_urlencode $qmsg]"] + set babel_page [dict get $babel_result page] set result_pattern "$marker (\[^<\]*)" - if {[regexp -nocase $result_pattern $babel_result ignore msg_tr]} { + if {[regexp -nocase $result_pattern $babel_page ignore msg_tr]} { regsub "$marker." $msg_tr "" msg_tr return [string trim $msg_tr] } else { @@ -959,9 +1022,9 @@ {-description:required} } { @author Simon Carstensen - @creation_date 2003-08-12 + @creation-date 2003-08-12 } { - if { [empty_string_p [string trim $description]] } { + if { [string trim $description] eq "" } { db_dml update_description_insert_null {} } else { db_dml update_description {} -clobs [list $description]