forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brailleTables.py
907 lines (850 loc) · 38.5 KB
/
brailleTables.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2008-2024 NV Access Limited, Joseph Lee, Babbage B.V., Julien Cochuyt, Leonard de Ruijter
"""Manages information about available braille translation tables."""
import collections
from enum import Enum, StrEnum, auto
import os
from locale import strxfrm
from typing import NamedTuple
from configobj import ConfigObj, flatten_errors
from configobj.validate import Validator
import config
import globalVars
from logHandler import log
import languageHandler
TABLES_DIR = os.path.join(globalVars.appDir, "louis", "tables")
"""The directory in which liblouis braille tables are located."""
DEFAULT_TABLE = "en-ueb-g1.ctb"
"""The default braille table."""
class TableSource(StrEnum):
BUILTIN = "builtin"
"""The name of the builtin table source"""
SCRATCHPAD = "scratchpad"
"""The name of the scratchpad table source"""
class TableType(Enum):
INPUT = auto()
"""Input type for braille tables for back-translation"""
OUTPUT = auto()
"""Output type for braille tables for translation"""
_tablesDirs = collections.ChainMap(
{
TableSource.BUILTIN: TABLES_DIR,
},
)
"""Chainmap of directories for braille tables lookup, including custom tables."""
class BrailleTable(NamedTuple):
"""Information about a braille table."""
fileName: str
"""The file name of the table."""
displayName: str
"""The name of the table as displayed to the user. This should be translatable."""
contracted: bool = False
"""True if the table is contracted, False if uncontracted."""
output: bool = True
"""True if this table can be used for output, False if not."""
input: bool = True
"""True if this table can be used for input, False if not."""
source: str = TableSource.BUILTIN
"""An identifier describing the source of the table.
This defaults to C{TableSource.BUILTIN}, but is set to the name of the add-on or "scratchpad",
depending on its source.
"""
_tables = collections.ChainMap()
"""Maps file names to L{BrailleTable} objects.
The parent map will be loaded at import time with the builtin tables.
The first map will be loaded when calling L{initialize} with the custom tables,
and cleared when calling L{terminate}.
"""
_inputTableForLangs: dict[str, str] = dict()
"""Maps languages to input L{BrailleTable.fileName}."""
_outputTableForLangs: dict[str, str] = dict()
"""Maps languages to output L{BrailleTable.fileName}."""
def getDefaultTableForCurLang(tableType: TableType) -> str:
"""Gets the file name of the braille table for the current NVDA language.
:param tableType: INPUT (back-translation) or OUTPUT (translation).
:return: A L{BrailleTable} fileName.
"""
match tableType:
case tableType.INPUT:
langDict = _inputTableForLangs
case tableType.OUTPUT:
langDict = _outputTableForLangs
case _:
raise ValueError(f"Unknown tableType: {tableType}")
lang = languageHandler.getLanguage()
table = langDict.get(lang)
if table is not None:
return table
if "_" in lang:
lang = lang.split("_")[0]
return langDict.get(lang, DEFAULT_TABLE)
def addTable(
fileName: str,
displayName: str,
contracted: bool = False,
output: bool = True,
input: bool = True,
source: str = TableSource.BUILTIN,
inputForLangs: set[str] | None = None,
outputForLangs: set[str] | None = None,
):
"""Register a braille translation table.
At least one of C{input} or C{output} must be C{True}.
:param fileName: The file name of the table.
:param displayname: The name of the table as displayed to the user. This should be translatable.
:param contracted: True if the table is contracted, False if uncontracted.
:param output: True if this table can be used for output, False if not.
:param input: True if this table can be used for input, False if not.
:param source: An identifier describing the source of the table.
:param inputForLangs: A set of languages available in NVDA or C{None}.
:param outputForLangs: A set of languages available in NVDA or C{None}.
"""
if not output and not input:
raise ValueError("input and output cannot both be False")
table = BrailleTable(fileName, displayName, contracted, output, input, source)
_tables[fileName] = table
if inputForLangs is not None:
for lang in inputForLangs:
if lang in _inputTableForLangs:
log.warning(
f"input table lang {lang} already set to {_inputTableForLangs[lang]} overwriting to {table.fileName}",
)
_inputTableForLangs[lang] = table.fileName
if outputForLangs is not None:
for lang in outputForLangs:
if lang in _outputTableForLangs:
log.warning(
f"output table lang {lang} already set to {_outputTableForLangs[lang]} overwriting to {table.fileName}",
)
_outputTableForLangs[lang] = table.fileName
def getTable(fileName: str) -> BrailleTable:
"""Get information about a table given its file name.
@return: The table information.
@raise LookupError: If there is no table registered with this file name.
"""
if fileName == "auto":
fileName = DEFAULT_TABLE
return _tables[fileName]
def listTables() -> list[BrailleTable]:
"""List all registered braille tables.
@return: A list of braille tables.
"""
return sorted(
_tables.values(),
key=lambda table: (table.source != TableSource.BUILTIN, strxfrm(table.displayName)),
)
#: Maps old table names to new table names for tables renamed in newer versions of liblouis.
RENAMED_TABLES = {
"ar-fa.utb": "fa-ir-g1.utb",
"da-dk-g16.utb": "da-dk-g16.ctb",
"da-dk-g18.utb": "da-dk-g18.ctb",
"de-de-g0.utb": "de-g0.utb",
"de-de-g1.ctb": "de-g1.ctb",
"de-de-g2.ctb": "de-g2.ctb",
"de-g0-bidi.utb": "de-g0-detailed.utb",
"de-g1-bidi.ctb": "de-g1-detailed.ctb",
"en-us-comp8.ctb": "en-us-comp8-ext.utb",
"fr-ca-g1.utb": "fr-bfu-comp6.utb",
"Fr-Ca-g2.ctb": "fr-bfu-g2.ctb",
"gr-bb.ctb": "grc-international-en.utb",
"gr-gr-g1.utb": "el.ctb",
"he.ctb": "he-IL-comp8.utb",
"hr.ctb": "hr-comp8.utb",
"mn-MN.utb": "mn-MN-g1.utb",
"nl-BE-g0.utb": "nl-NL-g0.utb",
"nl-NL-g1.ctb": "nl-NL-g0.utb",
"no-no.ctb": "no-no-8dot.utb",
"no-no-comp8.ctb": "no-no-8dot.utb",
"ru-compbrl.ctb": "ru.ctb",
"ru-ru-g1.utb": "ru-litbrl-detailed.utb",
"Se-Se-g1.utb": "sv-g0.utb",
"sk-sk-g1.utb": "sk-g1.ctb",
"UEBC-g1.ctb": "en-ueb-g1.ctb",
"UEBC-g2.ctb": "en-ueb-g2.ctb",
"vi-g1.ctb": "vi-vn-g1.ctb",
}
# Add the builtin tables at import time.
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("afr-za-g1.ctb", _("Afrikaans grade 1"), inputForLangs={"af_ZA"}, outputForLangs={"af_ZA"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("afr-za-g2.ctb", _("Afrikaans grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("akk.utb", _("Akkadian (US) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("akk-borger.utb", _("Akkadian (Borger) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ar-ar-comp8.utb", _("Arabic 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ar-ar-g1.utb", _("Arabic grade 1"), inputForLangs={"ar"}, outputForLangs={"ar"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ar-ar-g2.ctb", _("Arabic grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("as-in-g1.utb", _("Assamese grade 1"), inputForLangs={"as"}, outputForLangs={"as"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ba.utb", _("Bashkir grade 1"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("be-in-g1.utb", _("Bengali grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("bel-comp.utb", _("Belarusian computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("bel.utb", _("Belarusian literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("bel-detailed.utb", _("Belarusian literary braille (detailed)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("bg.ctb", _("Bulgarian 8 dot computer braille"), inputForLangs={"bg"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("bg.utb", _("Bulgarian grade 1"), outputForLangs={"bg"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ca-g1.ctb", _("Catalan grade 1"), inputForLangs={"ca"}, outputForLangs={"ca"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ckb-g1.ctb", _("Central Kurdish grade 1"), inputForLangs={"ckb"}, outputForLangs={"ckb"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cop-eg-comp8.utb", _("Coptic 8 dot computer braille"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cuneiform-transliterated.utb", _("Cuneiform (transliterated) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cy-cy-g1.utb", _("Welsh grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cy-cy-g2.ctb", _("Welsh grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cs-comp8.utb", _("Czech 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("cs-g1.ctb", _("Czech grade 1"), inputForLangs={"cs"}, outputForLangs={"cs"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g08.ctb", _("Danish 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g08_1993.ctb", _("Danish 8 dot computer braille (1993)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g16.ctb", _("Danish 6 dot grade 1"), inputForLangs={"da"}, outputForLangs={"da"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g16_1993.ctb", _("Danish 6 dot grade 1 (1993)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g18.ctb", _("Danish 8 dot grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g18_1993.ctb", _("Danish 8 dot grade 1 (1993)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g26.ctb", _("Danish 6 dot grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g26_1993.ctb", _("Danish 6 dot grade 2 (1993)"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g28.ctb", _("Danish 8 dot grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("da-dk-g28_1993.ctb", _("Danish 8 dot grade 2 (1993)"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-comp6.utb", _("German 6 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-de-comp8.ctb", _("German 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g0.utb", _("German grade 0"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g0-detailed.utb", _("German grade 0 (detailed)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g1.ctb", _("German grade 1"), input=False, outputForLangs={"de"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g1-detailed.ctb", _("German grade 1 (detailed)"), inputForLangs={"de"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g2.ctb", _("German grade 2"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("de-g2-detailed.ctb", _("German grade 2 (detailed)"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("el.ctb", _("Greek (Greece)"), inputForLangs={"el"}, outputForLangs={"el"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-gb-comp8.ctb", _("English (U.K.) 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-gb-g1.utb", _("English (U.K.) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-GB-g2.ctb", _("English (U.K.) grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-nabcc.utb", _("English North American Braille Computer Code"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-ueb-g1.ctb", _("Unified English Braille Code grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-ueb-g2.ctb", _("Unified English Braille Code grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-us-comp6.ctb", _("English (U.S.) 6 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-us-comp8-ext.utb", _("English (U.S.) 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-us-g1.ctb", _("English (U.S.) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("en-us-g2.ctb", _("English (U.S.) grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("eo-g1.ctb", _("Esperanto grade 1"))
addTable(
"Es-Es-G0.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Spanish 8 dot computer braille"),
inputForLangs={"es", "gl"},
outputForLangs={"es", "gl"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("es-g1.ctb", _("Spanish grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("es-g2.ctb", _("Spanish grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("et-g0.utb", _("Estonian grade 0"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ethio-g1.ctb", _("Ethiopic grade 1"), inputForLangs={"am"}, outputForLangs={"am"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fa-ir-comp8.ctb", _("Persian 8 dot computer braille"), inputForLangs={"fa"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fa-ir-g1.utb", _("Persian grade 1"), outputForLangs={"fa"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fi.utb", _("Finnish 6 dot"))
addTable(
"fi-fi-8dot.ctb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Finnish 8 dot computer braille"),
inputForLangs={"fi"},
outputForLangs={"fi"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fil-g2.ctb", _("Filipino grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fr-bfu-comp6.utb", _("French (unified) 6 dot computer braille"))
addTable(
"fr-bfu-comp8.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("French (unified) 8 dot computer braille"),
inputForLangs={"fr"},
outputForLangs={"fr"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("fr-bfu-g2.ctb", _("French (unified) grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ga-g1.utb", _("Irish grade 1"), inputForLangs={"ga"}, outputForLangs={"ga"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ga-g2.ctb", _("Irish grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("gu-in-g1.utb", _("Gujarati grade 1"), inputForLangs={"gu"}, outputForLangs={"gu"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("grc-international-en.utb", _("Greek international braille (2-cell accented letters)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("grc-international-en-composed.utb", _("Greek international braille (single-cell accented letters)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("grc-international-es.utb", _("Spanish for Greek text"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hbo.utb", _("Hebrew (Biblical) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("he-IL.utb", _("Israeli grade 1"))
addTable(
"he-IL-comp8.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Hebrew computer braille"),
inputForLangs={"he"},
outputForLangs={"he"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hi-in-g1.utb", _("Hindi grade 1"), inputForLangs={"hi"}, outputForLangs={"hi"})
addTable(
"hr-comp8.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Croatian 8 dot computer braille"),
inputForLangs={"hr"},
outputForLangs={"hr"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hr-g1.ctb", _("Croatian grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hu-hu-comp8.ctb", _("Hungarian 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hu-hu-g1.ctb", _("Hungarian grade 1"), inputForLangs={"hu"}, outputForLangs={"hu"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("hu-hu-g2.ctb", _("Hungarian grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("is.ctb", _("Icelandic 8 dot computer braille"), inputForLangs={"is"}, outputForLangs={"is"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("IPA.utb", _("International Phonetic Alphabet"), input=False)
addTable(
"it-it-comp6.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Italian 6 dot computer braille"),
inputForLangs={"it"},
outputForLangs={"it"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("it-it-comp8.utb", _("Italian 8 dot computer braille"))
addTable(
"ja-kantenji.utb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Japanese (Kantenji) literary braille"),
input=False,
outputForLangs={"ja"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ka-in-g1.utb", _("Kannada grade 1"), inputForLangs={"kn"}, outputForLangs={"kn"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ka.utb", _("Georgian literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("kk.utb", _("Kazakh grade 1"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("km-g1.utb", _("Khmer grade 1"), inputForLangs={"km"}, outputForLangs={"km"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("kmr.tbl", _("Northern Kurdish grade 0"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ko-2006-g1.ctb", _("Korean grade 1 (2006)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ko-2006-g2.ctb", _("Korean grade 2 (2006)"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ko-g1.ctb", _("Korean grade 1"), inputForLangs={"ko"}, outputForLangs={"ko"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ko-g2.ctb", _("Korean grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ks-in-g1.utb", _("Kashmiri grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("lo-g1.utb", _("Lao Grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("lg-ug-g1.utb", _("Luganda literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("lt.ctb", _("Lithuanian 8 dot"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("lt-6dot.utb", _("Lithuanian 6 dot"), inputForLangs={"lt"}, outputForLangs={"lt"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("Lv-Lv-g1.utb", _("Latvian grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ml-in-g1.utb", _("Malayalam grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("mn-in-g1.utb", _("Manipuri grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ms-my-g2.ctb", _("Malay grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("mn-MN-g1.utb", _("Mongolian grade 1"), inputForLangs={"mn"}, outputForLangs={"mn"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("mn-MN-g2.ctb", _("Mongolian grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("mr-in-g1.utb", _("Marathi grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("my-g1.utb", _("Burmese grade 1"), inputForLangs={"my"}, outputForLangs={"my"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("my-g2.ctb", _("Burmese grade 2"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("nl-NL-g0.utb", _("Dutch 6 dot"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("nl-comp8.utb", _("Dutch 8 dot"), inputForLangs={"nl"}, outputForLangs={"nl"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("no-no-8dot.utb", _("Norwegian 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("No-No-g0.utb", _("Norwegian grade 0"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("No-No-g1.ctb", _("Norwegian grade 1"), inputForLangs={"nb_NO"}, outputForLangs={"nb_NO"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("No-No-g2.ctb", _("Norwegian grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("No-No-g3.ctb", _("Norwegian grade 3"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("np-in-g1.utb", _("Nepali grade 1"), inputForLangs={"ne"}, outputForLangs={"ne"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("nso-za-g1.utb", _("Sepedi grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("nso-za-g2.ctb", _("Sepedi grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ny-mw.utb", _("Chichewa (Malawi) literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("or-in-g1.utb", _("Oriya grade 1"))
addTable(
"pl-pl-comp8.ctb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
_("Polish 8 dot computer braille"),
inputForLangs={"pl"},
outputForLangs={"pl"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("Pl-Pl-g1.utb", _("Polish literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("pt-pt-comp8.ctb", _("Portuguese 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("Pt-Pt-g1.utb", _("Portuguese grade 1"), inputForLangs={"pt"}, outputForLangs={"pt"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("Pt-Pt-g2.ctb", _("Portuguese grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("pu-in-g1.utb", _("Punjabi grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ro-g0.utb", _("Romanian 6 dot"), inputForLangs={"ro"}, outputForLangs={"ro"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ro.ctb", _("Romanian"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ru.ctb", _("Russian computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ru-litbrl.ctb", _("Russian literary braille"), inputForLangs={"ru"}, outputForLangs={"ru"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ru-litbrl-detailed.utb", _("Russian literary braille (detailed)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ru-ru-g1.ctb", _("Russian contracted braille"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("rw-rw-g1.utb", _("Kinyarwanda literary braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sa-in-g1.utb", _("Sanskrit grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sah.utb", _("Yakut grade 1"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("Se-Se.ctb", _("Swedish 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sk-g1.ctb", _("Slovak grade 1"), inputForLangs={"sk"}, outputForLangs={"sk"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sl-si-comp8.ctb", _("Slovenian 8 dot computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sl-si-g1.utb", _("Slovenian grade 1"), inputForLangs={"sl"}, outputForLangs={"sl"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sot-za-g1.ctb", _("Sesotho grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sot-za-g2.ctb", _("Sesotho grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sr-g1.ctb", _("Serbian grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sr-Cyrl.ctb", _("Serbian Cyrillic grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sv-g0.utb", _("Swedish uncontracted braille"), input=False, outputForLangs={"sv"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sv-g1.ctb", _("Swedish partially contracted braille"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sv-g2.ctb", _("Swedish contracted braille"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g1.utb", _("Swahili (Kenya) grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g1-2.ctb", _("Swahili (Kenya) grade 1.2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g1-3.ctb", _("Swahili (Kenya) grade 1.3"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g1-4.ctb", _("Swahili (Kenya) grade 1.4"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g1-5.ctb", _("Swahili (Kenya) grade 1.5"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("sw-ke-g2.ctb", _("Swahili (Kenya) Grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("syc.utb", _("Syriac grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ta-ta-g1.ctb", _("Tamil grade 1"), inputForLangs={"ta"}, outputForLangs={"ta"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("tt.utb", _("Tatar grade 1"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("te-in-g1.utb", _("Telugu grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("th-comp8-backward.utb", _("Thai 8 dot computer braille"), output=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("th-g0.utb", _("Thai grade 0"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("th-g1.utb", _("Thai grade 1"), input=False, contracted=True, outputForLangs={"th"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("tr.ctb", _("Turkish grade 1"), inputForLangs={"tr"}, outputForLangs={"tr"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("tr-g2.ctb", _("Turkish grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("tsn-za-g1.ctb", _("Setswana grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("tsn-za-g2.ctb", _("Setswana grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("uga.utb", _("Ugaritic grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("uk.utb", _("Ukrainian grade 1"), inputForLangs={"uk"}, outputForLangs={"uk"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("uk-detailed.utb", _("Ukrainian literary braille (detailed)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("uk-comp.utb", _("Ukrainian computer braille"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ur-pk-g1.utb", _("Urdu grade 1"), inputForLangs={"ur"}, outputForLangs={"ur"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ur-pk-g2.ctb", _("Urdu grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("uz-g1.utb", _("Uzbek grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("unicode-braille.utb", _("Unicode braille"), output=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("vi-vn-g0.utb", _("Vietnamese grade 0"), inputForLangs={"vi"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ve-za-g1.utb", _("Tshivenda grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("ve-za-g2.ctb", _("Tshivenda grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("vi-vn-g1.ctb", _("Vietnamese grade 1"), input=False, outputForLangs={"vi"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("vi-vn-g2.ctb", _("Vietnamese grade 2"), contracted=True, input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("vi-saigon-g1.ctb", _("Southern Vietnamese grade 1"), input=False)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("xh-za-g1.utb", _("Xhosa grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("xh-za-g2.ctb", _("Xhosa grade 2"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("yi.utb", _("Yiddish grade 1"))
addTable(
"zhcn-cbs.ctb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
# This should be translated to '中文中国汉语通用盲文' in Mandarin.
_("Chinese common braille (simplified Chinese characters)"),
input=False,
outputForLangs={"zh_CN"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
# This should be translated to '中文中国汉语现行盲文(无声调)' in Mandarin.
addTable("zh-chn.ctb", _("Chinese (China, Mandarin) Current Braille System (no tones)"))
addTable(
"zhcn-g1.ctb",
# Translators: The name of a braille table displayed in the
# braille settings dialog.
# This should be translated to '中文中国汉语现行盲文' in Mandarin.
_("Chinese (China, Mandarin) Current Braille System"),
inputForLangs={"zh_HK"},
outputForLangs={"zh_HK"},
)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
# This should be translated to '中文中国汉语双拼盲文' in Mandarin.
addTable("zhcn-g2.ctb", _("Chinese (China, Mandarin) Double-phonic Braille System"), contracted=True)
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("zh-hk.ctb", _("Chinese (Hong Kong, Cantonese)"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("zh-tw.ctb", _("Chinese (Taiwan, Mandarin)"), inputForLangs={"zh_TW"}, outputForLangs={"zh_TW"})
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("zu-za-g1.utb", _("Zulu grade 1"))
# Translators: The name of a braille table displayed in the
# braille settings dialog.
addTable("zu-za-g2.ctb", _("Zulu grade 2"), contracted=True)
# Add new first maps for the custom tables - provided in the scratchpad directory
# and/or by addons.
_tables = _tables.new_child()
_tablesDirs = _tablesDirs.new_child()
def _loadTablesFromManifestSection(source: str, directory: str, tablesDict: dict):
for fileName, tableConfig in tablesDict.items():
addTable(
fileName=fileName,
displayName=tableConfig["displayName"],
contracted=tableConfig["contracted"],
input=tableConfig["input"],
output=tableConfig["output"],
source=source,
)
def initialize():
# The builtin tables were added at import time to the parent map.
# Now, add the custom tables to the first map.
import addonHandler
for addon in addonHandler.getRunningAddons():
try:
tablesDict = addon.manifest.get("brailleTables")
if not tablesDict:
continue
log.debug(f"Found {len(tablesDict)} braille table entries in manifest for add-on {addon.name!r}")
directory = os.path.join(addon.path, "brailleTables")
if os.path.isdir(directory):
_tablesDirs[addon.name] = directory
_loadTablesFromManifestSection(addon.name, directory, tablesDict)
except Exception:
log.exception(f"Error while applying custom braille tables config from addon {addon.name!r}")
# Load the custom tables from the scratchpad last so it takes precedence over add-ons
if not globalVars.appArgs.secure and config.conf["development"]["enableScratchpadDir"]:
scratchpad = config.getScratchpadDir()
directory = os.path.join(scratchpad, "brailleTables")
if os.path.isdir(directory):
manifestPath = os.path.join(scratchpad, addonHandler.MANIFEST_FILENAME)
if not os.path.isfile(manifestPath):
return
_tablesDirs[TableSource.SCRATCHPAD] = directory
configspec = {"brailleTables": addonHandler.AddonManifest.configspec["brailleTables"]}
try:
with open(manifestPath, "rb") as file:
manifest = ConfigObj(file, configspec=configspec)
section = manifest.get("brailleTables")
if not section:
return
if (res := manifest.validate(Validator(), preserve_errors=True)) is not True:
raise ValueError(f"Errors in scratchpad manifest: {flatten_errors(manifest, res)}")
log.debug(f"Found {len(tablesDict)} braille table entries in manifest for scratchpad")
_loadTablesFromManifestSection(TableSource.SCRATCHPAD, directory, section)
except Exception:
log.exception(
"Error while applying custom braille tables config from scratchpad manifest: "
f"{manifestPath}",
)
if config.conf["braille"]["translationTable"] == "auto":
config.conf["braille"]["translationTable"] = getDefaultTableForCurLang(TableType.OUTPUT)
def terminate():
# Clear all the custom tables, preserving only the builtin ones.
_tablesDirs.clear()
_tables.clear()