1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Wed Dec 23 07:59:16 2009 +0100
1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Wed Dec 23 20:45:19 2009 +0100
1.3 @@ -39,6 +39,7 @@
1.4 import java.io.IOException;
1.5 import java.io.InputStream;
1.6 import java.net.URI;
1.7 +import java.util.Date;
1.8 import java.util.HashMap;
1.9 import java.util.List;
1.10 import java.util.Locale;
1.11 @@ -407,10 +408,12 @@
1.12 private Viewable viewable(String page, Document doc, Object... more) {
1.13 ResourceBundle rb = null;
1.14 String lng = user == null ? null : user.getProperty("language"); // NOI18N
1.15 + Locale locale = null;
1.16 if (lng != null) {
1.17 try {
1.18 Locale l = new Locale(lng);
1.19 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", l);
1.20 + locale = l;
1.21 } catch (MissingResourceException e) {
1.22 // OK
1.23 }
1.24 @@ -419,6 +422,8 @@
1.25 for (Locale l : headers.getAcceptableLanguages()) {
1.26 try {
1.27 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", l);
1.28 + locale = l;
1.29 + break;
1.30 } catch (MissingResourceException e) {
1.31 // OK
1.32 }
1.33 @@ -426,15 +431,26 @@
1.34 }
1.35 if (rb == null) {
1.36 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", Locale.ENGLISH);
1.37 + locale = Locale.ENGLISH;
1.38 }
1.39
1.40 Map<String,Object> map = new HashMap<String,Object>();
1.41 + class ConvertToDate extends HashMap<Object,Object> {
1.42 + @Override
1.43 + public Object get(Object o) {
1.44 + long time = Long.parseLong(o.toString());
1.45 + return new Date(time);
1.46 + }
1.47 + }
1.48 +
1.49 + map.put("locale", locale.toString());
1.50 map.put("doc", doc);
1.51 if (user != null) {
1.52 map.put("user", user.getId());
1.53 map.put("email", user.getProperty("email"));
1.54 }
1.55 map.put("bundle", rb);
1.56 + map.put("toDate", new ConvertToDate());
1.57 map.put("now", System.currentTimeMillis());
1.58 map.put("version", version);
1.59 for (int i = 0; i < more.length; i += 2) {
2.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/Bundle.properties Wed Dec 23 07:59:16 2009 +0100
2.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/Bundle.properties Wed Dec 23 20:45:19 2009 +0100
2.3 @@ -8,14 +8,15 @@
2.4 gameWhiteBlack={0} vs. {1}
2.5 LastMove=Last move {1,choice,\
2.6 0#second|\
2.7 - 2#{1} seconds|\
2.8 - 60#a minute|\
2.9 - 120#{2} minutes|\
2.10 - 3600#an hour|\
2.11 - 7200#{3} hours|\
2.12 - 86400#a day|\
2.13 - 172800#{4} days\
2.14 -} ago
2.15 + 2#{1} seconds ago|\
2.16 + 60#a minute ago|\
2.17 + 120#{2} minutes ago|\
2.18 + 3600#an hour ago|\
2.19 + 7200#{3} hours ago|\
2.20 + 86400#a day ago|\
2.21 + 172800#{4} days ago|\
2.22 + 1000000#on {5}\
2.23 +}
2.24 GAME_MOVE=Your move
2.25 GAME_WAIT=Opponent's move
2.26 GAME_WON=Won games ({0})
3.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/Bundle_cs.properties Wed Dec 23 07:59:16 2009 +0100
3.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/Bundle_cs.properties Wed Dec 23 20:45:19 2009 +0100
3.3 @@ -14,24 +14,25 @@
3.4 GAME_ALL=V\u0161echny hry
3.5 WHITE=B\u00EDl\u00FD
3.6 BLACK=\u010Cern\u00FD
3.7 -LastMove=T\u00E1hnuto p\u0159ed {1,choice,\
3.8 - 0#chv\u00EDl\u00ED|\
3.9 - 10#{1}-ti sekundami|\
3.10 - 60#minutou|\
3.11 - 120#dv\u011Bma minutami|\
3.12 - 180#t\u0159emi minutami|\
3.13 - 240#\u010Dty\u0159mi minutami|\
3.14 - 300#{2}-ti minutami|\
3.15 - 3600#hodinou|\
3.16 - 7200#dv\u011Bma hodinami|\
3.17 - 10800#t\u0159emi hodinami|\
3.18 - 14400#\u010Dty\u0159mi hodinami|\
3.19 - 18000#{3}-ti hodinami|\
3.20 - 86400#jedn\u00EDm dnem|\
3.21 - 172800#dv\u011Bma dny|\
3.22 - 259200#t\u0159emi dny|\
3.23 - 345600#\u010Dty\u0159mi dny|\
3.24 - 432000#{4}-ti dny\
3.25 +LastMove={1,choice,\
3.26 + 0#T\u00E1hnuto p\u0159ed chv\u00EDl\u00ED|\
3.27 + 10#T\u00E1hnuto p\u0159ed {1}-ti sekundami|\
3.28 + 60#T\u00E1hnuto p\u0159ed minutou|\
3.29 + 120#T\u00E1hnuto p\u0159ed dv\u011Bma minutami|\
3.30 + 180#T\u00E1hnuto p\u0159ed t\u0159emi minutami|\
3.31 + 240#T\u00E1hnuto p\u0159ed \u010Dty\u0159mi minutami|\
3.32 + 300#T\u00E1hnuto p\u0159ed {2}-ti minutami|\
3.33 + 3600#T\u00E1hnuto p\u0159ed hodinou|\
3.34 + 7200#T\u00E1hnuto p\u0159ed dv\u011Bma hodinami|\
3.35 + 10800#T\u00E1hnuto p\u0159ed t\u0159emi hodinami|\
3.36 + 14400#T\u00E1hnuto p\u0159ed \u010Dty\u0159mi hodinami|\
3.37 + 18000#T\u00E1hnuto p\u0159ed {3}-ti hodinami|\
3.38 + 86400#T\u00E1hnuto p\u0159ed jedn\u00EDm dnem|\
3.39 + 172800#T\u00E1hnuto p\u0159ed dv\u011Bma dny|\
3.40 + 259200#T\u00E1hnuto p\u0159ed t\u0159emi dny|\
3.41 + 345600#T\u00E1hnuto p\u0159ed \u010Dty\u0159mi dny|\
3.42 + 432000#T\u00E1hnuto p\u0159ed {4}-ti dny|\
3.43 + 1000000#{5} je den posledn\u00EDho tahu\
3.44 }
3.45
3.46 NEXT=Dal\u0161\u00ED
4.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Wed Dec 23 07:59:16 2009 +0100
4.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Wed Dec 23 20:45:19 2009 +0100
4.3 @@ -1,5 +1,6 @@
4.4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4.5 <html>
4.6 + <#setting locale = locale/>
4.7 <#assign toMove = 0/>
4.8 <#assign toWait = 0/>
4.9 <#assign toWon = 0/>
4.10 @@ -43,18 +44,20 @@
4.11 <body bgcolor="white">
4.12 <h1>${bundle.TITLE}</h1>
4.13
4.14 - <#macro before t>
4.15 + <#macro before t w>
4.16 <#assign seconds = (t / 1000)?long/>
4.17 <#assign minutes= (seconds / 60)?long/>
4.18 <#assign hours= (minutes / 60)?long/>
4.19 <#assign days= (hours / 24)?long/>
4.20 <!--millis: ${t}, seconds: ${seconds}, minutes: ${minutes} hours: ${hours}, days: ${days} -->
4.21 - ${bundle("LastMove", t?int, seconds?int, minutes?int, hours?int, days?int)}
4.22 + ${bundle("LastMove", t?int, seconds?int, minutes?int, hours?int, days?int, w?date?string.long)}
4.23 </#macro>
4.24
4.25 <#macro game game>
4.26 - ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)}
4.27 - <a href="/games/${game.@id}/"><@before (now - game.@modified?number)?long/></a>
4.28 + ${bundle("gameWhiteBlack", game.@white?string, game.@black?string)}
4.29 + <#assign sinceNow= now - game.@modified?number/>
4.30 + <#assign when=toDate[game.@modified?string]/>
4.31 + <a href="/games/${game.@id}/"><@before t=sinceNow w=when/></a>
4.32 <#if game.@comments?number != 0>
4.33 ${bundle("comments", game.@comments?number)}
4.34 </#if>