1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2013-2014, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9 package com.ibm.icu.samples.iuc; 10 11 import java.util.HashMap; 12 import java.util.HashSet; 13 import java.util.Locale; 14 import java.util.Map; 15 import java.util.Set; 16 17 import com.ibm.icu.samples.iuc.PopulationData.TerritoryEntry; 18 import com.ibm.icu.text.LocaleDisplayNames; 19 import com.ibm.icu.text.LocaleDisplayNames.DialectHandling; 20 import com.ibm.icu.text.MessageFormat; 21 import com.ibm.icu.util.ULocale; 22 import com.ibm.icu.util.UResourceBundle; 23 24 /** 25 * @author srl 26 * 27 */ 28 public class Sample40_PopMsg { 29 public static void main(String... args) { 30 // setup 31 Locale defaultLocaleID = Locale.getDefault(); 32 LocaleDisplayNames ldn = LocaleDisplayNames.getInstance(ULocale.forLocale(defaultLocaleID), 33 DialectHandling.DIALECT_NAMES); 34 String defaultLocaleName = ldn.localeDisplayName(defaultLocaleID); 35 36 Set<PopulationData.TerritoryEntry> territoryList; 37 territoryList = PopulationData.getTerritoryEntries(defaultLocaleID, 38 new HashSet<TerritoryEntry>()); 39 int territoryCount = territoryList.size(); 40 UResourceBundle resourceBundle = 41 UResourceBundle.getBundleInstance( 42 Sample40_PopMsg.class.getPackage().getName().replace('.', '/')+"/data/popmsg", 43 defaultLocaleID, 44 Sample40_PopMsg.class.getClassLoader()); 45 46 // say hello 47 String pattern = resourceBundle.getString("welcome"); 48 MessageFormat fmt = new MessageFormat(pattern,defaultLocaleID); 49 Map<String, Object> msgargs = new HashMap<String, Object>(); 50 msgargs.put("territoryCount", territoryCount); 51 msgargs.put("myLanguage", defaultLocaleName); 52 msgargs.put("today", System.currentTimeMillis()); 53 System.out.println(fmt.format(msgargs, new StringBuffer(), null)); 54 55 // Population roll call 56 String info = resourceBundle.getString("info"); 57 Map<String, Object> infoArgs = new HashMap<String, Object>(); 58 for(PopulationData.TerritoryEntry entry : territoryList) { 59 infoArgs.put("territory", entry.territoryName()); 60 infoArgs.put("population", entry.population()); 61 System.out.println(MessageFormat.format(info, infoArgs)); 62 } 63 } 64 } 65