• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 package org.unicode.icu.tool.cldrtoicu;
4 
5 import java.nio.file.Path;
6 import java.util.Map;
7 import java.util.Set;
8 
9 import com.google.common.base.Preconditions;
10 import org.unicode.cldr.api.CldrDraftStatus;
11 import org.unicode.icu.tool.cldrtoicu.LdmlConverter.OutputType;
12 
13 import com.google.common.base.Ascii;
14 
15 import static com.google.common.base.Preconditions.checkNotNull;
16 
17 /** API for configuring the LDML converter. */
18 public interface LdmlConverterConfig {
19     /** Output directories for ICU locale data (this is not used for supplemental data). */
20     enum IcuLocaleDir {
21         /** Data for the break-iterator library. */
22         BRKITR(true),
23         /** Data for the collations library. */
24         COLL(true),
25         /** Currency data. */
26         CURR(false),
27         /** Language data. */
28         LANG(false),
29         /** General locale data. */
30         LOCALES(true),
31         /** Rule-based number formatter data. */
32         RBNF(true),
33         /** Region data. */
34         REGION(false),
35         /** Measurement and units data. */
36         UNIT(false),
37         /** Timezone data. */
38         ZONE(false);
39 
40         private final String dirName = Ascii.toLowerCase(name());
41         private final boolean includeEmpty;
42 
IcuLocaleDir(boolean includeEmpty)43         IcuLocaleDir(boolean includeEmpty) {
44             this.includeEmpty = includeEmpty;
45         }
46 
47         /** Returns the relative output directory name. */
getOutputDir()48         public String getOutputDir() {
49             return dirName;
50         }
51 
52         /**
53          * Whether the directory is expected to contain empty data files (used to advertise
54          * the supported set of locales for the "service" provided by the data in that
55          * directory).
56          */
57         // TODO: Document why there's a difference between directories for empty files.
includeEmpty()58         boolean includeEmpty() {
59             return includeEmpty;
60         }
61     }
62 
63     final class IcuVersionInfo {
64         private final String icuVersion;
65         private final String icuDataVersion;
66         private final String cldrVersion;
67 
IcuVersionInfo(String icuVersion, String icuDataVersion, String cldrVersion)68         public IcuVersionInfo(String icuVersion, String icuDataVersion, String cldrVersion) {
69             this.icuVersion = checkNotNull(icuVersion);
70             this.icuDataVersion = checkNotNull(icuDataVersion);
71             this.cldrVersion = checkNotNull(cldrVersion);
72         }
73 
getIcuVersion()74         public String getIcuVersion() {
75             return icuVersion;
76         }
77 
getIcuDataVersion()78         public String getIcuDataVersion() {
79             return icuDataVersion;
80         }
81 
getCldrVersion()82         public String getCldrVersion() {
83             return cldrVersion;
84         }
85     }
86 
87     /**
88      * Returns the set of output types to be converted. Use {@link OutputType#ALL} to convert
89      * everything.
90      */
getOutputTypes()91     Set<OutputType> getOutputTypes();
92 
93     /**
94      * Returns an additional "specials" directory containing additional ICU specific XML
95      * files depending on the given output type. This is where the converter finds any XML
96      * files using the "icu:" namespace.
97      */
getSpecialsDir()98     Path getSpecialsDir();
99 
100     /**
101      * Returns the root of the ICU output directory hierarchy into which ICU data file are
102      * written.
103      */
getOutputDir()104     Path getOutputDir();
105 
106     /**
107      * Returns a CLDR version String (e.g. {@code "36.1"}) according to either the specified option
108      * or (as a fallback) the version specified by the CLDR library against which this code is run.
109      */
getVersionInfo()110     IcuVersionInfo getVersionInfo();
111 
112     /** Returns the minimal draft status for CLDR data to be converted. */
getMinimumDraftStatus()113     CldrDraftStatus getMinimumDraftStatus();
114 
115     /**
116      * Returns the complete set of locale IDs which should be considered for processing for this
117      * configuration.
118      *
119      * <p>Note that this set can contain IDs which have no CLDR data associated with them if they
120      * are suitable aliases (e.g. they are deprecated versions of locale IDs for which data does
121      * exist).
122      */
getAllLocaleIds()123     Set<String> getAllLocaleIds();
124 
125     /**
126      * Returns the set of locale IDs to be processed for the given directory. This set must always
127      * be a subset of {@link #getAllLocaleIds()}.
128      */
getTargetLocaleIds(IcuLocaleDir dir)129     Set<String> getTargetLocaleIds(IcuLocaleDir dir);
130 
131     /**
132      * Returns a map of locale IDs which specifies aliases which are applied to the given directory
133      * in contradiction to the natural alias which would otherwise be generated. This mechanism
134      * allows for restructuring locale relationships on a per directory basis for special-case
135      * behaviour (such as sharing data which would otherwise need to be copied).
136      */
getForcedAliases(IcuLocaleDir dir)137     Map<String, String> getForcedAliases(IcuLocaleDir dir);
138 
139     /**
140      * Returns a map of locale IDs which specifies aliases which are applied to the given directory
141      * in contradiction to the natural parent which would otherwise be generated. This mechanism
142      * allows for restructuring locale relationships on a per directory basis for special-case
143      * behaviour (such as sharing data which would otherwise need to be copied).
144      */
145     // TODO: Combine this and the force aliases into a single mechanism at this level.
getForcedParents(IcuLocaleDir dir)146     Map<String, String> getForcedParents(IcuLocaleDir dir);
147 
148     /**
149      * Whether to emit a summary report for debug purposes after conversion is complete.
150      */
emitReport()151     boolean emitReport();
152 }
153