multi-language support
[pnews.git] / war / src / main / java / pnews / servlet / Config.java
index 09a5457..bafb606 100644 (file)
@@ -23,11 +23,16 @@ public class Config {
         private Feed[] feeds;
         private Category[] categories;
         private Language[] languages;
+        /**
+         * The key is the language, the value is the default category for this language.
+         */
+        private Map<String, Category> defaultCategories = new HashMap<>();
         private static final Logger LOG = Logger.getLogger(Config.class.getName());
                 
         private void loadCategories(JsonArray jcats) {
                 List<Category> cats;
                 JsonObject jcat;
+                Category cat;
                 String id, label, title, language;
                 
                 cats = new ArrayList<>(jcats.size());
@@ -38,7 +43,10 @@ public class Config {
                         label = jcat.getString("label");
                         title = jcat.getString("title");
                         language = jcat.getString("language");
-                        cats.add(new Category(id, label, title, language));
+                        cat = new Category(id, label, title, language);
+                        cats.add(cat);
+                        if (defaultCategories.get(language) == null)
+                                defaultCategories.put(language, cat);
                 }
                 
                 categories = cats.toArray(new Category[0]);
@@ -141,8 +149,8 @@ public class Config {
                 return categories;
         }
         
-        public Category getDefaultCategory() {
-                return categories[0];
+        public Category getDefaultCategory(Language lang) {
+                return defaultCategories.get(lang.getId());
         }
         
         public Language[] getLanguages() {