freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
changeset 59 fd7e8e705b75
parent 57 fa12b02023a0
child 68 33cf89760fab
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Fri Sep 04 21:14:33 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          }