]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/Language.java
Merge branch 'templateHotDeploy' into newm
[gigi.git] / src / org / cacert / gigi / Language.java
index 431f0b32a41989fa2ff87a4e45aae4eec47e218f..fc94ce1b766fecb897f6ad3a9804d6bb501328bb 100644 (file)
@@ -4,7 +4,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.HashMap;
-
+import java.util.Locale;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -17,12 +17,19 @@ import org.xml.sax.SAXException;
 public class Language {
        private static HashMap<String, Language> langs = new HashMap<String, Language>();
        HashMap<String, String> translations = new HashMap<String, String>();
-       private Language(String language) throws ParserConfigurationException,
-                       IOException, SAXException {
+       Locale l;
+
+       private Language(String language) throws ParserConfigurationException, IOException, SAXException {
+               if (language.contains("_")) {
+                       String[] parts = language.split("_");
+                       l = new Locale(parts[0], parts[1]);
+               } else {
+                       l = new Locale(language);
+               }
+
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
-               Document d = db.parse(new FileInputStream(new File("locale", language
-                               + ".xml")));
+               Document d = db.parse(new FileInputStream(new File("locale", language + ".xml")));
                NodeList nl = d.getDocumentElement().getChildNodes();
                for (int i = 0; i < nl.getLength(); i++) {
                        if (!(nl.item(i) instanceof Element)) {
@@ -35,6 +42,15 @@ public class Language {
                }
                System.out.println(translations.size() + " strings loaded.");
        }
+
+       public String getTranslation(String text) {
+               String string = translations.get(text);
+               if (string == null || string.equals("")) {
+                       return text;
+               }
+               return string;
+       }
+
        public static Language getInstance(String language) {
                Language l = langs.get(language);
                if (l == null) {
@@ -51,7 +67,9 @@ public class Language {
                }
                return l;
        }
-       public static void main(String[] args) {
-               Language.getInstance("de");
+
+       public Locale getLocale() {
+               return l;
        }
+
 }