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