X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FLanguage.java;h=75593ccf723618a47598b084611d971c987c809e;hb=6b985b637949909402c2e7be5e682b33d5e6abcd;hp=5841c3c35dc918b025df178735d3e1500706f12e;hpb=06c5d96d7dc2df71a1658e1c7c9e34ad065d10d7;p=gigi.git diff --git a/src/org/cacert/gigi/Language.java b/src/org/cacert/gigi/Language.java index 5841c3c3..75593ccf 100644 --- a/src/org/cacert/gigi/Language.java +++ b/src/org/cacert/gigi/Language.java @@ -5,10 +5,12 @@ 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; +import org.cacert.gigi.util.HTMLEncoder; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -18,8 +20,8 @@ public class Language { private static HashMap langs = new HashMap(); HashMap translations = new HashMap(); Locale l; - private Language(String language) throws ParserConfigurationException, - IOException, SAXException { + + private Language(String language) throws ParserConfigurationException, IOException, SAXException { if (language.contains("_")) { String[] parts = language.split("_"); l = new Locale(parts[0], parts[1]); @@ -29,8 +31,7 @@ public class 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)) { @@ -39,10 +40,11 @@ public class Language { Element e = (Element) nl.item(i); Element id = (Element) e.getElementsByTagName("id").item(0); Element msg = (Element) e.getElementsByTagName("msg").item(0); - translations.put(id.getTextContent(), msg.getTextContent()); + translations.put(id.getTextContent(), HTMLEncoder.encodeHTML(msg.getTextContent())); } System.out.println(translations.size() + " strings loaded."); } + public String getTranslation(String text) { String string = translations.get(text); if (string == null || string.equals("")) { @@ -50,6 +52,7 @@ public class Language { } return string; } + public static Language getInstance(String language) { Language l = langs.get(language); if (l == null) { @@ -66,6 +69,7 @@ public class Language { } return l; } + public Locale getLocale() { return l; }