[Unicode]   Common Locale Data Repository : Bug Tracking Home | Site Map | Search
 

Changeset 11158


Ignore:
Timestamp:
01/29/15 16:16:56 (4 years ago)
Author:
emmons
Message:

cldrbug 7968: Changes to JSON converter to group output into packages

Location:
trunk/tools/java/org/unicode/cldr/json
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/java/org/unicode/cldr/json/JSON_config.txt

    r11082 r11158  
    1 section=languages ; path=//cldr/main/[^/]++/localeDisplayNames/languages/.* 
    2 section=scripts ; path=//cldr/main/[^/]++/localeDisplayNames/scripts/.* 
    3 section=territories ; path=//cldr/main/[^/]++/localeDisplayNames/territories/.* 
    4 section=variants ; path=//cldr/main/[^/]++/localeDisplayNames/variants/.* 
    5 section=transformNames ; path=//cldr/main/[^/]++/localeDisplayNames/transformNames/.* 
    6 section=measurementSystemNames ; path=//cldr/main/[^/]++/localeDisplayNames/measurementSystemNames/.* 
    7 section=localeDisplayNames ; path=//cldr/main/[^/]++/localeDisplayNames/.* 
    8 section=contextTransforms ; path=//cldr/main/[^/]++/contextTransforms/.* 
    9 section=layout ; path=//cldr/main/[^/]++/layout/.* 
    10 section=characters ; path=//cldr/main/[^/]++/characters/.* 
    11 section=delimiters ; path=//cldr/main/[^/]++/delimiters/.* 
    12 section=ca-buddhist ; path=//cldr/main/[^/]++/dates/calendars/buddhist/.* 
    13 section=ca-chinese ; path=//cldr/main/[^/]++/dates/calendars/chinese/.* 
    14 section=ca-coptic ; path=//cldr/main/[^/]++/dates/calendars/coptic/.* 
    15 section=ca-dangi ; path=//cldr/main/[^/]++/dates/calendars/dangi/.* 
    16 section=ca-ethiopic ; path=//cldr/main/[^/]++/dates/calendars/ethiopic/.* 
    17 section=ca-ethiopic-amete-alem ; path=//cldr/main/[^/]++/dates/calendars/ethiopic-amete-alem/.* 
    18 section=ca-generic ; path=//cldr/main/[^/]++/dates/calendars/generic/.* 
    19 section=ca-gregorian ; path=//cldr/main/[^/]++/dates/calendars/gregorian/.* 
    20 section=ca-hebrew ; path=//cldr/main/[^/]++/dates/calendars/hebrew/.* 
    21 section=ca-indian ; path=//cldr/main/[^/]++/dates/calendars/indian/.* 
    22 section=ca-islamic ; path=//cldr/main/[^/]++/dates/calendars/islamic/.* 
    23 section=ca-islamic-civil ; path=//cldr/main/[^/]++/dates/calendars/islamic-civil/.* 
    24 section=ca-islamic-rgsa ; path=//cldr/main/[^/]++/dates/calendars/islamic-rgsa/.* 
    25 section=ca-islamic-tbla ; path=//cldr/main/[^/]++/dates/calendars/islamic-tbla/.* 
    26 section=ca-islamic-umalqura ; path=//cldr/main/[^/]++/dates/calendars/islamic-umalqura/.* 
    27 section=ca-japanese ; path=//cldr/main/[^/]++/dates/calendars/japanese/.* 
    28 section=ca-persian ; path=//cldr/main/[^/]++/dates/calendars/persian/.* 
    29 section=ca-roc ; path=//cldr/main/[^/]++/dates/calendars/roc/.* 
    30 section=dateFields ; path=//cldr/main/[^/]++/dates/fields/.* 
    31 section=timeZoneNames ; path=//cldr/main/[^/]++/dates/timeZoneNames/.* 
    32 section=currencies ; path=//cldr/main/[^/]++/numbers/currencies/.* 
    33 section=numbers ; path=//cldr/main/[^/]++/numbers/.* 
    34 section=units ; path=//cldr/main/[^/]++/units/.* 
    35 section=listPatterns ; path=//cldr/main/[^/]++/listPatterns/.* 
    36 section=posix ; path=//cldr/main/[^/]++/posix/.* 
    37 section=characterFallbacks ; path=//cldr/supplemental/characters/.* 
    38 section=dayPeriods ; path=//cldr/supplemental/dayPeriodRuleSet/.* 
    39 section=gender ; path=//cldr/supplemental/gender/.* 
    40 section=languageInfo ; path=//cldr/supplemental/languageInfo/.* 
    41 section=likelySubtags ; path=//cldr/supplemental/likelySubtags/.* 
    42 section=metaZones ; path=//cldr/supplemental/metaZones/.* 
    43 section=primaryZones ; path=//cldr/supplemental/primaryZones/.* 
    44 section=numberingSystems ; path=//cldr/supplemental/numberingSystems/.* 
    45 section=ordinals ; path=//cldr/supplemental/plurals\[@type="ordinal"\]/.* 
    46 section=plurals ; path=//cldr/supplemental/plurals\[@type="cardinal"\]/.* 
    47 section=postalCodeData ; path=//cldr/supplemental/postalCodeData/.* 
    48 section=currencyData ; path=//cldr/supplemental/currencyData/.* 
    49 section=territoryContainment ; path=//cldr/supplemental/territoryContainment/.* 
    50 section=languageData ; path=//cldr/supplemental/languageData/.* 
    51 section=languageMatching ; path=//cldr/supplemental/languageMatching/.* 
    52 section=territoryInfo ; path=//cldr/supplemental/territoryInfo/.* 
    53 section=calendarData ; path=//cldr/supplemental/calendarData/.* 
    54 section=calendarPreferenceData ; path=//cldr/supplemental/calendarPreferenceData/.* 
    55 section=weekData ; path=//cldr/supplemental/weekData/.* 
    56 section=timeData ; path=//cldr/supplemental/timeData/.* 
    57 section=measurementData ; path=//cldr/supplemental/measurementData/.* 
    58 section=codeMappings ; path=//cldr/supplemental/codeMappings/.* 
    59 section=parentLocales ; path=//cldr/supplemental/parentLocales/.* 
    60 section=references ; path=//cldr/supplemental/references/.* 
    61 section=telephoneCodeData ; path=//cldr/supplemental/telephoneCodeData/.* 
    62 section=windowsZones ; path=//cldr/supplemental/windowsZones/.* 
    63 section=aliases ; path=//cldr/supplemental/metadata/alias/(language|script|territory|variant|zone)Alias.* 
    64 section=suppressions ; path=//cldr/segments/segmentations/.* 
     1section=languages ; path=//cldr/main/[^/]++/localeDisplayNames/languages/.* ; package=localenames 
     2section=scripts ; path=//cldr/main/[^/]++/localeDisplayNames/scripts/.* ; package=localenames 
     3section=territories ; path=//cldr/main/[^/]++/localeDisplayNames/territories/.* ; package=localenames 
     4section=variants ; path=//cldr/main/[^/]++/localeDisplayNames/variants/.* ; package=localenames 
     5section=transformNames ; path=//cldr/main/[^/]++/localeDisplayNames/transformNames/.* ; package=localenames 
     6section=measurementSystemNames ; path=//cldr/main/[^/]++/localeDisplayNames/measurementSystemNames/.* ; package=units 
     7section=localeDisplayNames ; path=//cldr/main/[^/]++/localeDisplayNames/.* ; package=localenames 
     8section=contextTransforms ; path=//cldr/main/[^/]++/contextTransforms/.* ; package=misc 
     9section=layout ; path=//cldr/main/[^/]++/layout/.* ; package=misc 
     10section=characters ; path=//cldr/main/[^/]++/characters/.* ; package=misc 
     11section=delimiters ; path=//cldr/main/[^/]++/delimiters/.* ; package=misc 
     12section=ca-buddhist ; path=//cldr/main/[^/]++/dates/calendars/buddhist/.* ; package=cal-buddhist 
     13section=ca-chinese ; path=//cldr/main/[^/]++/dates/calendars/chinese/.* ; package=cal-chinese 
     14section=ca-coptic ; path=//cldr/main/[^/]++/dates/calendars/coptic/.* ; package=cal-coptic 
     15section=ca-dangi ; path=//cldr/main/[^/]++/dates/calendars/dangi/.* ; package=cal-dangi 
     16section=ca-ethiopic ; path=//cldr/main/[^/]++/dates/calendars/ethiopic/.* ; package=cal-ethiopic 
     17section=ca-ethiopic-amete-alem ; path=//cldr/main/[^/]++/dates/calendars/ethiopic-amete-alem/.* ; package=cal-ethiopic 
     18section=ca-generic ; path=//cldr/main/[^/]++/dates/calendars/generic/.* ; package=dates 
     19section=ca-gregorian ; path=//cldr/main/[^/]++/dates/calendars/gregorian/.* ; package=dates 
     20section=ca-hebrew ; path=//cldr/main/[^/]++/dates/calendars/hebrew/.* ; package=cal-hebrew 
     21section=ca-indian ; path=//cldr/main/[^/]++/dates/calendars/indian/.* ; package=cal-indian 
     22section=ca-islamic ; path=//cldr/main/[^/]++/dates/calendars/islamic/.* ; package=cal-islamic 
     23section=ca-islamic-civil ; path=//cldr/main/[^/]++/dates/calendars/islamic-civil/.* ; package=cal-islamic 
     24section=ca-islamic-rgsa ; path=//cldr/main/[^/]++/dates/calendars/islamic-rgsa/.* ; package=cal-islamic 
     25section=ca-islamic-tbla ; path=//cldr/main/[^/]++/dates/calendars/islamic-tbla/.* ; package=cal-islamic 
     26section=ca-islamic-umalqura ; path=//cldr/main/[^/]++/dates/calendars/islamic-umalqura/.* ; package=cal-islamic 
     27section=ca-japanese ; path=//cldr/main/[^/]++/dates/calendars/japanese/.* ; package=cal-japanese 
     28section=ca-persian ; path=//cldr/main/[^/]++/dates/calendars/persian/.* ; package=cal-persian 
     29section=ca-roc ; path=//cldr/main/[^/]++/dates/calendars/roc/.* ; package=cal-roc 
     30section=dateFields ; path=//cldr/main/[^/]++/dates/fields/.* ; package=dates 
     31section=timeZoneNames ; path=//cldr/main/[^/]++/dates/timeZoneNames/.* ; package=dates 
     32section=currencies ; path=//cldr/main/[^/]++/numbers/currencies/.* ; package=numbers 
     33section=numbers ; path=//cldr/main/[^/]++/numbers/.* ; package=numbers 
     34section=units ; path=//cldr/main/[^/]++/units/.* ; package=units 
     35section=listPatterns ; path=//cldr/main/[^/]++/listPatterns/.* ; package=misc 
     36section=posix ; path=//cldr/main/[^/]++/posix/.* ; package=misc 
     37section=characterFallbacks ; path=//cldr/supplemental/characters/.* ; package=core 
     38section=dayPeriods ; path=//cldr/supplemental/dayPeriodRuleSet/.* ; package=core 
     39section=gender ; path=//cldr/supplemental/gender/.* ; package=core 
     40section=languageInfo ; path=//cldr/supplemental/languageInfo/.* ; package=core 
     41section=likelySubtags ; path=//cldr/supplemental/likelySubtags/.* ; package=core 
     42section=metaZones ; path=//cldr/supplemental/metaZones/.* ; package=core 
     43section=primaryZones ; path=//cldr/supplemental/primaryZones/.* ; package=core 
     44section=numberingSystems ; path=//cldr/supplemental/numberingSystems/.* ; package=core 
     45section=ordinals ; path=//cldr/supplemental/plurals\[@type="ordinal"\]/.* ; package=core 
     46section=plurals ; path=//cldr/supplemental/plurals\[@type="cardinal"\]/.* ; package=core 
     47section=postalCodeData ; path=//cldr/supplemental/postalCodeData/.* ; package=core 
     48section=currencyData ; path=//cldr/supplemental/currencyData/.* ; package=core 
     49section=territoryContainment ; path=//cldr/supplemental/territoryContainment/.* ; package=core 
     50section=languageData ; path=//cldr/supplemental/languageData/.* ; package=core 
     51section=languageMatching ; path=//cldr/supplemental/languageMatching/.* ; package=core 
     52section=territoryInfo ; path=//cldr/supplemental/territoryInfo/.* ; package=core 
     53section=calendarData ; path=//cldr/supplemental/calendarData/.* ; package=core 
     54section=calendarPreferenceData ; path=//cldr/supplemental/calendarPreferenceData/.* ; package=core 
     55section=weekData ; path=//cldr/supplemental/weekData/.* ; package=core 
     56section=timeData ; path=//cldr/supplemental/timeData/.* ; package=core 
     57section=measurementData ; path=//cldr/supplemental/measurementData/.* ; package=core 
     58section=codeMappings ; path=//cldr/supplemental/codeMappings/.* ; package=core 
     59section=parentLocales ; path=//cldr/supplemental/parentLocales/.* ; package=core 
     60section=references ; path=//cldr/supplemental/references/.* ; package=core 
     61section=telephoneCodeData ; path=//cldr/supplemental/telephoneCodeData/.* ; package=core 
     62section=windowsZones ; path=//cldr/supplemental/windowsZones/.* ; package=core 
     63section=aliases ; path=//cldr/supplemental/metadata/alias/(language|script|territory|variant|zone)Alias.* ; package=core 
     64section=suppressions ; path=//cldr/segments/segmentations/.* ; package=segments 
  • trunk/tools/java/org/unicode/cldr/json/Ldml2JsonConverter.java

    r11061 r11158  
    2929import org.unicode.cldr.util.FileProcessor; 
    3030import org.unicode.cldr.util.Level; 
     31import org.unicode.cldr.util.LocaleIDParser; 
     32import org.unicode.cldr.util.StandardCodes; 
    3133import org.unicode.cldr.util.SupplementalDataInfo; 
    3234import org.unicode.cldr.util.XPathParts; 
     
    4648    private static final String MAIN = "main"; 
    4749    private static final String SEGMENTS = "segments"; 
    48  
     50    private static final StandardCodes sc = StandardCodes.make(); 
     51    private Set<String> defaultContentLocales = SupplementalDataInfo.getInstance().getDefaultContentLocales(); 
    4952    private static final Options options = new Options( 
    5053        "Usage: LDML2JsonConverter [OPTIONS] [FILES]\n" + 
     
    7073        .add("other", 'o', "(true|false)", "false", 
    7174            "Whether to write out the 'other' section, which contains any unmatched paths") 
     75        .add("packages", 'p', "(true|false)", "false", 
     76            "Whether to group data files into installable packages") 
    7277        .add("identity", 'i', "(true|false)", "true", 
    7378            "Whether to copy the identity info into all sections containing data") 
     
    109114        public String section; 
    110115        public Matcher matcher; 
     116        public String packageName; 
    111117 
    112118        public int compareTo(JSONSection other) { 
     
    134140            protected boolean handleLine(int lineCount, String line) { 
    135141                String[] lineParts = line.trim().split("\\s*;\\s*"); 
    136                 String key, value, section = null, path = null; 
     142                String key, value, section = null, path = null, packageName = null; 
    137143                boolean hasSection = false; 
    138144                boolean hasPath = false; 
     145                boolean hasPackage = false; 
    139146                for (String linePart : lineParts) { 
    140147                    int pos = linePart.indexOf('='); 
     
    150157                        hasPath = true; 
    151158                        path = value; 
    152                     } 
    153                     if (hasSection && hasPath) { 
    154                         JSONSection j = new JSONSection(); 
    155                         j.section = section; 
    156                         j.matcher = Pattern.compile(path).matcher(""); 
    157                         sections.add(j); 
    158                     } 
     159                    } else if (key.equals("package")) { 
     160                        hasPackage = true; 
     161                        packageName = value; 
     162                    } 
     163                } 
     164                if (hasSection && hasPath) { 
     165                    JSONSection j = new JSONSection(); 
     166                    j.section = section; 
     167                    j.matcher = Pattern.compile(path).matcher(""); 
     168                    if (hasPackage) { 
     169                        j.packageName = packageName; 
     170                    } 
     171                    sections.add(j); 
    159172                } 
    160173 
     
    353366     * @throws ParseException 
    354367     */ 
    355     private void convertCldrItems(String outDirname, String pathPrefix) 
     368    private void convertCldrItems(String dirName, String filename, String pathPrefix) 
    356369        throws IOException, ParseException { 
    357370        // zone and timezone items are queued for sorting first before they are 
     
    434447            outFilename = js.section + ".json"; 
    435448            boolean writeOther = Boolean.parseBoolean(options.get("other").getValue()); 
     449            boolean writePackages = Boolean.parseBoolean(options.get("packages").getValue()); 
    436450            if (js.section.equals("other") && !writeOther) { 
    437451                continue; 
    438452            } else { 
    439                 writeToFile(outDirname, outFilename, out); 
     453                StringBuilder outputDirname = new StringBuilder(outputDir); 
     454                if (writePackages && js.packageName != null) { 
     455                    outputDirname.append(File.separator + "cldr-" + js.packageName); 
     456                } 
     457                if (dirName.equals(MAIN) || dirName.equals(SEGMENTS)) { 
     458                    LocaleIDParser lp = new LocaleIDParser(); 
     459                    lp.set(filename); 
     460                    if (writePackages && defaultContentLocales.contains(filename) && 
     461                        lp.getRegion().length() > 0) { 
     462                        continue; 
     463                    } 
     464                    Level localeCoverageLevel = sc.getLocaleCoverageLevel("Cldr", filename); 
     465                    String tier; 
     466                    if (localeCoverageLevel == Level.MODERN || filename.equals("root")) { 
     467                        tier = "modern"; 
     468                    } else { 
     469                        tier = "full"; 
     470                    } 
     471                    outputDirname.append("-"+tier); 
     472                    outputDirname.append(File.separator + filename.replaceAll("_", "-")); 
     473                } 
     474                File dir = new File(outputDirname.toString()); 
     475                if (!dir.exists()) { 
     476                    dir.mkdirs(); 
     477                } 
     478                writeToFile(outputDirname.toString(), outFilename, out); 
    440479            } 
    441480 
     
    886925            mapPathsToSections(file, pathPrefix, sdi); 
    887926 
    888             String outputDirname; 
    889             if (dirName.equals(MAIN) || dirName.equals(SEGMENTS)) { 
    890                 outputDirname = outputDir + File.separator + filename.replaceAll("_", "-"); 
    891             } else { 
    892                 outputDirname = outputDir + File.separator + dirName; 
    893             } 
    894             File dir = new File(outputDirname); 
    895             if (!dir.exists()) { 
    896                 dir.mkdirs(); 
    897             } 
    898             convertCldrItems(outputDirname, pathPrefix); 
     927            convertCldrItems(dirName, filename, pathPrefix); 
    899928        } 
    900929    } 
  • trunk/tools/java/org/unicode/cldr/json/LdmlConvertRules.java

    r11061 r11158  
    1313    /** File set that will not be processed in JSON transformation. */ 
    1414    public static final Set<String> IGNORE_FILE_SET = Builder.with(new HashSet<String>()) 
    15         .add("coverageLevels").add("pluralRanges").freeze(); 
     15        .add("coverageLevels").add("pluralRanges").add("dayPeriods").freeze(); 
    1616 
    1717    /** 
Note: See TracChangeset for help on using the changeset viewer.