Hi there!

I was wondering how ThreadLocale's Locale can be set depending on its
URL/domain/subdomain....

I am injecting ThreadLocale to contributeRequestHandler in AppModule:

public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
configuration,
            @Local
            RequestFilter filter,
            final ThreadLocale threadLocale)
    {
        
         
        Map<String, Locale> serverNameMappings = new
HashMap<String,Locale>();
                
        serverNameMappings.put("www.domain.de", Locale.GERMAN);
        serverNameMappings.put("subdomain.domain.de", Locale.ENGLISH);
                
                                
        configuration.add("HostBasedLocalization", new
HostBasedLocaleFilter(threadLocale, serverNameMappings),
        "after:Localization");
        
    }


The HostBasedLocaleFilter looks like this:

public class HostBasedLocaleFilter implements RequestFilter {

        private Map<String, Locale> serverNameMapping;

        private ThreadLocale threadLocale;

        public HostBasedLocaleFilter(final ThreadLocale threadLocale,
                        final Map<String, Locale> serverNameMapping) {
                this.serverNameMapping = serverNameMapping;
                this.threadLocale = threadLocale;
        }

        public boolean service(Request request, Response response,
                        RequestHandler handler) throws IOException {
                String servername = request.getServerName();
                Locale locale = this.serverNameMapping.get(servername);
                if (locale == null) {
                        locale = Locale.ENGLISH;
                }
                threadLocale.setLocale(locale);
                return handler.service(request, response);
        }

}

However, accessing the page from a subdomain does not change the Locale.


Thanks!

Tobias

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

Reply via email to