1 package org.unicode.cldr.test; 2 3 import java.util.Set; 4 import java.util.regex.Matcher; 5 import java.util.regex.Pattern; 6 7 import org.unicode.cldr.util.Organization; 8 import org.unicode.cldr.util.RegexUtilities; 9 import org.unicode.cldr.util.StandardCodes; 10 11 import com.google.common.collect.ImmutableSet; 12 13 public final class SubmissionLocales { 14 public static Set<String> NEW_CLDR_LOCALES = ImmutableSet.of( 15 "ceb", // Cebuano (not new in release, but needs major changes) 16 "mai", // Maithili 17 "mni", // Manipuri (Bengali script)-Apple as well 18 "sat", // Santali -(Apple use Olck script) 19 "kok", // Konkani -(Note: this is already covered by a MS vetter at Modern level) 20 "sd_Deva", // Sindhi (Devanagari) 21 "su", // Sundanese (script TBD) 22 "pcm" // Nigerian Pidgin 23 // "cad", // Caddo 24 // "gn" // Guarani 25 ); 26 27 public static Set<String> HIGH_LEVEL_LOCALES = ImmutableSet.of( 28 "chr", // Cherokee 29 "gd", // Scottish Gaelic, Gaelic 30 "fo" // Faroese 31 ); 32 33 // have to have a lazy eval because otherwise CLDRConfig is called too early in the boot process 34 public static Set<String> CLDR_LOCALES = ImmutableSet.<String>builder() 35 .addAll(HIGH_LEVEL_LOCALES) 36 .addAll(NEW_CLDR_LOCALES) 37 .addAll(StandardCodes.make().getLocaleToLevel(Organization.cldr).keySet()).build(); 38 39 // synchronized (SUBMISSION) { 40 // if (CLDR_LOCALES == null) { 41 // CLDR_LOCALES = ImmutableSet.<String>builder() 42 // .addAll(HIGH_LEVEL_LOCALES) 43 // .addAll(StandardCodes.make().getLocaleToLevel(Organization.cldr).keySet()).build(); 44 // } 45 // } 46 47 public static final Pattern ALLOWED_IN_LIMITED_PATHS = 48 Pattern.compile("//ldml/annotations/annotation.*[⬆➡⬇⬅♾✖➕➖➗]"); 49 50 51 /* Example of special paths 52 * Pattern.compile( 53 "//ldml/" 54 + "(listPatterns/listPattern\\[@type=\"standard" 55 + "|annotations/annotation\\[@cp=\"([©®‼⁉☑✅✔✖✨✳✴❇❌❎❓-❕❗❣ ➕-➗-⭕⭕]|♀|♂)\"" 56 + "|localeDisplayNames/" 57 + "(scripts/script\\[@type=\"(Elym|Hmnp|Nand|Wcho)\"" 58 + "|territories/territory\\[@type=\"(MO|SZ)\"](\\[@alt=\"variant\"])?" 59 + "|types/type\\[@key=\"numbers\"]\\[@type=\"(hmnp|wcho)\"]" 60 + ")" 61 + "|dates/timeZoneNames/(metazone\\[@type=\"Macau\"]" 62 + "|zone\\[@type=\"Asia/Macau\"]" 63 + ")" 64 + ")" 65 ); 66 */ 67 68 //ldml/dates/timeZoneNames/metazone[@type="Macau"]/long/daylight, old: Macau Summer Time, new: Macao Summer Time 69 //ldml/dates/timeZoneNames/metazone[@type="Macau"]/long/standard, old: Macau Standard Time, new: Macao Standard Time 70 //ldml/localeDisplayNames/territories/territory[@type="SZ"][@alt="variant"], old: SZ, new: Swaziland 71 //ldml/dates/timeZoneNames/zone[@type="Asia/Macau"]/exemplarCity, old: Macau, new: Macao 72 //ldml/dates/timeZoneNames/metazone[@type="Macau"]/long/generic, old: Macau Time, new: Macao Time 73 //ldml/localeDisplayNames/territories/territory[@type="SZ"], old: Swaziland, new: Eswatini 74 75 76 /** 77 * Only call this if LIMITED_SUBMISSION 78 * @param localeString 79 * @param path 80 * @param isError 81 * @param isMissing 82 * @return true if submission is allowed, else false 83 */ allowEvenIfLimited(String localeString, String path, boolean isError, boolean isMissing)84 public static boolean allowEvenIfLimited(String localeString, String path, boolean isError, boolean isMissing) { 85 86 // don't limit new locales or errors 87 88 if (SubmissionLocales.NEW_CLDR_LOCALES.contains(localeString) || isError) { 89 return true; 90 } else { 91 int debug = 0; // for debugging 92 } 93 94 // all but CLDR locales are otherwise locked 95 96 if (!SubmissionLocales.CLDR_LOCALES.contains(localeString)) { 97 return false; 98 } else { 99 int debug = 0; // for debugging 100 } 101 102 // in those locales, lock all paths except missing and special 103 104 if (isMissing) { 105 return true; 106 } else { 107 int debug = 0; // for debugging 108 } 109 110 if (pathAllowedInLimitedSubmission(path)) { 111 return true; 112 } else { 113 int debug = 0; // for debugging 114 } 115 116 return false; // skip 117 } 118 119 private static final boolean DEBUG_REGEX = false; 120 121 /** 122 * Only public for testing 123 * @param path 124 * @return 125 */ pathAllowedInLimitedSubmission(String path)126 public static boolean pathAllowedInLimitedSubmission(String path) { 127 if (ALLOWED_IN_LIMITED_PATHS == null) { 128 return false; 129 } 130 final Matcher matcher = SubmissionLocales.ALLOWED_IN_LIMITED_PATHS.matcher(path); 131 boolean result = matcher.lookingAt(); 132 if (DEBUG_REGEX && !result) { 133 System.out.println(RegexUtilities.showMismatch(matcher, path)); 134 } 135 return result; 136 } 137 }