forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cldrDict_sconscript
130 lines (125 loc) · 3.31 KB
/
cldrDict_sconscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
###
#This file is a part of the NVDA project.
#URL: http://www.nvda-project.org/
#Copyright 2018 NV Access Limited, Babbage B.V.
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2.0, as published by
#the Free Software Foundation.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#This license can be found at:
#http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
###
Import(
'env', 'sourceDir',
)
def createCLDRAnnotationsDict(sources, dest):
import codecs
from xml.etree import ElementTree
from collections import OrderedDict
cldrDict = OrderedDict()
for source in sources:
tree = ElementTree.parse(source)
for element in tree.iter("annotation"):
if element.attrib.get("type") == "tts":
cldrDict[element.attrib['cp']] = element.text.replace(":","")
assert cldrDict, "cldrDict is empty"
with codecs.open(dest, "w", "utf_8_sig", errors="replace") as dictFile:
dictFile.write(u"symbols:\r\n")
for pattern, description in cldrDict.items():
# Punctuations are set to none for CLDR characters to be pronounced even if user set punctuation level to None
dictFile.write(u"{pattern}\t{description}\tnone\r\n".format(
pattern=pattern,
description=description
))
cldrDictAction=env.Action(
lambda target,source,env: createCLDRAnnotationsDict([src.path for src in source], target[0].path),
lambda target,source,env: 'Generating %s'%target[0],
)
cldrDictBuilder=env.Builder(
action=cldrDictAction,
suffix='.dic',
src_suffix='.xml',
)
env['BUILDERS']['cldrDict']=cldrDictBuilder
NVDAToCLDRLocales = {
"af_ZA":("af",),
"am":("am",),
#"an":(),
"ar":("ar",),
"as":("as",),
"bg":("bg",),
"bn":("bn",),
"ca":("ca",),
#"ckb":(),
"cs":("cs",),
"da":("da",),
"de":("de",),
"de_CH":("de_CH",),
"el":("el",),
"en":("en_001","en"),
"es":("es",),
#"es_CO":(),
"fa":("fa",),
"fi":("fi",),
"fr":("fr",),
"ga":("ga",),
"gl":("gl",),
"gu":("gu",),
"he":("he",),
"hi":("hi",),
"hr":("hr",),
"hu":("hu",),
"id":("id",),
"is":("is",),
"it":("it",),
"ja":("ja",),
"ka":("ka",),
#"kmr":(),
"kn":("kn",),
"ko":("ko",),
#"kok":(),
"ky":("ky",),
"lt":("lt",),
"mk":("mk",),
"ml":("ml",),
"mn":("mn",),
#"mni":(),
"my":("my",),
"nb_NO":("nb",),
"ne":("ne",),
"nl":("nl",),
"nn_NO":("nn",),
"pa":("pa",),
"pl":("pl",),
"pt_BR":("pt",),
"pt_pt":("pt","pt_PT"),
"ro":("ro",),
"ru":("ru",),
"sk":("sk",),
"sl":("sl",),
#"so":(),
"sq":("sq",),
"sr":("sr",),
"sv":("sv",),
"ta":("ta",),
"te":("te",),
"th":("th",),
"tr":("tr",),
"uk":("uk",),
"vi":("vi",),
"zh_cn":("zh",),
"zh_hk":("zh","zh_Hant_HK"),
"zh_tw":("zh","zh_Hant"),
}
annotationsDir = env.Dir("include/cldr/common/annotations")
annotationsDerivedDir = env.Dir("include/cldr/common/annotationsDerived")
for destLocale, sourceLocales in NVDAToCLDRLocales.items():
cldrSources = []
# First add all annotations, then the derived ones.
for sourceLocale in sourceLocales:
cldrSources.append(annotationsDir.File("%s.xml" % sourceLocale))
for sourceLocale in sourceLocales:
cldrSources.append(annotationsDerivedDir.File("%s.xml" % sourceLocale))
env.cldrDict(sourceDir.Dir("locale/%s" % destLocale).File("cldr.dic"), cldrSources)