1 package org.unicode.cldr.tool; 2 3 import java.util.List; 4 import java.util.Map; 5 import java.util.Map.Entry; 6 import java.util.Set; 7 import java.util.TreeMap; 8 import java.util.TreeSet; 9 10 import org.unicode.cldr.util.CLDRConfig; 11 import org.unicode.cldr.util.CLDRFile; 12 import org.unicode.cldr.util.LanguageTagParser; 13 import org.unicode.cldr.util.StandardCodes; 14 import org.unicode.cldr.util.StandardCodes.LstrField; 15 import org.unicode.cldr.util.StandardCodes.LstrType; 16 import org.unicode.cldr.util.SupplementalDataInfo; 17 18 import com.google.common.base.Objects; 19 import com.ibm.icu.impl.Row.R2; 20 21 public class CompareSuppress { 22 23 enum Status { 24 missingSuppress, missingLikely, difference 25 } 26 main(String[] args)27 public static void main(String[] args) { 28 CLDRConfig config = CLDRConfig.getInstance(); 29 config.getStandardCodes(); 30 Map<LstrType, Map<String, Map<LstrField, String>>> lstr = StandardCodes.getEnumLstreg(); 31 Map<String, Map<LstrField, String>> langData = lstr.get(LstrType.language); 32 LanguageTagParser ltp = new LanguageTagParser(); 33 34 Map<String, String> langToSuppress = new TreeMap<>(); 35 for (Entry<String, Map<LstrField, String>> entry : langData.entrySet()) { 36 String lang = entry.getKey(); 37 Map<LstrField, String> value = entry.getValue(); 38 String script = value.get(LstrField.Suppress_Script); 39 if (script != null) { 40 langToSuppress.put(lang, script); 41 } 42 } 43 Set<String> langs = new TreeSet(langToSuppress.keySet()); 44 SupplementalDataInfo sdi = config.getSupplementalDataInfo(); 45 Map<String, String> likely = sdi.getLikelySubtags(); 46 for (Entry<String, String> s : likely.entrySet()) { 47 ltp.set(s.getValue()); 48 langs.add(ltp.getLanguage()); 49 } 50 LikelySubtags likelyMaker = new LikelySubtags(likely); 51 CLDRFile english = config.getEnglish(); 52 Map<String, R2<List<String>, String>> langAlias = sdi.getLocaleAliasInfo().get("language"); 53 54 for (Status status : Status.values()) { 55 for (String base : langs) { 56 String suppressScript = langToSuppress.get(base); 57 58 String likelyScript = null; 59 String max = likelyMaker.maximize(base); 60 if (max != null) { 61 ltp.set(max); 62 likelyScript = ltp.getScript(); 63 } 64 String prefix = langAlias.containsKey(base) ? "(dep) " : ""; 65 66 if (!Objects.equal(suppressScript, likelyScript)) { 67 switch (status) { 68 case difference: 69 if (likelyScript != null && suppressScript != null) { 70 System.out.println(prefix + status + "\t" 71 + langAndName(english, base) 72 + "\tSuppress:\t" + scriptAndName(english, suppressScript) 73 + "\tLikely: \t" + scriptAndName(english, likelyScript)); 74 } 75 break; 76 case missingLikely: 77 if (likelyScript == null) { 78 System.out.println(prefix + status + "\t" 79 + langAndName(english, base) 80 + "\t" + scriptAndName(english, suppressScript)); 81 } 82 break; 83 case missingSuppress: 84 if (suppressScript == null) { 85 System.out.println(prefix + status + "\t" 86 + langAndName(english, base) 87 + "\t" + scriptAndName(english, likelyScript)); 88 break; 89 } 90 } 91 } 92 } 93 System.out.println(); 94 } 95 } 96 langAndName(CLDRFile english, String base)97 public static String langAndName(CLDRFile english, String base) { 98 return base + "\t" + english.getName(base); 99 } 100 scriptAndName(CLDRFile english, String suppressScript)101 public static String scriptAndName(CLDRFile english, String suppressScript) { 102 return suppressScript 103 + "\t" + english.getName(CLDRFile.SCRIPT_NAME, suppressScript); 104 } 105 }