Skip to content

Commit e301a34

Browse files
srl295pedberg-icu
authored andcommitted
CLDR-18406 v47 Chart Improvements (#4487)
(cherry picked from commit 2ef784e)
1 parent 2f2c425 commit e301a34

File tree

8 files changed

+100
-40
lines changed

8 files changed

+100
-40
lines changed

tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartUnitConversions.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.unicode.cldr.util.UnitConverter.UnitSystem;
1919

2020
public class ChartUnitConversions extends Chart {
21+
private static final boolean DUMP_UNIT_TABLE_TO_STDOUT = false;
2122

2223
public static final String QUANTITY_MSG =
2324
"The units are grouped and ordered by Quantity (which are based on the NIST quantities, see "
@@ -170,10 +171,12 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
170171
.finishRow();
171172
}
172173
pw.write(tablePrinter.toTable());
173-
PrintWriter pw2 = new PrintWriter(System.out);
174-
tablePrinter.toTsv(pw2);
175-
pw2.flush();
176-
pw2.close();
174+
if (DUMP_UNIT_TABLE_TO_STDOUT) {
175+
PrintWriter pw2 = new PrintWriter(System.out);
176+
tablePrinter.toTsv(pw2);
177+
pw2.flush();
178+
pw2.close();
179+
}
177180
// for (R4<UnitId, UnitSystem, Rational, String> sk : all) {
178181
// System.out.println(String.format("%s\t%s\t%s\t%s", sk.get0(), sk.get1(),
179182
// sk.get2(), sk.get3()));

tools/cldr-code/src/main/java/org/unicode/cldr/tool/FormattedFileWriter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import com.ibm.icu.text.Collator;
44
import com.ibm.icu.util.ICUUncheckedIOException;
55
import java.io.IOException;
6-
import java.io.PrintWriter;
76
import java.io.StringWriter;
8-
import java.nio.file.Paths;
97
import java.util.ArrayList;
108
import java.util.Date;
119
import java.util.Set;
@@ -16,6 +14,7 @@
1614
import org.unicode.cldr.util.CLDRPaths;
1715
import org.unicode.cldr.util.CldrUtility;
1816
import org.unicode.cldr.util.CollatorHelper;
17+
import org.unicode.cldr.util.TempPrintWriter;
1918

2019
public class FormattedFileWriter extends java.io.Writer {
2120
public static final String CHART_TARGET_DIR = CLDRPaths.CHART_DIRECTORY + "/supplemental/";
@@ -188,13 +187,10 @@ public static void writeTargetWithReplacements(
188187
String targetFileName,
189188
final String templateFileName,
190189
String[] replacements) {
191-
try {
192-
PrintWriter pw2 =
193-
org.unicode.cldr.draft.FileUtilities.openUTF8Writer(targetdir, targetFileName);
194-
System.err.println("Writing: " + Paths.get(targetdir, targetFileName));
190+
try (final TempPrintWriter pw2 = new TempPrintWriter(targetdir, targetFileName)) {
191+
pw2.noDiff();
195192
FileUtilities.appendBufferedReader(
196-
ToolUtilities.getUTF8Data(templateFileName), pw2, replacements);
197-
pw2.close();
193+
ToolUtilities.getUTF8Data(templateFileName), pw2.asPrintWriter(), replacements);
198194
} catch (IOException e) {
199195
throw new ICUUncheckedIOException(e);
200196
}

tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateAllCharts.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.unicode.cldr.util.CldrUtility;
77
import org.unicode.cldr.util.DateTimeFormats;
88
import org.unicode.cldr.util.FileCopier;
9+
import org.unicode.cldr.util.StackTracker;
910
import org.unicode.cldr.util.VerifyCompactNumbers;
1011
import org.unicode.cldr.util.VerifyZones;
1112

@@ -18,14 +19,26 @@
1819
* @author markdavis
1920
*/
2021
public class GenerateAllCharts {
22+
/** print an eyecatcher with the line number of this stage of GenerateAllCharts */
23+
private static void headline(String str) {
24+
StackTraceElement caller = StackTracker.currentElement(0);
25+
System.out.println();
26+
System.out.println("---------------------------");
27+
System.out.println(caller.getFileName() + ":" + caller.getLineNumber() + " " + str);
28+
}
29+
2130
public static void main(String[] args) throws Exception {
31+
headline("Setting Up");
2232
final File mainDir = new File(CLDRPaths.CHART_DIRECTORY);
33+
System.out.println("Writing to " + mainDir.getAbsolutePath());
2334
if (mainDir.mkdirs()) {
2435
System.err.println("Created: " + mainDir);
2536
}
2637
if (!mainDir.isDirectory()) {
2738
throw new IOException("Main dir doesn't exist: " + mainDir);
2839
}
40+
41+
headline("Copying LICENSE, README.md, css, etc.");
2942
FileCopier.copy(CldrUtility.class, "data/LICENSE", CLDRPaths.CHART_DIRECTORY, "LICENSE");
3043
FileCopier.copy(
3144
GenerateAllCharts.class,
@@ -39,30 +52,49 @@ public static void main(String[] args) throws Exception {
3952
"main-index.html",
4053
CLDRPaths.CHART_DIRECTORY,
4154
"index.html");
55+
56+
headline("Setting Up include htmls");
4257
FormattedFileWriter.copyIncludeHtmls(CLDRPaths.CHART_DIRECTORY);
4358

4459
if (ToolConstants.CHART_VERSION.compareTo("37") >= 0) {
60+
headline("ChartGrammaticalForms");
4561
new ChartGrammaticalForms().writeChart(null);
4662
}
4763

64+
headline("ShowLanguages");
4865
ShowLanguages.main(args);
4966

67+
headline("ChartAnnotations");
5068
new ChartAnnotations().writeChart(null);
69+
headline("ChartSubdivisionNames");
5170
new ChartSubdivisionNames().writeChart(null);
71+
headline("GenerateBcp47Text");
5272
GenerateBcp47Text.main(args);
73+
headline("GenerateSidewaysView");
5374
GenerateSidewaysView.main(args);
75+
headline("ShowData");
5476
ShowData.main(args);
5577

78+
// headline("GenerateTransformCharts");
5679
// GenerateTransformCharts.main(args);
80+
headline("ChartDelta");
5781
ChartDelta.main(args);
82+
headline("ChartDelta - high level");
5883
ChartDelta.main(args, true); // churn
84+
headline("ChartCollation");
5985
ChartCollation.main(args);
6086

87+
headline("VerifyCompactNumbers");
6188
VerifyCompactNumbers.main(args);
89+
headline("VerifyZones");
6290
VerifyZones.main(args);
91+
headline("DateTimeFormats");
6392
DateTimeFormats.main(args);
93+
headline("ChartPersonNames");
6494
new ChartPersonNames().writeChart(null);
6595

96+
headline("GenerateKeyboardCharts");
6697
GenerateKeyboardCharts.main(args);
98+
headline("DONE");
6799
}
68100
}

tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateKeyboardCharts.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class GenerateKeyboardCharts {
1111

1212
static final String SUBDIR = "keyboards";
13+
static IOException copyErr = null;
1314

1415
public static void main(String args[]) throws IOException {
1516
final File mainDir = new File(CLDRPaths.CHART_DIRECTORY);
@@ -62,8 +63,12 @@ public static void main(String args[]) throws IOException {
6263
} catch (IOException e) {
6364
e.printStackTrace();
6465
System.err.println("Error copying " + path);
65-
System.exit(1);
66+
// will overwrite if more than one- but at least one will be
67+
// thrown.
68+
copyErr = new IOException("Error copying " + path, e);
6669
}
6770
});
71+
// rethrow any error
72+
if (copyErr != null) throw copyErr;
6873
}
6974
}

tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
@CLDRTool(alias = "showlanguages", description = "Generate Language info charts")
8686
public class ShowLanguages {
8787
private static final boolean SHOW_NATIVE = true;
88+
private static final boolean SHOW_SKIPPED = false;
89+
private static int skipped = 0;
8890

8991
static Comparator col =
9092
new org.unicode.cldr.util.MultiComparator(
@@ -110,6 +112,12 @@ public static void main(String[] args) throws IOException {
110112
// cldrFactory = Factory.make(Utility.COMMON_DIRECTORY + "../dropbox/extra2/", ".*");
111113
// printLanguageData(cldrFactory, "language_info2.txt");
112114
System.out.println("Done - wrote into " + FormattedFileWriter.CHART_TARGET_DIR);
115+
if (skipped > 0) {
116+
System.err.println(
117+
"*** WARNING ***\nTODO CLDR-1129: "
118+
+ skipped
119+
+ " skipped xpath(s) - set SHOW_SKIPPED=true to debug.");
120+
}
113121
}
114122

115123
/** */
@@ -920,28 +928,28 @@ public LanguageInfo(Factory cldrFactory) throws IOException {
920928
deprecatedItems.add(parts.findAttributes("deprecatedItems"));
921929
continue;
922930
}
923-
if (path.indexOf("/calendarData") >= 0) {
924-
Map<String, String> attributes = parts.findAttributes("calendar");
931+
if (path.indexOf("/calendarPreferenceData/calendarPreference") >= 0) {
932+
Map<String, String> attributes = parts.findAttributes("calendarPreference");
925933
if (attributes == null) {
926934
System.err.println(
927935
"Err: on path "
928936
+ fullPath
929-
+ " , no attributes on 'calendar'. Probably, this tool is out of date.");
937+
+ " , no attributes on 'calendarPreference'. Probably, this tool is out of date.");
930938
} else {
931-
String type = attributes.get("type");
939+
String ordering = attributes.get("ordering");
932940
String territories = attributes.get("territories");
933941
if (territories == null) {
934942
System.err.println(
935943
"Err: on path "
936944
+ fullPath
937945
+ ", missing territories. Probably, this tool is out of date.");
938-
} else if (type == null) {
946+
} else if (ordering == null) {
939947
System.err.println(
940948
"Err: on path "
941949
+ fullPath
942-
+ ", missing type. Probably, this tool is out of date.");
950+
+ ", missing ordering. Probably, this tool is out of date.");
943951
} else {
944-
addTerritoryInfo(territories, "calendar", type);
952+
addTerritoryInfo(territories, "Preferred Calendar", ordering);
945953
}
946954
}
947955
}
@@ -985,7 +993,10 @@ public LanguageInfo(Factory cldrFactory) throws IOException {
985993
}
986994
}
987995
if (path.indexOf("/generation") >= 0 || path.indexOf("/version") >= 0) continue;
988-
System.out.println("Skipped Element: " + path);
996+
skipped++;
997+
if (SHOW_SKIPPED) {
998+
System.out.println("Skipped Element: " + path);
999+
}
9891000
}
9901001

9911002
for (String territory : supplementalDataInfo.getTerritoriesWithPopulationData()) {

tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLocaleCoverage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private static void showCoverage(
374374

375375
System.out.println(Joiner.on("\n").join(languageToRegion.asMap().entrySet()));
376376

377-
System.out.println("# Checking: " + availableLanguages);
377+
System.out.println("# Writing coverage: " + availableLanguages);
378378

379379
NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH);
380380
percentFormat.setMaximumFractionDigits(1);

tools/cldr-code/src/main/java/org/unicode/cldr/util/CalculateLocaleCoverage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private void calculateCoverage(final String only) {
166166

167167
logger.info(Joiner.on("\n").join(languageToRegion.asMap().entrySet()));
168168

169-
logger.info("# Checking: " + availableLanguages);
169+
logger.info("# Calculating locale coverage: " + availableLanguages);
170170

171171
NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH);
172172
percentFormat.setMaximumFractionDigits(1);

tools/cldr-code/src/main/java/org/unicode/cldr/util/TempPrintWriter.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class TempPrintWriter extends Writer {
2727
final String filename;
2828
boolean noReplace = false;
2929
boolean skipCopyright = false;
30+
boolean noDiff = false;
3031

3132
public TempPrintWriter skipCopyright(boolean newSkipCopyright) {
3233
skipCopyright = newSkipCopyright;
@@ -37,6 +38,15 @@ public PrintWriter asPrintWriter() {
3738
return tempPrintWriter;
3839
}
3940

41+
/**
42+
* turn off the file difference print. Good if you expect a lot of changes, such as with a
43+
* chart.
44+
*/
45+
public TempPrintWriter noDiff() {
46+
noDiff = true;
47+
return this;
48+
}
49+
4050
public static TempPrintWriter openUTF8Writer(String filename) {
4151
return new TempPrintWriter(new File(filename));
4252
}
@@ -77,7 +87,7 @@ public void close() {
7787
if (noReplace) {
7888
new File(tempName).delete();
7989
} else {
80-
replaceDifferentOrDelete(filename, tempName, skipCopyright);
90+
replaceDifferentOrDelete(filename, tempName);
8191
}
8292
} catch (IOException e) {
8393
throw new ICUUncheckedIOException(e);
@@ -129,8 +139,7 @@ public void printlnWithTabs(int desiredCount, String textToPrint) {
129139
* If contents(newFile) ≠ contents(oldFile), rename newFile to old. Otherwise delete newfile.
130140
* Return true if replaced. *
131141
*/
132-
private static boolean replaceDifferentOrDelete(
133-
String oldFile, String newFile, boolean skipCopyright) throws IOException {
142+
private boolean replaceDifferentOrDelete(String oldFile, String newFile) throws IOException {
134143
final File oldFile2 = new File(oldFile);
135144
if (oldFile2.exists()) {
136145
final String lines[] = new String[2];
@@ -139,20 +148,24 @@ private static boolean replaceDifferentOrDelete(
139148
new File(newFile).delete();
140149
return false;
141150
}
142-
System.out.println("Found difference in : " + oldFile + ", " + newFile);
143-
final int diff = compare(lines[0], lines[1]);
144-
System.out.println(
145-
" File1: '"
146-
+ lines[0].substring(0, diff)
147-
+ "', '"
148-
+ lines[0].substring(diff)
149-
+ "'");
150-
System.out.println(
151-
" File2: '"
152-
+ lines[1].substring(0, diff)
153-
+ "', '"
154-
+ lines[1].substring(diff)
155-
+ "'");
151+
if (noDiff) {
152+
System.out.println("Writing: " + oldFile);
153+
} else {
154+
System.out.println("Found difference in : " + oldFile + ", " + newFile);
155+
final int diff = compare(lines[0], lines[1]);
156+
System.out.println(
157+
" File1: '"
158+
+ lines[0].substring(0, diff)
159+
+ "', '"
160+
+ lines[0].substring(diff)
161+
+ "'");
162+
System.out.println(
163+
" File2: '"
164+
+ lines[1].substring(0, diff)
165+
+ "', '"
166+
+ lines[1].substring(diff)
167+
+ "'");
168+
}
156169
}
157170
Files.move(Path.of(newFile), oldFile2.toPath(), StandardCopyOption.REPLACE_EXISTING);
158171
return true;

0 commit comments

Comments
 (0)