1 package org.unicode.cldr.tool; 2 3 import java.util.Date; 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.CLDRFile; 11 import org.unicode.cldr.util.CLDRPaths; 12 import org.unicode.cldr.util.Factory; 13 import org.unicode.cldr.util.StandardCodes; 14 import org.unicode.cldr.util.SupplementalDataInfo; 15 import org.unicode.cldr.util.SupplementalDataInfo.CurrencyDateInfo; 16 import org.unicode.cldr.util.SupplementalDataInfo.OfficialStatus; 17 import org.unicode.cldr.util.SupplementalDataInfo.PopulationData; 18 19 import com.ibm.icu.impl.Relation; 20 21 public class CheckEnglishCurrencyNames { 22 static SupplementalDataInfo supplementalDataInfo = SupplementalDataInfo 23 .getInstance(CLDRPaths.SUPPLEMENTAL_DIRECTORY); 24 static StandardCodes sc = StandardCodes.make(); 25 static Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*"); 26 static CLDRFile english = cldrFactory.make("en", true); 27 main(String[] args)28 public static void main(String[] args) { 29 Date now = new Date(); 30 Set<String> currencyCodes = sc.getGoodAvailableCodes("currency"); 31 Relation<String, String> currencyCodesWithDates = Relation.of(new TreeMap<String, Set<String>>(), TreeSet.class); 32 Relation<String, String> modernCurrencyCodes2territory = Relation.of(new TreeMap<String, Set<String>>(), TreeSet.class); 33 Set<String> territoriesWithoutModernCurrencies = new TreeSet<String>(sc.getGoodAvailableCodes("territory")); 34 35 for (String territory : sc.getGoodAvailableCodes("territory")) { 36 if (supplementalDataInfo.getContained(territory) != null) { 37 territoriesWithoutModernCurrencies.remove(territory); 38 continue; 39 } 40 System.out.println(territory); 41 Set<CurrencyDateInfo> currencyInfo = supplementalDataInfo.getCurrencyDateInfo(territory); 42 if (currencyInfo == null) { 43 System.out.println("\tNONE"); 44 continue; 45 } 46 for (CurrencyDateInfo dateInfo : currencyInfo) { 47 if (!dateInfo.isLegalTender()) { 48 continue; 49 } 50 final String currency = dateInfo.getCurrency(); 51 final Date start = dateInfo.getStart(); 52 final Date end = dateInfo.getEnd(); 53 if (end.compareTo(now) >= 0) { 54 modernCurrencyCodes2territory.put(currency, territory); 55 territoriesWithoutModernCurrencies.remove(territory); 56 } else { 57 currencyCodesWithDates.put(currency, territory); 58 } 59 System.out.println("\t" + currency + "\t" + start + "\t" + end); 60 } 61 } 62 System.out.println("Modern Codes: " + modernCurrencyCodes2territory); 63 for (String currency : modernCurrencyCodes2territory.keySet()) { 64 final String name = english.getName(CLDRFile.CURRENCY_NAME, currency).toLowerCase(); 65 if (name.contains("new") || name.contains("old")) { 66 System.out.println(currency + "\t" + name); 67 } 68 } 69 System.out.println("Non-Modern Codes (with dates): " + currencyCodesWithDates); 70 for (String currency : currencyCodesWithDates.keySet()) { 71 final String name = english.getName(CLDRFile.CURRENCY_NAME, currency).toLowerCase(); 72 if (name.contains("new") || name.contains("old")) { 73 System.out.println(currency + "\t" + name); 74 } 75 } 76 Set<String> remainder = new TreeSet<String>(); 77 remainder.addAll(currencyCodes); 78 remainder.removeAll(currencyCodesWithDates.keySet()); 79 System.out.println("Currencies without Territories: " + remainder); 80 System.out.println("Territories without Modern Currencies: " + territoriesWithoutModernCurrencies); 81 82 Relation<String, String> territory2official = Relation.of(new TreeMap<String, Set<String>>(), TreeSet.class); 83 84 // finding official languages 85 for (String language : supplementalDataInfo.getLanguagesForTerritoriesPopulationData()) { 86 for (String territory : supplementalDataInfo.getTerritoriesForPopulationData(language)) { 87 PopulationData populationData = supplementalDataInfo.getLanguageAndTerritoryPopulationData(language, 88 territory); 89 OfficialStatus status = populationData.getOfficialStatus(); 90 switch (status) { 91 case official: 92 case de_facto_official: 93 case recognized: 94 territory2official.put(territory, language); 95 } 96 } 97 } 98 Relation<String, String> currency2symbols = Relation.of(new TreeMap<String, Set<String>>(), TreeSet.class); 99 Map<String, Relation<String, String>> currency2symbol2locales = new TreeMap<String, Relation<String, String>>(); // 100 System.out.format("Raw usage data\n"); 101 Set<String> noOfficialLanguages = new TreeSet<String>(); 102 103 for (Entry<String, Set<String>> currencyAndTerritories : modernCurrencyCodes2territory.keyValuesSet()) { 104 String currency = currencyAndTerritories.getKey(); 105 Set<String> territories = currencyAndTerritories.getValue(); 106 for (String territory : territories) { 107 final Set<String> languages = territory2official.get(territory); 108 if (languages == null) { 109 noOfficialLanguages.add(territory); 110 continue; 111 } 112 for (String language : languages) { 113 CLDRFile nativeLanguage = null; 114 String locale = language + "_" + territory; 115 try { 116 nativeLanguage = cldrFactory.make(locale, true); 117 } catch (Exception e) { 118 try { 119 nativeLanguage = cldrFactory.make(language, true); 120 } catch (Exception e1) { 121 } 122 } 123 String symbol = nativeLanguage == null ? "N/A" : nativeLanguage.getName(CLDRFile.CURRENCY_SYMBOL, 124 currency); 125 System.out.println( 126 currency + "\t" + english.getName(CLDRFile.CURRENCY_NAME, currency) 127 + "\t" + territory + "\t" + english.getName(CLDRFile.TERRITORY_NAME, territory) 128 + "\t" + language + "\t" + english.getName(language) 129 + "\t" + symbol); 130 // TODO add script 131 if (nativeLanguage != null) { 132 currency2symbols.put(currency, symbol); 133 Relation<String, String> rel = currency2symbol2locales.get(currency); 134 if (rel == null) { 135 currency2symbol2locales.put(currency, 136 rel = Relation.of(new TreeMap<String, Set<String>>(), TreeSet.class)); 137 } 138 rel.put(symbol, locale); 139 } 140 } 141 } 142 } 143 System.out.format("No official languages\n"); 144 for (String territory : noOfficialLanguages) { 145 System.out.println(territory + "\t" + english.getName(CLDRFile.TERRITORY_NAME, territory)); 146 } 147 System.out.format("Collected usage data\n"); 148 for (Entry<String, Set<String>> currencyAndSymbols : currency2symbols.keyValuesSet()) { 149 String currency = currencyAndSymbols.getKey(); 150 Set<String> symbols = currencyAndSymbols.getValue(); 151 System.out.println(currency + "\t" + english.getName(CLDRFile.CURRENCY_NAME, currency) 152 + "\t" + symbols.size() 153 + "\t" + symbols 154 + "\t" + currency2symbol2locales.get(currency)); 155 } 156 157 } 158 } 159