lang::conn::browser_locale (private)

 lang::conn::browser_locale

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

Get the users preferred locale from the accept-language HTTP header.

Returns:
A locale or an empty string if no locale can be found that is supported by the system
Authors:
Lars Pind
Peter Marklund

Partial Call Graph (max 5 caller/called nodes):
%3 test_locale__test_lang_conn_browser_locale locale__test_lang_conn_browser_locale (test acs-lang) lang::conn::browser_locale lang::conn::browser_locale test_locale__test_lang_conn_browser_locale->lang::conn::browser_locale lang::conn::get_accept_language_header lang::conn::get_accept_language_header (private) lang::conn::browser_locale->lang::conn::get_accept_language_header lang::system::get_locales lang::system::get_locales (public) lang::conn::browser_locale->lang::system::get_locales lang::util::default_locale_from_lang lang::util::default_locale_from_lang (public) lang::conn::browser_locale->lang::util::default_locale_from_lang lang::conn::locale_not_cached lang::conn::locale_not_cached (private) lang::conn::locale_not_cached->lang::conn::browser_locale lang::test::assert_browser_locale lang::test::assert_browser_locale (private) lang::test::assert_browser_locale->lang::conn::browser_locale

Testcases:
locale__test_lang_conn_browser_locale
Source code:
    set conn_locales [lang::conn::get_accept_language_header]

    set system_locales [lang::system::get_locales]

    foreach locale $conn_locales {
        regexp {^([^_]+)(?:_([^_]+))?$} $locale locale language region

        if { [info exists region] && $region ne "" } {
            # We have both language and region, e.g. en_US
            if {$locale in $system_locales} {
                # The locale was found in the system, a perfect match
                set perfect_match $locale
                break
            } else {
                # We don't have the full locale in the system but check if
                # we have a different locale with matching language,
                # i.e. a tentative match
                if { ![info exists tentative_match] } {
                    set default_locale [lang::util::default_locale_from_lang $language]
                    if { $default_locale ne "" } {
                        set tentative_match $default_locale
                    }
                } else {
                    # We already have a tentative match with higher priority so
                    # continue searching for a perfect match
                    continue
                }
            }
        } else {
            # We have just a language, e.g. en
            set default_locale [lang::util::default_locale_from_lang $locale]
            if { $default_locale ne "" } {
                set perfect_match $default_locale
                break
            }
        }
    }

    if { [info exists perfect_match] && $perfect_match ne "" } {
        return $perfect_match
    } elseif { [info exists tentative_match] && $tentative_match ne "" } {
        return $tentative_match
    } else {
        # We didn't find a match
        return ""
    }
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-lang/tcl/locale-procs.xql

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