[Unicode]   Unicode Localization Interoperability Technical Committee : Bug Tracking Home | Site Map | Search
 

source: trunk/abbrs/src/cookjson.py @ 34

Revision 34, 2.4 KB checked in by srloomis, 16 months ago (diff)

ticket:7336: move pt_BR to pt. Update XML generator with latest CLDR DTD and latest proposal.

Line 
1# -*- coding: utf-8 -*-
2# by srl
3#
4# Cook the ULI JSON by loading CLDR data
5
6import sys
7reload(sys)
8sys.setdefaultencoding("utf-8")
9
10import json
11import os
12
13dbg = False
14
15locs = []
16
17# doing it wrong.
18files = os.walk('../json')
19for ent in files:
20    (path,dirs,files) = ent
21    if(path.find("/.svn") != -1):
22        continue
23    for file in files:
24        if(file.endswith('.json')):
25            locs.append(file.split('.')[0])
26
27#testing
28#locs = ['de']
29
30# TODO: read this from argv[1]
31# cldr-json must be local or symlink
32CLDR_JSON='./cldr-json'
33
34for loc in locs:
35    print 'Locale: %s' % (loc)
36
37
38    #print(data)
39
40    ulifn= '../json/%s.json' % (loc)
41    ulif = open(ulifn, 'rb')
42    data = json.load(ulif)
43    ulif.close()
44
45
46    cldr = {}
47
48    # don't load all of cldr
49    subfiles = ['ca-gregorian']
50
51    for subfile in subfiles:
52        fni = '%s/main/%s/%s.json' % (CLDR_JSON, loc, subfile)
53        print "Reading %s" % (fni)
54        fi  = open(fni, 'rb')
55        cldr[subfile] = json.load(fi)
56        fi.close()
57
58    # read ULI data
59    abbrs = set(data['data']['abbrs'])
60
61    # TODO: parameterize, use all calendars. Additional items.
62    lists = [cldr["ca-gregorian"]["main"][loc]["dates"]["calendars"]["gregorian"]["months"]["format"]["abbreviated"], cldr["ca-gregorian"]["main"][loc]["dates"]["calendars"]["gregorian"]["days"]["format"]["abbreviated"],cldr["ca-gregorian"]["main"][loc]["dates"]["calendars"]["gregorian"]["eras"]["eraAbbr"]]
63
64    # list of stuff to add
65    #print lists
66    len0 = len(abbrs)
67    print "len: %d" % len(abbrs)
68
69    for cldrlist in lists:
70        for k in cldrlist.keys():
71            v = cldrlist[k]
72            # print v
73            # TODO: use other abbrs besides '.'.  Find out which items cause break.
74            if v[len(v)-1] == '.':
75                # ends with dot
76                abbrs.add(v)
77
78    len1 = len(abbrs)
79
80    print "new len: %d - added %d" % (len(abbrs), (len1-len0))
81    #abbrs.sort()
82    # copy back
83    data['data']['abbrs'] = list(abbrs)
84    data['data']['abbrs'].sort()
85
86    cldrver = cldr["ca-gregorian"]["main"][loc]["identity"]["version"]["@cldrVersion"]
87
88
89    if len1 > len0:
90        data['about']['cooked'] = 'Loaded %d abbrs from CLDR %s' % (len1-len0, cldrver)
91        data['about']['cldrVer'] = cldrver
92    else:
93        data['about']['cooked'] = 'No abbrs loaded from CLDR %s' % (cldrver)
94
95    fn = '../json-cooked/%s.json' % (loc)
96    f = open(fn, 'wb')
97    print >>f, json.dumps(data, sort_keys=True, indent=4)
98
Note: See TracBrowser for help on using the repository browser.