From 69112d2b71a47a81cf19bd9fd788caaa6e42f2b1 Mon Sep 17 00:00:00 2001 From: macchiati Date: Wed, 12 Jun 2024 11:42:18 -0700 Subject: [PATCH] CLDR-17719 Add reformatted TSV for coverage goals --- .../org/unicode/cldr/tool/ShowLanguages.java | 281 ++++++++++-------- 1 file changed, 159 insertions(+), 122 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java index 8febcaef8cd..3f0a3068dd3 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java @@ -1378,144 +1378,181 @@ private String getLanguageName(String languageCode) { Set.of(Organization.cldr)); private void showCoverageGoals(PrintWriter pw) throws IOException { - PrintWriter pw2 = - new PrintWriter( - new FormattedFileWriter( - null, "Coverage Goals", null, SUPPLEMENTAL_INDEX_ANCHORS)); - - TablePrinter tablePrinter = - new TablePrinter() - // tablePrinter.setSortPriorities(0,4) - .addColumn("Language", "class='source'", null, "class='source'", false) - .setSortPriority(0) - .setBreakSpans(false) + try (PrintWriter pw2 = + new PrintWriter( + new FormattedFileWriter( + null, + "Coverage Goals", + null, + SUPPLEMENTAL_INDEX_ANCHORS)); + PrintWriter coverageGoalsTsv = + FileUtilities.openUTF8Writer( + CLDRPaths.CHART_DIRECTORY + "tsv/", "coverage_goals.tsv"); ) { + + TablePrinter tablePrinter = + new TablePrinter() + // tablePrinter.setSortPriorities(0,4) + .addColumn( + "Language", "class='source'", null, "class='source'", false) + .setSortPriority(0) + .setBreakSpans(false) + .addColumn( + "Code", + "class='source'", + "{0}", + "class='source'", + false) + .addColumn( + "D. Votes", + "class='target'", + null, + "class='target'", + false); + + Map> vendordata = sc.getLocaleTypes(); + Set locales = new TreeSet<>(); + Set vendors = new LinkedHashSet<>(); + Set smallVendors = new LinkedHashSet<>(); + + for (Organization organization : TC_Vendors) { + // if (vendor.equals(Organization.java)) continue; + Map data = vendordata.get(organization); + vendors.add(organization); + tablePrinter .addColumn( - "Code", - "class='source'", - "{0}", - "class='source'", + organization.getDisplayName(), + "class='target'", + null, + "class='target'", false) - .addColumn("D. Votes", "class='target'", null, "class='target'", false); + .setSpanRows(false); + locales.addAll(data.keySet()); + showTabbedOrgLevels(coverageGoalsTsv, organization, data); + } - Map> vendordata = sc.getLocaleTypes(); - Set locales = new TreeSet<>(); - Set vendors = new LinkedHashSet<>(); - Set smallVendors = new LinkedHashSet<>(); + for (Entry> vendorData : vendordata.entrySet()) { + Organization organization = vendorData.getKey(); + if (!TC_Vendors.contains(organization)) { + smallVendors.add(organization); + Map data = vendordata.get(organization); + showTabbedOrgLevels(coverageGoalsTsv, organization, data); + continue; + } + } - for (Organization organization : TC_Vendors) { - // if (vendor.equals(Organization.java)) continue; - Map data = vendordata.get(organization); - vendors.add(organization); - tablePrinter - .addColumn( - organization.getDisplayName(), - "class='target'", - null, - "class='target'", - false) - .setSpanRows(false); - locales.addAll(data.keySet()); - } + Collection data = new ArrayList<>(); + List list = new ArrayList<>(); + LanguageTagParser ltp = new LanguageTagParser(); + // String alias2 = getAlias("sh_YU"); - for (Entry> vendorData : vendordata.entrySet()) { - Organization vendor = vendorData.getKey(); - if (!TC_Vendors.contains(vendor)) { - smallVendors.add(vendor); - continue; - } - } + pw2.append("

TC Orgs

"); - Collection data = new ArrayList<>(); - List list = new ArrayList<>(); - LanguageTagParser ltp = new LanguageTagParser(); - // String alias2 = getAlias("sh_YU"); - - pw2.append("

TC Orgs

"); - - for (String locale : locales) { - list.clear(); - String localeCode = locale.equals("*") ? "und" : locale; - String alias = getAlias(localeCode); - if (!alias.equals(localeCode)) { - throw new IllegalArgumentException( - "Should use canonical form: " + locale + " => " + alias); - } - // String baseLang = ltp.set(localeCode).getLanguage(); - String baseLangName = getLanguageName(localeCode); - list.add("und".equals(localeCode) ? "other" : baseLangName); - list.add(locale); - int defaultVotes = - supplementalDataInfo.getRequiredVotes(CLDRLocale.getInstance(locale), null); - list.add(String.valueOf(defaultVotes)); - for (Organization vendor : vendors) { - String status = getVendorStatus(locale, vendor, vendordata); - // if (!baseLang.equals(locale) && !status.startsWith("<")) { - // String langStatus = getVendorStatus(baseLang, vendor, - // vendordata); - // if (!langStatus.equals(status)) { - // status += "*"; - // } - // } - list.add(status); + for (String locale : locales) { + list.clear(); + String localeCode = locale.equals("*") ? "und" : locale; + String alias = getAlias(localeCode); + if (!alias.equals(localeCode)) { + throw new IllegalArgumentException( + "Should use canonical form: " + locale + " => " + alias); + } + // String baseLang = ltp.set(localeCode).getLanguage(); + String baseLangName = getLanguageName(localeCode); + list.add("und".equals(localeCode) ? "other" : baseLangName); + list.add(locale); + int defaultVotes = + supplementalDataInfo.getRequiredVotes( + CLDRLocale.getInstance(locale), null); + list.add(String.valueOf(defaultVotes)); + for (Organization vendor : vendors) { + String status = getVendorStatus(locale, vendor, vendordata); + // if (!baseLang.equals(locale) && + // !status.startsWith("<")) { + // String langStatus = getVendorStatus(baseLang, + // vendor, + // vendordata); + // if (!langStatus.equals(status)) { + // status += "*"; + // } + // } + list.add(status); + } + data.add(list.toArray(new String[list.size()])); } - data.add(list.toArray(new String[list.size()])); - } - Comparable[][] flattened = data.toArray(new Comparable[data.size()][]); - String value = tablePrinter.addRows(flattened).toTable(); - pw2.println(value); - - pw2.append("

Others

    "); - - for (Organization vendor2 : smallVendors) { - pw2.append("
  • "); - pw2.append(TransliteratorUtilities.toHTML.transform(vendor2.getDisplayName())) - .append(": "); - boolean first1 = true; - for (Level level : Level.values()) { - boolean first2 = true; - Level other = null; - for (Entry data2 : vendordata.get(vendor2).entrySet()) { - String key = data2.getKey(); - Level level2 = data2.getValue(); - if (level != level2) { - continue; - } - if (key.equals("*")) { - other = level2; - continue; - } - if (first2) { - if (first1) { - first1 = false; + Comparable[][] flattened = data.toArray(new Comparable[data.size()][]); + String value = tablePrinter.addRows(flattened).toTable(); + pw2.println(value); + + pw2.append("

    Others

      "); + + for (Organization vendor2 : smallVendors) { + pw2.append("
    • "); + pw2.append(TransliteratorUtilities.toHTML.transform(vendor2.getDisplayName())) + .append(": "); + boolean first1 = true; + for (Level level : Level.values()) { + boolean first2 = true; + Level other = null; + for (Entry data2 : vendordata.get(vendor2).entrySet()) { + String key = data2.getKey(); + Level level2 = data2.getValue(); + if (level != level2) { + continue; + } + if (key.equals("*")) { + other = level2; + continue; + } + if (first2) { + if (first1) { + first1 = false; + } else { + pw2.append("; "); + } + pw2.append(level2.toString()).append(": "); + first2 = false; } else { - pw2.append("; "); + pw2.append(", "); } - pw2.append(level2.toString()).append(": "); - first2 = false; - } else { - pw2.append(", "); + pw2.append(TransliteratorUtilities.toHTML.transform(key)); } - pw2.append(TransliteratorUtilities.toHTML.transform(key)); - } - if (other != null) { - if (first2) { - if (first1) { - first1 = false; + if (other != null) { + if (first2) { + if (first1) { + first1 = false; + } else { + pw2.append("; "); + } + pw2.append(level.toString()).append(": "); + first2 = false; } else { - pw2.append("; "); + pw2.append(", "); } - pw2.append(level.toString()).append(": "); - first2 = false; - } else { - pw2.append(", "); + pw2.append("other"); } - pw2.append("other"); } + pw2.append("
    • "); } - pw2.append(""); + pw2.append("
    "); + } + } + + public void showTabbedOrgLevels( + PrintWriter coverageGoalsTsv, Organization organization, Map data) { + coverageGoalsTsv.println( + String.format( + "\n#%s\t;\t%s\t;\t%s\t;\t%s\n", + "Org", "Locale", "Level", "Locale Name")); + for (Entry entry : data.entrySet()) { + String locale = entry.getKey(); + Level level = entry.getValue(); + final String name = + locale.equals("*") + ? "ALL" + : english.getName(locale, true, CLDRFile.SHORT_ALTS); + coverageGoalsTsv.println( + String.format( + "%s\t;\t%s\t;\t%s\t;\t%s", organization, locale, level, name)); } - pw2.append("
"); - pw2.close(); } LanguageTagParser lpt2 = new LanguageTagParser();