> I've never heard of filters named "SetupRender" or "BeginRender" so I'm
> pretty sure "before:SetupRender" has no effect
I just tried this while I was trying to get it work.

> Interfaces are very necessary!!!. They are crucial to tapestry to support
> lazy loading etc. You should NEVER refer to your services by their concrete
> type.

> Should be:
> binder.bind(RequestFilter.class, TimingFilter.class).withSimpleId();
> should be:
> public static void
> contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
> @InjectService("TimingFilter") RequestFilter timingFilter) {;

Ok, I didn't know that.  

Now the code is:

        binder.bind(RequestFilter.class, TimingFilter.class).withSimpleId();
        binder.bind(RequestFilter.class, 
LocaleRequestFilter.class).withSimpleId();

and:

    public static void contributeRequestHandler(
            OrderedConfiguration<RequestFilter> configuration,
            @InjectService("TimingFilter") RequestFilter timingFilter,
            @InjectService("LocaleRequestFilter") RequestFilter 
localeRequestFilter) {
        configuration.add("TimingFilter", timingFilter);
        configuration.add("LocaleRequestFilter", localeRequestFilter, 
"before:*");
    }

> René, I think I've figured out what your problem is. You should not be using
> LocalizationSetter as this is backed by the PersistantLocale which is
> ultimately responsible for including the language as the first folder in the
> URL.

I've also changed this, to:

public class LocaleRequestFilter implements RequestFilter {

    private Cookies cookies;
    private ThreadLocale threadLocale;

    public LocaleRequestFilter(Cookies cookies, ThreadLocale threadLocale) {
        this.cookies = cookies;
        this.threadLocale = threadLocale;
    }

    @Override
    public boolean service(Request request, Response response, RequestHandler 
handler) throws IOException {
        TranslatedLanguage preferredLanguage;

        String languageValueInCookie = 
cookies.readCookieValue(PlainTraySetting.COOKIE_LANGUAGE_VALUE_NAME);
        String languageValueInHttpRequest = request.getLocale().getLanguage();

        if (languageValueInCookie != null) {
            preferredLanguage = 
TranslatedLanguage.findLanguage(languageValueInCookie);
        } else {
            preferredLanguage = 
TranslatedLanguage.findLanguage(languageValueInHttpRequest);
        }

        if (preferredLanguage == null) {
            preferredLanguage = PlainTraySetting.DEFAULT_LANGUAGE;
        }

        if (languageValueInCookie == null) {
            
cookies.writeCookieValue(PlainTraySetting.COOKIE_LANGUAGE_VALUE_NAME, 
preferredLanguage.toString());
        }

        System.out.println("set locale to " + new 
Locale(preferredLanguage.toString()).getLanguage());
        threadLocale.setLocale(new Locale(preferredLanguage.toString()));
        System.out.println("get locale is " + 
threadLocale.getLocale().getLanguage());
        return handler.service(request, response);
    }
}

I see the output "set locale to de" and on the next line "get locale is de", so 
I'm pretty sure threadLocale.setLocale(...) ran correctly.
But it still doesn't work. I always get the browser locale (English). 


On 08.02.2013 13:58, Lance Java wrote:
> René, I think I've figured out what your problem is. You should not be using
> LocalizationSetter as this is backed by the PersistantLocale which is
> ultimately responsible for including the language as the first folder in the
> URL.
>
> As I said initially, if you want your own custom logic (ie storing in a
> cookie) then I suggest you use ThreadLocale instead.
>
>
>
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/How-to-call-locale-properties-file-based-on-urls-tp5719862p5719874.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to