Forum .LRN Q&A: Re: Internationalization - ACS5.0.0

Collapse
Posted by Peter Marklund on
Sung,
take a look at the proc lang::conn::browser_locale. It already looks for an exact locale match, but uses a locale with only matching language part if it doesn't find that.

Here is code from the corresponding test case that explains the logic:

        # First locale is perfect language match
        lang::test::assert_browser_locale "da,en-us;q=0.8,de;q=0.5,es;q=0.3" "da_DK"

        # First locale is perfect locale match
        lang::test::assert_browser_locale "da_DK,en-us;q=0.8,de;q=0.5,es;q=0.3" "da_DK"

        # Tentative match being discarded
        lang::test::assert_browser_locale "da_BLA,foobar,en" "en_US"

        # Tentative match being used
        lang::test::assert_browser_locale "da_BLA,foobar" "da_DK"

        # Several tentative matches, all being discarded
        lang::test::assert_browser_locale "da_BLA,foobar,da_BLUB,da_DK" "da_DK"