@@ -70,6 +70,7 @@ public class CLDRConverter {
70
70
private static String TIMEZONE_SOURCE_FILE ;
71
71
private static String WINZONES_SOURCE_FILE ;
72
72
private static String PLURALS_SOURCE_FILE ;
73
+ private static String DAYPERIODRULE_SOURCE_FILE ;
73
74
static String DESTINATION_DIR = "build/gensrc" ;
74
75
75
76
static final String LOCALE_NAME_PREFIX = "locale.displayname." ;
@@ -100,6 +101,7 @@ public class CLDRConverter {
100
101
static NumberingSystemsParseHandler handlerNumbering ;
101
102
static MetaZonesParseHandler handlerMetaZones ;
102
103
static TimeZoneParseHandler handlerTimeZone ;
104
+ static DayPeriodRuleParseHandler handlerDayPeriodRule ;
103
105
private static BundleGenerator bundleGenerator ;
104
106
105
107
// java.base module related
@@ -116,6 +118,10 @@ public class CLDRConverter {
116
118
private static String tzDataDir ;
117
119
private static final Map <String , String > canonicalTZMap = new HashMap <>();
118
120
121
+ // rules maps
122
+ static Map <String , String > pluralRules ;
123
+ static Map <String , String > dayPeriodRules ;
124
+
119
125
static enum DraftType {
120
126
UNCONFIRMED ,
121
127
PROVISIONAL ,
@@ -248,6 +254,7 @@ public static void main(String[] args) throws Exception {
248
254
SPPL_META_SOURCE_FILE = CLDR_BASE + "/supplemental/supplementalMetadata.xml" ;
249
255
WINZONES_SOURCE_FILE = CLDR_BASE + "/supplemental/windowsZones.xml" ;
250
256
PLURALS_SOURCE_FILE = CLDR_BASE + "/supplemental/plurals.xml" ;
257
+ DAYPERIODRULE_SOURCE_FILE = CLDR_BASE + "/supplemental/dayPeriods.xml" ;
251
258
252
259
if (BASE_LOCALES .isEmpty ()) {
253
260
setupBaseLocales ("en-US" );
@@ -259,6 +266,10 @@ public static void main(String[] args) throws Exception {
259
266
parseSupplemental ();
260
267
parseBCP47 ();
261
268
269
+ // rules maps
270
+ pluralRules = generateRules (handlerPlurals );
271
+ dayPeriodRules = generateRules (handlerDayPeriodRule );
272
+
262
273
List <Bundle > bundles = readBundleList ();
263
274
convertBundles (bundles );
264
275
@@ -268,9 +279,6 @@ public static void main(String[] args) throws Exception {
268
279
269
280
// Generate Windows tzmappings
270
281
generateWindowsTZMappings ();
271
-
272
- // Generate Plural rules
273
- generatePluralRules ();
274
282
}
275
283
}
276
284
@@ -462,6 +470,10 @@ private static void parseSupplemental() throws Exception {
462
470
// Parse plurals
463
471
handlerPlurals = new PluralsParseHandler ();
464
472
parseLDMLFile (new File (PLURALS_SOURCE_FILE ), handlerPlurals );
473
+
474
+ // Parse day period rules
475
+ handlerDayPeriodRule = new DayPeriodRuleParseHandler ();
476
+ parseLDMLFile (new File (DAYPERIODRULE_SOURCE_FILE ), handlerDayPeriodRule );
465
477
}
466
478
467
479
// Parsers for data in "bcp47" directory
@@ -809,7 +821,9 @@ private static Map<String, Object> extractCalendarData(Map<String, Object> map,
809
821
"TimePatterns" ,
810
822
"DatePatterns" ,
811
823
"DateTimePatterns" ,
812
- "DateTimePatternChars"
824
+ "DateTimePatternChars" ,
825
+ "PluralRules" ,
826
+ "DayPeriodRules" ,
813
827
};
814
828
815
829
private static Map <String , Object > extractFormatData (Map <String , Object > map , String id ) {
@@ -1125,49 +1139,21 @@ public int compare(String t1, String t2) {
1125
1139
}
1126
1140
1127
1141
/**
1128
- * Generate ResourceBundle source file for plural rules. The generated
1129
- * class is {@code sun.text.resources.PluralRules} which has one public
1130
- * two dimensional array {@code rulesArray}. Each array element consists
1131
- * of two elements that designate the locale and the locale's plural rules
1132
- * string. The latter has the syntax from Unicode Consortium's
1133
- * <a href="http://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax">
1134
- * Plural rules syntax</a>. {@code samples} and {@code "other"} are being ommited.
1135
- *
1136
- * @throws Exception
1142
+ * Generates rules map for Plural rules and DayPeriod rules. The key is the locale id,
1143
+ * and the value is rules, defined by the LDML spec. Each rule consists of {@code type:rule}
1144
+ * notation, concatenated with a ";" as a delimiter.
1145
+ * @param handler handler containing rules
1146
+ * @return the map
1137
1147
*/
1138
- private static void generatePluralRules () throws Exception {
1139
- Files .createDirectories (Paths .get (DESTINATION_DIR , "sun" , "text" , "resources" ));
1140
- Files .write (Paths .get (DESTINATION_DIR , "sun" , "text" , "resources" , "PluralRules.java" ),
1141
- Stream .concat (
1142
- Stream .concat (
1143
- Stream .of (
1144
- "package sun.text.resources;" ,
1145
- "public final class PluralRules {" ,
1146
- " public static final String[][] rulesArray = {"
1147
- ),
1148
- pluralRulesStream ().sorted ()
1149
- ),
1150
- Stream .of (
1151
- " };" ,
1152
- "}"
1153
- )
1154
- )
1155
- .collect (Collectors .toList ()),
1156
- StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
1157
- }
1158
-
1159
- private static Stream <String > pluralRulesStream () {
1160
- return handlerPlurals .getData ().entrySet ().stream ()
1161
- .filter (e -> !(e .getValue ()).isEmpty ())
1162
- .map (e -> {
1163
- String loc = e .getKey ();
1148
+ private static Map <String , String > generateRules (AbstractLDMLHandler <Map <String , String >> handler ) {
1149
+ return handler .getData ().entrySet ().stream ()
1150
+ .collect (Collectors .toMap (Map .Entry ::getKey , e -> {
1164
1151
Map <String , String > rules = e .getValue ();
1165
- return " {\" " + loc + "\" , \" " +
1166
- rules .entrySet ().stream ()
1167
- .map (rule -> rule .getKey () + ":" + rule .getValue ().replaceFirst ("@.*" , "" ))
1168
- .map (String ::trim )
1169
- .collect (Collectors .joining (";" )) + "\" }," ;
1170
- });
1152
+ return rules .entrySet ().stream ()
1153
+ .map (rule -> rule .getKey () + ":" + rule .getValue ().replaceFirst ("@.*" , "" ))
1154
+ .map (String ::trim )
1155
+ .collect (Collectors .joining (";" ));
1156
+ }));
1171
1157
}
1172
1158
1173
1159
// for debug
@@ -1188,4 +1174,3 @@ static void dumpMap(Map<String, Object> map) {
1188
1174
.forEach (System .out ::println );
1189
1175
}
1190
1176
}
1191
-
0 commit comments