lang::conn::get_accept_language_header (private)

 lang::conn::get_accept_language_header

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

Obtain a list of locals from the request headers.

Returns:
a list of locales in the syntax used by OpenACS (ISO codes)

Partial Call Graph (max 5 caller/called nodes):
%3 lang::conn::browser_locale lang::conn::browser_locale (private) lang::conn::get_accept_language_header lang::conn::get_accept_language_header lang::conn::browser_locale->lang::conn::get_accept_language_header lang::conn::valid_locale_p lang::conn::valid_locale_p (private) lang::conn::get_accept_language_header->lang::conn::valid_locale_p lang::system::locale lang::system::locale (public) lang::conn::get_accept_language_header->lang::system::locale

Testcases:
No testcase defined.
Source code:
    set acclang [ns_set iget [ns_conn headers] "Accept-Language"]

    # Split by comma, and get rid of any ;q=0.5 parts
    # acclang is something like 'da,en-us;q=0.8,es-ni;q=0.5,de;q=0.3'
    set acclangv [list]
    foreach elm [split $acclang ","] {
        # Get rid of trailing ;q=0.5 part and trim spaces
        set elm [string trimleft [lindex [split $elm ";"] 0] " "]
        # Ignore the default catchall setting "*"
        if {$elm eq "*"} {
            continue
        }
        # elm is now either like 'da' or 'en-us'
        # make it into something like 'da' or 'en_US'
        set elmv [split $elm "-"]
        set elm [lindex $elmv 0]
        if { [llength $elmv] > 1 } {
            append elm "_[string toupper [lindex $elmv 1]]"
        }
        if {[lang::conn::valid_locale_p $elm]} {
            lappend acclangv $elm
        } else {
            # It is usually bots or other kinds of not-canonical web
            # browsers which set this wrong. We tolerate it by
            # assuming our default language.
            ns_log warning "Invalid locale '$elm' in provided Accept-Language header field. Defaulting to system locale."
            return [lang::system::locale]
        }
    }

    return $acclangv
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-lang/tcl/locale-procs.xql

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