Skip to content

Commit d398092

Browse files
authored
Merge e59f56a into b79276c
2 parents b79276c + e59f56a commit d398092

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

devDocs/developerGuide.t2t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Subsequent lines contain a textual identifier used to identify the symbol, a tab
7272
For example:
7373
```
7474
. sentence ending (?<=[^\s.])\.(?=[\"')\s]|$)
75+
dates . \b(\d\d)\.(\d\d)\.(\d{2}|\d{4})\b
7576
```
7677

7778
Again, the English symbols are inherited by all other locales, so you need not include any complex symbols already defined for English.
@@ -98,6 +99,8 @@ Certain characters cannot be typed into the file, so the following special seque
9899
- \f: form feed
99100
- \#: # character (needed because # at the start of a line denotes a comment)
100101
- replacement: The text which should be spoken for the symbol.
102+
If the symbol is a complex symbol, \1, \2, etc. can be used to refer to the groups matches, which will be inlined in the replacement, allowing for simpler rules.
103+
This also means that to get a \ character in the replacement, one has to type \\.
101104
- level: The symbol level at which the symbol should be spoken.
102105
The symbol level is configured by the user and specifies the amount of symbols that should be spoken.
103106
This field should contain one of the levels "none", "some", "most", "all" or "char", or "-" to use the default.
@@ -133,6 +136,13 @@ It means that the ". sentence ending" complex symbol should be spoken as "point"
133136
Level and preserve are not specified, so they will be taken from English.
134137
A display name is provided so that French users will know what the symbol represents.
135138

139+
```
140+
dates . \1 \2 \3 all always # point de date
141+
```
142+
This line appears in the French symbols.dic file.
143+
It means that the first, second, and third groups of the match will be included, separated by spaces.
144+
The effect is thus to remove the dots from the date.
145+
136146
Please see the file locale\en\symbols.dic for the English definitions which are inherited for all locales.
137147
This is also a good full example.
138148

source/characterProcessing.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,34 @@ def _regexpRepl(self, m):
540540
if group == "simple":
541541
# Simple symbol.
542542
symbol = self.computedSymbols[text]
543+
replacement = symbol.replacement
543544
else:
544545
# Complex symbol.
545546
index = int(group[1:])
546547
symbol = self._computedComplexSymbolsList[index]
548+
replacement = ''
549+
550+
escape = False
551+
for c in symbol.replacement:
552+
if not escape:
553+
if c == '\\':
554+
escape = True
555+
else:
556+
replacement += c
557+
else:
558+
if c == '\\':
559+
replacement += '\\'
560+
elif c >= '0' and c <= '9':
561+
replacement += m.group(m.lastindex + ord(c) - ord('0'))
562+
else:
563+
log.error("Invalid reference \\%s" % c)
564+
escape = False
565+
547566
if symbol.preserve == SYMPRES_ALWAYS or (symbol.preserve == SYMPRES_NOREP and self._level < symbol.level):
548567
suffix = text
549568
else:
550569
suffix = " "
551-
if self._level >= symbol.level and symbol.replacement:
570+
if self._level >= symbol.level and replacement:
552571
return u" {repl}{suffix}".format(repl=symbol.replacement, suffix=suffix)
553572
else:
554573
return suffix
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#tests/unit/test_characterProcessing.py
2+
#A part of NonVisual Desktop Access (NVDA)
3+
#This file is covered by the GNU General Public License.
4+
#See the file COPYING for more details.
5+
#Copyright (C) 2020 NV Access Limited
6+
7+
"""Unit tests for the characterProcessing module.
8+
"""
9+
10+
import unittest
11+
from characterProcessing import SYMLVL_ALL
12+
import characterProcessing.processSpeechSymbols as process
13+
14+
class TestBasic(unittest.TestCase):
15+
16+
# TODO: check that complex symbols work, check that levels work, check
17+
# that fallback to english works
18+
19+
def test_FR(self):
20+
"""Test some French replacements"""
21+
self.assertEqual(process("fr_FR", "-", SYMLVL_ALL), "tiret")

0 commit comments

Comments
 (0)