Thanks Andrew,

I got my application to work correctly, though I had to revert to some
manual work.  Basically in my login action, I now pick the request header
for accepted languages, iterate through the ugly String, parse out IE's
weightage information on languages, and set the Locale to the first
available locale.

best,
Amrinder

PS: The code is:

/**
     * A utility method to set the user preferred locale
     * @author Amrinder Arora
     */
    private void setPreferredLocale (HttpServletRequest request)
    {
        try {
            Enumeration acceptedLanguagesEnum =
request.getHeaders("Accept-Language");

            if ((acceptedLanguagesEnum == null) ||
(!acceptedLanguagesEnum.hasMoreElements())) {
                // cant do much here
                logger.debug ("No choices in accepted languages");
                return;
            }

            // Although declared as an enumeration, at least in IE6.0, the
entire
            // information comes back in one String, which is the only
element of Enumeration
            String acceptedLanguagesString = (String)
(acceptedLanguagesEnum.nextElement());

            // the format of this string in IE6.0 is:
            // lang1,lang2;q=w2,lang3;q=w3,lang4;q=w4,...

            StringTokenizer locales = new StringTokenizer
(acceptedLanguagesString, ",");
            boolean localeFinalized = false;
            while (locales.hasMoreElements()) {
                String locale = locales.nextToken();
                // ignore IE's q=0.x part
                if (locale.indexOf (';') >= 0)
                    locale = locale.substring (0, locale.indexOf (';'));
                logger.debug ("locale accepted by client: " + locale);
                // keeps trying to set the locale until successful,
                // if successful, method returns
                // if unsuccessful, waits for next accepted language
                if (!localeFinalized) {
                    try {
                        setLocale (request, new Locale (locale));
                        logger.debug ("set locale to: " + locale);
                        return;
                    } catch (Throwable t) {
                        logger.debug ("unable to set locale to: " + locale);
                    }
                }
            }
        } catch (Throwable t) {
            logger.error ("Exception in setting preferred locale", t);
        }
    }

----- Original Message -----
From: "Andrew Hill" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, January 21, 2003 5:37 AM
Subject: RE: missing some step(s) in i18n; setLocale() works, IE's settings
dont


> Probably not the problem here , but I encountered some issues with IE5's
> sending the accept-language header, where if one has modified ones
'Regional
> Settings' from the control panel, IE will sometimes use the default
language
> selected there, and sometimes use the setting in IE languages.
> This seems to change between consecutive requests even and I havent quite
> pinned down under which circumstances it submits the correct setting and
> when it uses the regional settings one.
> JavaScript location.replace always seem to submit the regional settings
> language though, instead of the language set in IE.
> This probably isnt the problem in your case but might be worth checking
just
> in case.
>
> -----Original Message-----
> From: Jagdish Arora [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 21 January 2003 18:29
> To: Struts Users Mailing List
> Subject: missing some step(s) in i18n; setLocale() works, IE's settings
> dont
>
>
>
> Hi all,
>
> Thanks for you help.
>
> I tried to convert my struts application to support multiple languages.
> However, it seems to me that application is not picking up the language
> setting set in IE (google does show up in Spanish, though).   However, If
I
> use setLocale in my LogonAction, the application does display the Spanish
> text (specified in ApplicationResources_es.properties) correctly.
>
> These are the steps that I did:
> 1) Put ApplicationResources.properties and
> ApplicationResources_es.properties under WEB-INF/resources
> 2) Put a content type UTF-8 declaration on top of all JSPs
> 3) Put (Craig/Apache)'s SetCharaceterEncodingFilter.java under filters in
> src.
> 4) Put the mapping of filter for ActionServlet in web.xml
> 5) Change the language of IE to spanish (the Google page does show up in
> Spanish).
> 6) Also tried to set the Locale in session in LogonAction.execute(), in
> which case, it picks up the correct file
>
>
> I am detailing the directory structure below, in case someone thinks it
> could be the issue.
>
> .ear
> |____.war
> |        |______servlet classes (some modules use HttpServlets)
> |        |______filters
> |                      |___SetCharaceterEncodingFilter
> |____.jar
>          |______com.fdt.lcp.* (actions/forms/models/daos/ejbs/utils)
>
>
> The struts.jar is not a part of the ear file.  It is under appserver/lib
> directory.  The Struts application runs fine, but internationalization is
> not working.
>
> thanks a bunch,
>
> Amrinder
>
> PS: This the change that I made to my web.xml to put filter mapping for
> action:
>
> <!-- Filter to set character encoding on each request -->
> <filter>
> <filter-name>Set Character Encoding</filter-name>
> <filter-class>filters.SetCharacterEncodingFilter</filter-class>
> <init-param>
> <param-name>encoding</param-name>
> <param-value>UTF-8</param-value>
> </init-param>
> </filter>
>
> <!-- Define filter mappings for the defined filters -->
> <filter-mapping>
> <filter-name>Set Character Encoding</filter-name>
> <servlet-name>action</servlet-name>
> </filter-mapping>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to