1 package org.unicode.cldr.tool; 2 3 import java.io.IOException; 4 5 import org.unicode.cldr.util.CldrUtility; 6 import org.unicode.cldr.util.DayPeriodData; 7 import org.unicode.cldr.util.DayPeriodInfo; 8 import org.unicode.cldr.util.DayPeriodInfo.DayPeriod; 9 import org.unicode.cldr.util.DayPeriodInfo.Type; 10 import org.unicode.cldr.util.LanguageGroup; 11 12 import com.ibm.icu.impl.Row.R3; 13 import com.ibm.icu.text.DateFormat; 14 import com.ibm.icu.util.TimeZone; 15 import com.ibm.icu.util.ULocale; 16 17 public class ChartDayPeriods extends Chart { 18 main(String[] args)19 public static void main(String[] args) { 20 new ChartDayPeriods().writeChart(null); 21 } 22 23 @Override getDirectory()24 public String getDirectory() { 25 return FormattedFileWriter.CHART_TARGET_DIR; 26 } 27 28 @Override getTitle()29 public String getTitle() { 30 return "Day Periods"; 31 } 32 33 @Override getExplanation()34 public String getExplanation() { 35 return "<p>Day Periods indicate roughly how the day is broken up in different languages. " 36 + "The following shows the ones that can be used as selectors in messages. " 37 + "The first column has a language group to collect languages together that are more likely to have similar day periods. " 38 + "For more information, see: " 39 + "<a href='http://unicode.org/repos/cldr/trunk/specs/ldml/tr35-dates.html#Day_Period_Rule_Sets'>Day Period Rules</a>. " 40 + "The latest release data for this chart is in " 41 + "<a href='http://unicode.org/cldr/latest/common/supplemental/dayPeriods.xml'>dayPeriods.xml</a>.<p>"; 42 } 43 44 @Override writeContents(FormattedFileWriter pw)45 public void writeContents(FormattedFileWriter pw) throws IOException { 46 47 TablePrinter tablePrinter = new TablePrinter() 48 .addColumn("Locale Group", "class='source'", CldrUtility.getDoubleLinkMsg(), "class='source'", true) 49 .addColumn("Locale Name", "class='source'", null, "class='source'", true) 50 .setSortPriority(1) 51 .addColumn("Code", "class='source'", CldrUtility.getDoubleLinkMsg(), "class='source'", true) 52 .setSortPriority(2) 53 .setBreakSpans(true) 54 //.addColumn("Type", "class='source'", null, "class='source'", true) 55 //.setSortPriority(3) 56 .addColumn("Start Time", "class='target'", null, "class='target'", true) 57 .addColumn("Day Period Code", "class='target'", null, "class='target'", true) 58 .addColumn("Example", "class='target'", null, "class='target'", true); 59 60 DateFormat df = DateFormat.getPatternInstance("HH:mm", ULocale.ENGLISH); 61 df.setTimeZone(TimeZone.GMT_ZONE); 62 63 for (Type type : Type.values()) { 64 if (type != Type.selection) { // skip until in better shape 65 continue; 66 } 67 for (String locale : SDI.getDayPeriodLocales(type)) { 68 if (locale.equals("root")) { 69 continue; 70 } 71 LanguageGroup group = LanguageGroup.get(new ULocale(locale)); 72 73 DayPeriodInfo dayPeriodInfo = SDI.getDayPeriods(Type.selection, locale); 74 for (int i = 0; i < dayPeriodInfo.getPeriodCount(); ++i) { 75 R3<Integer, Boolean, DayPeriod> data = dayPeriodInfo.getPeriod(i); 76 Integer time = data.get0(); 77 78 String name = DayPeriodData.getName(locale, data.get2()); 79 if (name == null) { 80 name = "missing"; 81 } 82 tablePrinter.addRow() 83 .addCell(group) 84 .addCell(ENGLISH.getName(locale)) 85 .addCell(locale) 86 //.addCell(type) 87 .addCell(df.format(time)) 88 .addCell(data.get2()) 89 .addCell(name) 90 .finishRow(); 91 } 92 } 93 } 94 pw.write(tablePrinter.toTable()); 95 } 96 97 } 98