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):
%3 test_ad_context_bar_multirow ad_context_bar_multirow (test acs-tcl) lang::util::localize lang::util::localize test_ad_context_bar_multirow->lang::util::localize test_lang_test__lang_user_site_wide_locale lang_test__lang_user_site_wide_locale (test acs-lang) test_lang_test__lang_user_site_wide_locale->lang::util::localize test_localize localize (test acs-lang) test_localize->lang::util::localize test_object_type_hierarchy object_type_hierarchy (test acs-tcl) test_object_type_hierarchy->lang::util::localize test_test_localize_list_of_lists test_localize_list_of_lists (test acs-lang) test_test_localize_list_of_lists->lang::util::localize ad_conn ad_conn (public) lang::util::localize->ad_conn lang::message::lookup lang::message::lookup (public) lang::util::localize->lang::message::lookup lang::util::get_hash_indices lang::util::get_hash_indices (public) lang::util::localize->lang::util::get_hash_indices Class ::cookieconsent::CookieConsent Class ::cookieconsent::CookieConsent (public) Class ::cookieconsent::CookieConsent->lang::util::localize Class ::xo::lti::LTI Class ::xo::lti::LTI (public) Class ::xo::lti::LTI->lang::util::localize Class ::xowf::test_item::Answer_manager Class ::xowf::test_item::Answer_manager (public) Class ::xowf::test_item::Answer_manager->lang::util::localize Class ::xowiki::formfield::localized_text Class ::xowiki::formfield::localized_text (public) Class ::xowiki::formfield::localized_text->lang::util::localize acs_object_type_hierarchy acs_object_type_hierarchy (public) acs_object_type_hierarchy->lang::util::localize

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_string
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-lang/tcl/lang-util-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: