Results 1 to 6 of 6

Thread: how can I set locale for Surf Application?

  1. #1
    Join Date
    Oct 2010
    Location
    Tokyo, Japan
    Posts
    4

    Unhappy how can I set locale for Surf Application?

    Hello everyone,

    I'm trying to make Spring Surf work with Alfresco and
    set locale as user select in login page.
    I actually set locale but messages of xxxx.get_ja.properties are always displayed whatever locale I choose.

    So far, I've done for customization as followings.

    ####### [ADD]
    jp.aegif.springframework.extensions.surf.mvc.Local eResolver
    this class receives request parameter sent from login.ftl and set locale using I18NUtil#setLocale.

    jp.aegif.springframework.extensions.surf.mvc.Login Controller
    replaced default LoginController with this class to set locale in it.

    ####### [CHANGE]
    SRC_MAIN_WEBAPP/WEB-INF/templates/sample/loginf.ftl
    added select component which includes values "en_US", "de_DE" and "ja_JP".


    SRC_MAIN_WEBAPP/WEB-INF/config/web-application-config.xml
    override default LoaleResolver bean definition with custom LocaleResolver class.
    <bean id="localeResolver"
    class="jp.aegif.springframework.extensions.surf.mv c.LocaleResolver" />

    override default LoginController bean definition with custom LoginController class.
    <bean id="loginController"
    class="jp.aegif.springframework.extensions.surf.mv c.LoginController">
    <property name="cacheSeconds" value="-1" />
    <property name="useExpiresHeader">
    <value>true</value>
    </property>
    <property name="useCacheControlHeader">
    <value>true</value>
    </property>
    </bean>

    #######
    and comment out default Surf codes because I want to let Surf work using locale selected in login.
    org.springframework.extensions.surf.site.servlet.B aseServlet
    56 //I18NUtil.setLocale(I18NUtil.parseLocale(language)) ;

    org.springframework.extensions.webscripts.servlet. mvc.WebScriptView
    119 //I18NUtil.setLocale(I18NUtil.parseLocale(language)) ;

    org.springframework.extensions.webscripts.servlet. WebScriptServlet
    141 //I18NUtil.setLocale(I18NUtil.parseLocale(language)) ;

    #######
    I also debugged by changing I18NUtil#getLocale as...
    98 public static Locale getLocale()
    99 {
    100 Locale locale = threadLocale.get();
    101 System.err.println("threadLocale: " + threadLocale.toString());
    102 if (locale == null)
    103 {
    104 // Get the default locale
    105 locale = Locale.getDefault();
    106 System.err.println("[aegif] I18NUtil: locale == null. Get DefaultLocale");
    107 } else {
    108 System.err.println("[aegif] locale already set -> " + locale);
    109 }
    110 return locale;
    111 }

    Outputs are...
    [aegif] locale already set -> en_US
    threadLocale: java.lang.ThreadLocal@6f1dc409
    [aegif] locale already set -> en_US
    threadLocale: java.lang.ThreadLocal@6f1dc409
    [aegif] I18NUtil: locale == null. Get DefaultLocale (**NOTE: Where has "en_US" setting gone?)
    threadLocale: java.lang.ThreadLocal@6f1dc409
    [aegif] I18NUtil: locale == null. Get DefaultLocale

    Locale seems to be set with "en_US" a bit after login.
    But "en_US" disappears suddenly.

    Why does it happen? Do I have any mistakes?
    Thanks in advance.

    ---
    mryoshio

  2. #2
    Join Date
    Oct 2010
    Location
    Tokyo, Japan
    Posts
    4

    Default

    My Spring Surf version is 1.0.0.M3.

    Best regards,
    mryoshio

  3. #3

    Default

    SpringSurf (and SpringMVC) are naturally wired up to set the locale to whatever is passed in the browser language header value. I assume what you want to do is override that, i.e. fix the locale from a selection on the login page?

  4. #4
    Join Date
    Oct 2010
    Location
    Tokyo, Japan
    Posts
    4

    Default

    kroast,

    Thanks for reply, and that's right. It's what I want to do.
    But Spring Surf won't work as I want it to.

    I missed something?

    ---
    mryoshio

  5. #5

    Default

    Hi,

    The SpringSurf locale handling is provided by a spring bean:
    Code:
        <!-- Locale Resolver -->
        <bean id="localeResolver" class="org.springframework.extensions.surf.mvc.LocaleResolver" />
    If you override that with your own impl that will get your started - currently this bean looks at the Accept-Header and applies it to the I18N util class.

    SpringMVC provides a couple of these beans that you might want to look at:
    org.springframework.web.servlet.i18n.AcceptHeaderL ocaleResolver
    org.springframework.web.servlet.i18n.CookieLocaleR esolver
    org.springframework.web.servlet.i18n.FixedLocaleRe solver
    org.springframework.web.servlet.i18n.SessionLocale Resolver

    Kev

  6. #6
    Join Date
    Oct 2010
    Location
    Tokyo, Japan
    Posts
    4

    Smile

    Hi,

    Thanks for information.
    Finally I succeeded in setting locale with using custom interceptor which makes use of session attribute.

    Unfortunately I couldn't fulfill my purpose when I use custom class which extends SessionLocaleResolver.

    thanks
    mryoshio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •