@@ -69,6 +69,7 @@ public class CLDRConverter {
6969 private static String WINZONES_SOURCE_FILE ;
7070 private static String PLURALS_SOURCE_FILE ;
7171 private static String DAYPERIODRULE_SOURCE_FILE ;
72+ private static String COVERAGELEVELS_FILE ;
7273 static String DESTINATION_DIR = "build/gensrc" ;
7374
7475 static final String LOCALE_NAME_PREFIX = "locale.displayname." ;
@@ -258,6 +259,7 @@ public static void main(String[] args) throws Exception {
258259 WINZONES_SOURCE_FILE = CLDR_BASE + "/supplemental/windowsZones.xml" ;
259260 PLURALS_SOURCE_FILE = CLDR_BASE + "/supplemental/plurals.xml" ;
260261 DAYPERIODRULE_SOURCE_FILE = CLDR_BASE + "/supplemental/dayPeriods.xml" ;
262+ COVERAGELEVELS_FILE = CLDR_BASE + "/properties/coverageLevels.txt" ;
261263
262264 if (BASE_LOCALES .isEmpty ()) {
263265 setupBaseLocales ("en-US" );
@@ -359,13 +361,18 @@ private static void enableFileAccess(SAXParser parser) throws SAXNotSupportedExc
359361 private static List <Bundle > readBundleList () throws Exception {
360362 List <Bundle > retList = new ArrayList <>();
361363 Path path = FileSystems .getDefault ().getPath (SOURCE_FILE_DIR );
364+ var coverageMap = coverageLevelsMap ();
362365 try (DirectoryStream <Path > dirStr = Files .newDirectoryStream (path )) {
363366 for (Path entry : dirStr ) {
364367 String fileName = entry .getFileName ().toString ();
365368 if (fileName .endsWith (".xml" )) {
366369 String id = fileName .substring (0 , fileName .indexOf ('.' ));
367370 Locale cldrLoc = Locale .forLanguageTag (toLanguageTag (id ));
368- StringBuilder sb = getCandLocales (cldrLoc );
371+ List <Locale > candList = getCandidateLocales (cldrLoc );
372+ if (!"root" .equals (id ) && candList .stream ().noneMatch (coverageMap ::containsKey )) {
373+ continue ;
374+ }
375+ StringBuilder sb = getCandLocales (candList );
369376 if (sb .indexOf ("root" ) == -1 ) {
370377 sb .append ("root" );
371378 }
@@ -510,8 +517,7 @@ private static void parseLDMLFile(File srcfile, AbstractLDMLHandler<?> handler)
510517 parser .parse (srcfile , handler );
511518 }
512519
513- private static StringBuilder getCandLocales (Locale cldrLoc ) {
514- List <Locale > candList = getCandidateLocales (cldrLoc );
520+ private static StringBuilder getCandLocales (List <Locale > candList ) {
515521 StringBuilder sb = new StringBuilder ();
516522 for (Locale loc : candList ) {
517523 if (!loc .equals (Locale .ROOT )) {
@@ -1195,6 +1201,26 @@ private static Map<String, String> generateRules(AbstractLDMLHandler<Map<String,
11951201 }));
11961202 }
11971203
1204+ private static Map <Locale , String > coverageLevelsMap () throws Exception {
1205+ // First, parse `coverageLevels.txt` file
1206+ var covMap = Files .readAllLines (Path .of (COVERAGELEVELS_FILE )).stream ()
1207+ .filter (line -> !line .isBlank () && !line .startsWith ("#" ))
1208+ .map (line -> line .split ("[\s \t ]*;[\s \t ]*" , 3 ))
1209+ .filter (a -> a [1 ].matches ("basic|moderate|modern|comprehensive" ))
1210+ .collect (Collectors .toMap (
1211+ a -> Locale .forLanguageTag (a [0 ].replaceAll ("_" , "-" )),
1212+ a -> a [1 ],
1213+ (v1 , v2 ) -> v2 , // should never happen
1214+ HashMap ::new ));
1215+
1216+ // Add other common (non-seed) locales (below `basic` coverage level) as of v42
1217+ ResourceBundle .getBundle (CLDRConverter .class .getPackageName () + ".OtherCommonLocales" )
1218+ .keySet ()
1219+ .forEach (k -> covMap .put (Locale .forLanguageTag (k ), "" ));
1220+
1221+ return covMap ;
1222+ }
1223+
11981224 // for debug
11991225 static void dumpMap (Map <String , Object > map ) {
12001226 map .entrySet ().stream ()
0 commit comments