+ private static void writeTranslationToFile(Document doc, File file) throws TransformerFactoryConfigurationError, TransformerConfigurationException, FileNotFoundException, TransformerException, IOException {
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer();
+
+ DOMSource source = new DOMSource(doc);
+ FileOutputStream fos = new FileOutputStream(file);
+ StreamResult result = new StreamResult(fos);
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ transformer.transform(source, result);
+ fos.close();
+ }
+
+ private static int addTranslationsFromPo(Document doc, URL fetch) throws IOException, UnsupportedEncodingException {
+ URLConnection uc = fetch.openConnection();
+ Scanner sc = new Scanner(new InputStreamReader(uc.getInputStream(), "UTF-8"));
+ String s = readLine(sc);
+ StringBuffer contents = new StringBuffer();
+ String id = "";
+ int count = 0;
+ while (s != null) {
+ if (s.startsWith("msgid")) {
+ count++;
+ contents.delete(0, contents.length());
+ s = readString(s, sc, contents);
+ id = contents.toString();
+ continue;
+ } else if (s.startsWith("msgstr")) {
+ contents.delete(0, contents.length());
+ // System.out.println("msgstr");
+ s = readString(s, sc, contents);
+ String msg = contents.toString().replace("\\\"", "\"").replace("\\n", "\n");
+ insertTranslation(doc, id, msg);
+ } else if (s.startsWith("#")) {
+ // System.out.println(s);
+ } else if (s.equals("") || s.equals("\r")) {
+
+ } else {
+ System.out.println("unknown line: " + s);
+ }
+ s = readLine(sc);
+ }
+ return count;
+ }
+