Localization of the game
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 04 Sep 2009 23:02:23 +0200
changeset 59fd7e8e705b75
parent 58 e00be634746c
child 60 74d333da1725
Localization of the game
freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game_cs.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login.fmt
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login_cs.properties
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Fri Sep 04 22:00:04 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Fri Sep 04 23:02:23 2009 +0200
     1.3 @@ -40,8 +40,11 @@
     1.4  import java.io.IOException;
     1.5  import java.net.URI;
     1.6  import java.util.HashMap;
     1.7 +import java.util.Locale;
     1.8  import java.util.Map;
     1.9 +import java.util.MissingResourceException;
    1.10  import java.util.Properties;
    1.11 +import java.util.ResourceBundle;
    1.12  import java.util.concurrent.Callable;
    1.13  import javax.ws.rs.DefaultValue;
    1.14  import javax.ws.rs.FormParam;
    1.15 @@ -225,9 +228,24 @@
    1.16      }
    1.17  
    1.18      private Viewable viewable(String page, Document doc, Object... more) {
    1.19 +        String bundle = page.split("\\.")[0];
    1.20 +
    1.21 +        ResourceBundle rb = null;
    1.22 +        for (Locale l : headers.getAcceptableLanguages()) {
    1.23 +            try {
    1.24 +                rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI." + bundle, l);
    1.25 +            } catch (MissingResourceException e) {
    1.26 +                // OK
    1.27 +            }
    1.28 +        }
    1.29 +        if (rb == null) {
    1.30 +            rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI." + bundle, Locale.ENGLISH);
    1.31 +        }
    1.32 +
    1.33          Map<String,Object> map = new HashMap<String,Object>();
    1.34          map.put("doc", doc);
    1.35          map.put("user", user);
    1.36 +        map.put("bundle", rb);
    1.37          for (int i = 0; i < more.length; i += 2) {
    1.38              map.put((String)more[i],more[i + 1]);
    1.39          }
     2.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt	Fri Sep 04 22:00:04 2009 +0200
     2.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt	Fri Sep 04 23:02:23 2009 +0200
     2.3 @@ -5,11 +5,11 @@
     2.4      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     2.5    </head>
     2.6    <body>
     2.7 -      <h1>Game</h1>
     2.8 -      <h3>${doc.game.id.@white} vs. ${doc.game.id.@black}</h3>
     2.9 +      <h1>${bundle.GAME}</h1>
    2.10 +      <h3>${doc.game.id.@white}${bundle.VS}${doc.game.id.@black}</h3>
    2.11  
    2.12        <p>
    2.13 -      <a href="/games/${doc.game.id.@id}">Reload</a>
    2.14 +      <a href="/games/${doc.game.id.@id}">${bundle.RELOAD}</a>
    2.15        </p>
    2.16        
    2.17        <#if message?? >
    2.18 @@ -42,10 +42,10 @@
    2.19                    <option>8</option>
    2.20                </select>
    2.21                <select name="direction">
    2.22 -                  <option>Horizontal</option>
    2.23 -                  <option>Vertical</option>
    2.24 +                  <option>${bundle.H}</option>
    2.25 +                  <option>${bundle.V}</option>
    2.26                </select>
    2.27 -              <input type="submit" value="Place!" />
    2.28 +              <input type="submit" value="${bundle.PLACE}" />
    2.29            </form>
    2.30            <form action="move">
    2.31                <input type="hidden" name="type" value="move" readonly="readonly"/>
    2.32 @@ -62,7 +62,7 @@
    2.33                    <option>N</option>
    2.34                    <option>S</option>
    2.35                </select>
    2.36 -              <input type="submit" value="Move!" />
    2.37 +              <input type="submit" value="${bundle.MOVE}" />
    2.38            </form>
    2.39        </#if>
    2.40        <pre>${doc.game.board}</pre>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.properties	Fri Sep 04 23:02:23 2009 +0200
     3.3 @@ -0,0 +1,7 @@
     3.4 +VS= vs.
     3.5 +PLACE=Place!
     3.6 +MOVE=Move!
     3.7 +H=Horizontal
     3.8 +V=Vertical
     3.9 +RELOAD=Reload
    3.10 +GAME=Game
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game_cs.properties	Fri Sep 04 23:02:23 2009 +0200
     4.3 @@ -0,0 +1,7 @@
     4.4 +VS=/
     4.5 +PLACE=Um\u00EDstit
     4.6 +MOVE=T\u00E1hnout
     4.7 +H=Horizont\u00E1ln\u011B
     4.8 +V=Vertik\u00E1ln\u011B
     4.9 +RELOAD=Obnovit
    4.10 +GAME=Hra
     5.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt	Fri Sep 04 22:00:04 2009 +0200
     5.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt	Fri Sep 04 23:02:23 2009 +0200
     5.3 @@ -5,10 +5,10 @@
     5.4      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     5.5    </head>
     5.6    <body>
     5.7 -      <h1>Quoridor Community Server</h1>
     5.8 +      <h1>${bundle.TITLE}</h1>
     5.9  
    5.10        <#macro game game>
    5.11 -          ${game.@white} vs. ${game.@black} <a href="/games/${game.@id}/">board</a>
    5.12 +          ${game.@white}${bundle.VS}${game.@black} <a href="/games/${game.@id}/">board</a>
    5.13        </#macro>
    5.14  
    5.15        <#if message?? >
    5.16 @@ -17,7 +17,7 @@
    5.17          </p>
    5.18        </#if>
    5.19  
    5.20 -      <h5>Games where you are expected to move</h5>
    5.21 +      <h5>${bundle.GAME_MOVE}</h5>
    5.22  
    5.23        <ol>
    5.24        <#list doc.gameIds.* as g>
    5.25 @@ -29,7 +29,7 @@
    5.26        </#list>
    5.27        </ol>
    5.28  
    5.29 -      <h5>Won games</h5>
    5.30 +      <h5>${bundle.GAME_WON}</h5>
    5.31  
    5.32        <ol>
    5.33        <#list doc.gameIds.* as g>
    5.34 @@ -44,7 +44,7 @@
    5.35        </#list>
    5.36        </ol>
    5.37  
    5.38 -      <h5>Lost games</h5>
    5.39 +      <h5>${bundle.GAME_LOST}</h5>
    5.40  
    5.41        <ol>
    5.42        <#list doc.gameIds.* as g>
    5.43 @@ -60,12 +60,12 @@
    5.44        </ol>
    5.45  
    5.46        <form action="games/create">
    5.47 -            White: <input type="text" name="white" value="" />
    5.48 -            Black: <input type="text" name="black" value="" />
    5.49 +            ${bundle.WHITE}: <input type="text" name="white" value="" />
    5.50 +            ${bundle.BLACK}: <input type="text" name="black" value="" />
    5.51              <input type="submit" value="Create!" />
    5.52        </form>
    5.53  
    5.54 -      <h5>All Games</h5>
    5.55 +      <h5>${bundle.GAME_ALL}</h5>
    5.56  
    5.57        <ol>
    5.58        <#list doc.gameIds.* as g>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties	Fri Sep 04 23:02:23 2009 +0200
     6.3 @@ -0,0 +1,10 @@
     6.4 +TITLE=Quoridor Community Server
     6.5 +VS= vs. 
     6.6 +GAME_MOVE=Games where you are expected to move
     6.7 +GAME_WON=Won games
     6.8 +GAME_LOST=Lost Games
     6.9 +CREATE=Create!
    6.10 +GAME_ALL=All Games
    6.11 +WHITE=White
    6.12 +BLACK=Black
    6.13 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties	Fri Sep 04 23:02:23 2009 +0200
     7.3 @@ -0,0 +1,9 @@
     7.4 +TITLE=Komunitn\u00ED server Quoridor
     7.5 +VS=/
     7.6 +GAME_MOVE=Jsi na tahu...
     7.7 +GAME_WON=Vyhran\u00E9
     7.8 +GAME_LOST=Prohran\u00E9
     7.9 +CREATE=Vytvo\u0159 novou
    7.10 +GAME_ALL=V\u0161echny hry
    7.11 +WHITE=B\u00EDl\u00FD
    7.12 +BLACK=\u010Cern\u00FD
     8.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login.fmt	Fri Sep 04 22:00:04 2009 +0200
     8.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login.fmt	Fri Sep 04 23:02:23 2009 +0200
     8.3 @@ -5,15 +5,15 @@
     8.4      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8.5    </head>
     8.6    <body>
     8.7 -      <h1>Quoridor Community Server</h1>
     8.8 -      <h2>Login</h2>
     8.9 +      <h1>${bundle.TITLE}</h1>
    8.10 +      <h2>${bundle.LOGIN}</h2>
    8.11  
    8.12        <b>${message!""}</b>
    8.13  
    8.14        <form action="login" method="post">
    8.15 -            Name: <input type="text" name="name"/>
    8.16 -            Password: <input type="password" name="password"/>
    8.17 -            <input type="submit" value="Login!"/>
    8.18 +            ${bundle.NAME}: <input type="text" name="name"/>
    8.19 +            ${bundle.PASSWORD}: <input type="password" name="password"/>
    8.20 +            <input type="submit" value="${bundle.LOGIN}"/>
    8.21        </form>
    8.22    </body>
    8.23  </html>
    8.24 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login.properties	Fri Sep 04 23:02:23 2009 +0200
     9.3 @@ -0,0 +1,4 @@
     9.4 +TITLE=Quoridor Community Server
     9.5 +NAME=Name
     9.6 +PASSWORD=Password
     9.7 +LOGIN=Login!
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/login_cs.properties	Fri Sep 04 23:02:23 2009 +0200
    10.3 @@ -0,0 +1,4 @@
    10.4 +TITLE=Komunitn\u00ED server Quoridor
    10.5 +NAME=Jm\u00E9no
    10.6 +PASSWORD=Heslo
    10.7 +LOGIN=P\u0159ihl\u00E1sit se