Example #1
0
 private void convertFile(
     Factory cldrFactory, String id, String outputDirectory, PrintWriter index)
     throws IOException {
   PrintWriter output = null;
   String filename = null;
   CLDRFile cldrFile = cldrFactory.make(id, false);
   boolean first = true;
   for (Iterator<String> it = cldrFile.iterator("", cldrFile.getComparator()); it.hasNext(); ) {
     String path = it.next();
     if (path.indexOf("/version") >= 0 || path.indexOf("/generation") >= 0) {
       continue;
     }
     String value = cldrFile.getStringValue(path);
     if (first) {
       String fullPath = cldrFile.getFullXPath(path);
       filename = addIndexInfo(index, fullPath, id);
       if (filename == null) return; // not a transform file!
       output = BagFormatter.openUTF8Writer(outputDirectory, filename);
       doHeader(output, "#", filename);
       first = false;
     }
     if (path.indexOf("/comment") >= 0) {
       if (!skipComments) {
         showComments(output, value);
       }
     } else if (path.indexOf("/tRule") >= 0) {
       value = fixup.transliterate(value);
       output.println(value);
     } else {
       throw new IllegalArgumentException("Unknown element: " + path + "\t " + value);
     }
   }
   output.close();
 }
Example #2
0
 public void writeTransforms(String inputDirectory, String matchingPattern, String outputDirectory)
     throws IOException {
   System.out.println(new File(inputDirectory).getCanonicalPath());
   Factory cldrFactory = Factory.make(inputDirectory, matchingPattern);
   Set<String> ids = cldrFactory.getAvailable();
   PrintWriter index = BagFormatter.openUTF8Writer(outputDirectory, "root.txt");
   doHeader(index, "//", "root.txt");
   try {
     index.println("root {");
     index.println("    RuleBasedTransliteratorIDs {");
     // addAlias(index, "Latin", "el", "", "Latin", "Greek", "UNGEGN");
     // addAlias(index, "el", "Latin", "", "Greek", "Latin", "UNGEGN");
     // addAlias(index, "Latin", "Jamo", "", "Latin", "ConjoiningJamo", "");
     addAlias(index, "Tone", "Digit", "", "Pinyin", "NumericPinyin", "");
     addAlias(index, "Digit", "Tone", "", "NumericPinyin", "Pinyin", "");
     // addAlias(index, "Simplified", "Traditional", "", "Hans", "Hant", "");
     // addAlias(index, "Traditional", "Simplified", "", "Hant", "Hans", "");
     for (String id : ids) {
       if (id.equals("All")) continue;
       try {
         convertFile(cldrFactory, id, outputDirectory, index);
       } catch (IOException e) {
         System.err.println("Failure in: " + id);
         throw e;
       }
     }
     index.println("    }");
     index.println("    TransliteratorNamePattern {");
     index.println("        // Format for the display name of a Transliterator.");
     index.println("        // This is the language-neutral form of this resource.");
     index.println("        \"{0,choice,0#|1#{1}|2#{1}-{2}}\" // Display name");
     index.println("    }");
     index.println("    // Transliterator display names");
     index.println("    // This is the English form of this resource.");
     index.println("    \"%Translit%Hex\"         { \"%Translit%Hex\" }");
     index.println("    \"%Translit%UnicodeName\" { \"%Translit%UnicodeName\" }");
     index.println("    \"%Translit%UnicodeChar\" { \"%Translit%UnicodeChar\" }");
     index.println("    TransliterateLATIN{        ");
     index.println("    \"\",");
     index.println("    \"\"");
     index.println("    }");
     index.println("}");
   } finally {
     index.close();
   }
 }
Example #3
0
  private int writeFile(
      String title,
      UnicodeSet sourceSet,
      Transliterator nfd,
      Transliterator toLatin,
      Transliterator fromLatin,
      boolean doLatin,
      UnicodeSet nativeSpecials,
      UnicodeSet latinSpecials)
      throws IOException {
    int errorCount = 0;
    PrintWriter out =
        BagFormatter.openUTF8Writer(
            org.unicode.cldr.util.CLDRPaths.GEN_DIRECTORY + "transTest/", title + ".html");
    out.println("<html><head>");
    out.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>");
    if (nativeSpecials != null) {
      out.println(
          "<h1>Specials</h1><table border='1' cellpadding='2' cellspacing='0' style='border-collapse: collapse'>");
      showItems(out, true, "Source", "ToLatin", "FromLatin", "BackToLatin");
      for (UnicodeSetIterator it = new UnicodeSetIterator(nativeSpecials); it.next(); ) {
        String item = it.getString();
        errorCount = checkString(out, item, nfd, fromLatin, toLatin, errorCount, null);
        errorCount = checkString(out, item, nfd, fromLatin, toLatin, errorCount, "-");
      }
      out.println("</table><p>Special failures:\t" + errorCount + "</p>");
      if (errorCount != 0) {
        errln("Special failures:\t" + errorCount);
        errorCount = 0;
      }
    }

    if (latinSpecials != null) {
      out.println(
          "<h1>Specials</h1><table border='1' cellpadding='2' cellspacing='0' style='border-collapse: collapse'>");
      showItems(out, true, "Latin", "ToNative", "BackToLatin", "BackToNative");
      for (UnicodeSetIterator it = new UnicodeSetIterator(latinSpecials); it.next(); ) {
        String item = it.getString();
        errorCount = checkString(out, item, nfd, toLatin, fromLatin, errorCount, null);
        // errorCount = checkString(out, item, nfd, fromLatin, toLatin, errorCount, "-");
      }
      out.println("</table><p>Special failures:\t" + errorCount + "</p>");
      if (errorCount != 0) {
        errln("Special failures:\t" + errorCount);
        errorCount = 0;
      }
    }

    if (doLatin) {
      out.println(
          "<h1>Latin failures</h1><table border='1' cellpadding='2' cellspacing='0' style='border-collapse: collapse'>");
      showItems(out, true, "Latin", "Target", "BackToLatin", "BackToTarget");
      errorCount = checkLatin(out, fromLatin, toLatin);
      out.println("</table><p>Latin failures:\t" + errorCount + "</p>");
      if (errorCount != 0) {
        errln("Latin failures:\t" + errorCount);
        errorCount = 0;
      }
    }

    out.println(
        "<h1>Not Reversible</h1><table border='1' cellpadding='2' cellspacing='0' style='border-collapse: collapse'>");
    errorCount = showMappings(out, sourceSet, null, nfd, fromLatin, toLatin);
    out.println("</table><p>Reversible failures:\t" + errorCount + "</p>");
    if (errorCount != 0) {
      errln("Reversible failures:\t" + errorCount);
      errorCount = 0;
    }

    out.println(
        "<h1>Has Unneeded Separator</h1><table border='1' cellpadding='2' cellspacing='0' style='border-collapse: collapse'>");
    errorCount = showMappings(out, sourceSet, "-", nfd, fromLatin, toLatin);
    out.println("</table><p>Separator failures:\t" + errorCount + "</p>");
    if (errorCount != 0) {
      logln("Unneeded Separators:\t" + errorCount);
      errorCount = 0;
    }

    out.print("</body></html>");
    out.close();
    return errorCount;
  }