diff --git a/src/main/java/org/traccar/web/server/model/GuiceServletConfig.java b/src/main/java/org/traccar/web/server/model/GuiceServletConfig.java index 52f5823d..831c0b5b 100644 --- a/src/main/java/org/traccar/web/server/model/GuiceServletConfig.java +++ b/src/main/java/org/traccar/web/server/model/GuiceServletConfig.java @@ -57,6 +57,7 @@ protected void configureServlets() { install(new JpaPersistModule(persistenceUnit)); filter("/traccar/*").through(PersistFilter.class); + filter("/", "/traccar.html", "/m/", "/m/index.html").through(LocaleFilter.class); serve("/traccar/dataService").with(DataServiceImpl.class); serve("/traccar/uiStateService").with(UIStateServiceImpl.class); diff --git a/src/main/java/org/traccar/web/server/model/LocaleFilter.java b/src/main/java/org/traccar/web/server/model/LocaleFilter.java new file mode 100644 index 00000000..b1ae9eea --- /dev/null +++ b/src/main/java/org/traccar/web/server/model/LocaleFilter.java @@ -0,0 +1,53 @@ +/* + * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.web.server.model; + +import com.google.inject.persist.Transactional; +import org.traccar.web.shared.model.ApplicationSettings; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Singleton +public class LocaleFilter implements Filter { + @Inject + Provider applicationSettings; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + @Transactional + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + ((HttpServletResponse) servletResponse).addCookie(new Cookie("GWT_LOCALE", applicationSettings.get().getLanguage())); + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + } +}