Exemple #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();
 }
Exemple #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();
   }
 }
Exemple #3
0
  /**
   * Returns the list of locales to generate.
   *
   * @param restrictLocales a comma-separated list of locales to include, or null for all locales.
   */
  List<String> chooseLocales(String restrictLocales) {
    Set<String> locales = delegate.getAvailable();
    if (restrictLocales != null) {
      Set<String> newLocales = new HashSet<String>();
      newLocales.add("root"); // always include root or things break
      for (String locale : restrictLocales.split(",")) {
        if (!locales.contains(locale)) {
          System.err.println("Ignoring non-existent locale " + locale);
          continue;
        }
        newLocales.add(locale);
      }
      locales = newLocales;
    }

    List<String> out = new ArrayList<String>(locales);
    Collections.sort(out);
    return out;
  }
Exemple #4
0
 List<String> getAvailableLanguages() {
   List<String> out = new ArrayList<String>(delegate.getAvailableLanguages());
   Collections.sort(out);
   return out;
 }
Exemple #5
0
 InputFile getSupplementalData() {
   return new InputFile(delegate.getSupplementalData());
 }
Exemple #6
0
 InputFile load(String localeId) {
   return new InputFile(delegate.make(localeId, true));
 }
Exemple #7
0
 InputFactory(String sourceDir) {
   delegate = Factory.make(sourceDir, ".*");
 }