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
 InputFile load(String localeId) {
   return new InputFile(delegate.make(localeId, true));
 }
Example #4
0
 InputFactory(String sourceDir) {
   delegate = Factory.make(sourceDir, ".*");
 }