Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/action/SwitchLanguageAction.java @ 706:2659a5b1fa1e
Added a link (and a controller) to toggle between german and english language (issue254).
gnv/trunk@970 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Apr 2010 07:55:05 +0000 |
parents | |
children | b7c6bf3cd7c9 |
comparison
equal
deleted
inserted
replaced
705:f550bd27a3f1 | 706:2659a5b1fa1e |
---|---|
1 package de.intevation.gnv.action; | |
2 | |
3 import de.intevation.gnv.action.sessionmodel.SessionModel; | |
4 import de.intevation.gnv.action.sessionmodel.SessionModelFactory; | |
5 | |
6 import java.util.Locale; | |
7 | |
8 import javax.servlet.http.HttpServletRequest; | |
9 import javax.servlet.http.HttpServletResponse; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 | |
13 import org.apache.struts.action.ActionForm; | |
14 import org.apache.struts.action.ActionForward; | |
15 import org.apache.struts.action.ActionMapping; | |
16 | |
17 /** | |
18 * Toggle the current language used to create the user interface. Two | |
19 * languages are available now - german and english. | |
20 * | |
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
22 */ | |
23 public class SwitchLanguageAction extends DescribeUIAction { | |
24 | |
25 public static Logger logger = Logger.getLogger(SwitchLanguageAction.class); | |
26 | |
27 @Override | |
28 public ActionForward execute( | |
29 ActionMapping mapping, | |
30 ActionForm form, | |
31 HttpServletRequest request, | |
32 HttpServletResponse response | |
33 ) throws Exception | |
34 { | |
35 SessionModelFactory factory = SessionModelFactory.getInstance(); | |
36 SessionModel sm = factory.getSessionModel(request); | |
37 | |
38 sm.setCurrentLocale(switchLanguage(sm.getCurrentLocale())); | |
39 | |
40 return super.execute(mapping, form, request, response); | |
41 } | |
42 | |
43 | |
44 /** | |
45 * This method toggles between german and english language. | |
46 * | |
47 * @param currentLocale The locale which is currently used. | |
48 * @return an english locale, if the current locale is german - otherwise | |
49 * a german locale. | |
50 */ | |
51 protected Locale switchLanguage(Locale currentLocale) { | |
52 if (currentLocale.getLanguage().equals(Locale.GERMAN.getLanguage())) { | |
53 logger.info("Switch from german to english locale."); | |
54 return Locale.ENGLISH; | |
55 } | |
56 else { | |
57 logger.info("Switch from english to german locale."); | |
58 return Locale.GERMAN; | |
59 } | |
60 } | |
61 } | |
62 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |