~zhangew401/scope-aggregator/fix-empty-query-to-clickstore

« back to all changes in this revision

Viewing changes to po/json_get_i18n.py

  • Committer: Kyle Nitzsche
  • Date: 2016-06-28 13:15:57 UTC
  • mfrom: (163.1.10 no-hints)
  • Revision ID: kyle.nitzsche@canonical.com-20160628131557-d80j07s5jk18hi0j
scope-agg projects no longer require a separate hints child scope to 
provide quick start help or to provide the no netork of the no location
message. All scopes rebasing on 4.8 must change their hints.json file
since the structure is now chagned. 

See 4.8-rebase-local-hints-README.md for complete details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
import json
 
3
import os
 
4
import sys
 
5
 
 
6
idx = -1
 
7
trans = dict();
 
8
 
 
9
def dolist(alist ):
 
10
    for l in alist:
 
11
        if type(l) is list:
 
12
            dolist(l)
 
13
        if type(l) is dict:
 
14
            dodict(l)
 
15
 
 
16
def dodict(adict):
 
17
    for k,v in adict.items():
 
18
        if k.startswith("_"):
 
19
            global idx
 
20
            idx += 1
 
21
            global tran
 
22
            trans[k + str(idx)] = v
 
23
        if type(v) is list:
 
24
            dolist(v)
 
25
        if type(v) is dict:
 
26
            dodict(v)
 
27
 
 
28
if len(sys.argv) < 2:
 
29
    print("File arg missing. Stopping")
 
30
    sys.exit(1)
 
31
 
 
32
if os.path.exists("i18n.json"):
 
33
    os.remove("i18n.json")
 
34
 
 
35
print("the filel:", sys.argv[1])
 
36
 
 
37
with open(sys.argv[1]) as j_file:
 
38
    j = json.load(j_file)
 
39
 
 
40
if type(j) is list:
 
41
    dolist(j)
 
42
if type(j) is dict:
 
43
    dodict(j)
 
44
 
 
45
with open("i18n.json", "w") as outfile:
 
46
    json.dump(trans, outfile, indent=4)
 
47
 
 
48
#print(json.dumps(trans, indent=4))