lang::util::localize (public)
lang::util::localize string_with_hashes [ locale ]
Defined in packages/acs-lang/tcl/lang-util-procs.tcl
Takes a string with embedded message keys on the format #message_key_name# and returns the same string but with the message keys (and their surrounding hash marks) replaced with the corresponding value in the message catalog. Message lookup is done with the locale of the request. If message lookup fails for a certain key then a translation missing message will be used instead.
- Parameters:
- string_with_hashes (required)
- locale (optional)
- Author:
- Peter marklund <peter@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- lang_test__lang_user_site_wide_locale, localize, test_localize_list_of_lists, ad_context_bar_multirow, object_type_hierarchy
Source code: # Return quickly for the fairly frequent case where there are no embedded message keys if { ![string match "*#*" $string_with_hashes] } { return $string_with_hashes } if {$locale eq ""} { set locale [ad_conn locale] } set indices_list [get_hash_indices $string_with_hashes] set subst_string "" set start_idx 0 foreach item_idx $indices_list { # The replacement string starts and ends with a hash mark set replacement_string [string range $string_with_hashes [lindex $item_idx 0] [lindex $item_idx 1]] set message_key [string range $replacement_string 1 [string length $replacement_string]-2] # Attempt a message lookup set message_value [lang::message::lookup $locale $message_key "" "" 2] # Replace the string # LARS: We don't use regsub here, because regsub interprets certain characters # in the replacement string specially. append subst_string [string range $string_with_hashes $start_idx [lindex $item_idx 0]-1] append subst_string $message_value set start_idx [expr {[lindex $item_idx 1] + 1}] } append subst_string [string range $string_with_hashes $start_idx end] return $subst_stringXQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-lang/tcl/lang-util-procs.xql