lang::message::check (public)

 lang::message::check locale package_key message_key message

Defined in packages/acs-lang/tcl/lang-message-procs.tcl

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.

Parameters:
locale
package_key
message_key
message

Partial Call Graph (max 5 caller/called nodes):
%3 test_lang_messages_correct lang_messages_correct (test acs-lang) lang::message::check lang::message::check test_lang_messages_correct->lang::message::check ad_log ad_log (public) lang::message::check->ad_log lang::message::get_embedded_vars lang::message::get_embedded_vars (public) lang::message::check->lang::message::get_embedded_vars lang::message::lookup lang::message::lookup (public) lang::message::check->lang::message::lookup lang::message::message_exists_p lang::message::message_exists_p (public) lang::message::check->lang::message::message_exists_p lang::util::default_locale_from_lang lang::util::default_locale_from_lang (public) lang::message::check->lang::util::default_locale_from_lang lang::message::register lang::message::register (public) lang::message::register->lang::message::check packages/acs-lang/www/admin/edit-localized-message.tcl packages/acs-lang/ www/admin/edit-localized-message.tcl packages/acs-lang/www/admin/edit-localized-message.tcl->lang::message::check

Testcases:
lang_messages_correct
Source code:
    # 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 } {
            set msg "Message key '$key' in locale '$locale' has these embedded variables not present in the en_US locale: [join $missing_vars ","]."
            ad_log error $msg
            error $msg
        }
    }

    # 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."
            }
        }
    }
Generic XQL file:
packages/acs-lang/tcl/lang-message-procs.xql

PostgreSQL XQL file:
packages/acs-lang/tcl/lang-message-procs-postgresql.xql

Oracle XQL file:
packages/acs-lang/tcl/lang-message-procs-oracle.xql

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