Skip to content

Commit e5f8538

Browse files
authored
Merge bf172d1 into dc6ae59
2 parents dc6ae59 + bf172d1 commit e5f8538

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

source/characterProcessing.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,16 @@ def _saveSymbol(self, symbol):
373373
return u"\t".join(fields)
374374

375375
_noSymbolLocalesCache = set()
376+
_noCLDRLocalesCache = set()
376377

377378

378379
def _getSpeechSymbolsForLocale(locale: str) -> Tuple[SpeechSymbols, SpeechSymbols]:
379-
if locale in _noSymbolLocalesCache:
380+
if (
381+
locale in _noSymbolLocalesCache
382+
and (locale in _noCLDRLocalesCache or not config.conf['speech']['includeCLDR'])
383+
):
380384
raise LookupError
385+
builtinDataImported = False
381386
builtin = SpeechSymbols()
382387
if config.conf['speech']['includeCLDR']:
383388
# Try to load CLDR data when processing is on.
@@ -388,12 +393,17 @@ def _getSpeechSymbolsForLocale(locale: str) -> Tuple[SpeechSymbols, SpeechSymbol
388393
os.path.join(globalVars.appDir, "locale", locale, "cldr.dic"),
389394
allowComplexSymbols=False
390395
)
396+
builtinDataImported = True
391397
except IOError:
398+
_noCLDRLocalesCache.add(locale)
392399
log.debugWarning("No CLDR data for locale %s" % locale)
393400
try:
394401
builtin.load(os.path.join(globalVars.appDir, "locale", locale, "symbols.dic"))
402+
builtinDataImported = True
395403
except IOError:
396404
_noSymbolLocalesCache.add(locale)
405+
log.debugWarning("No symbol data for locale %s" % locale)
406+
if not builtinDataImported:
397407
raise LookupError("No symbol information for locale %s" % locale)
398408
user = SpeechSymbols()
399409
try:

tests/unit/test_characterProcessing.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2020 NV Access Limited
4+
# Copyright (C) 2020-2022 NV Access Limited, Cyrille Bougot
55

66
"""Unit tests for the characterProcessing module.
77
"""
@@ -11,6 +11,7 @@
1111
from characterProcessing import SpeechSymbolProcessor
1212
from characterProcessing import SymbolLevel
1313
from characterProcessing import processSpeechSymbols as process
14+
from characterProcessing import processSpeechSymbol
1415

1516

1617
class TestComplex(unittest.TestCase):
@@ -128,3 +129,56 @@ def test_engine(self):
128129
self.assertEqual(replaced, "Le 03 point 04 point 05 point.")
129130
replaced = process("fr_FR", "Le 03/04/05.", SymbolLevel.ALL)
130131
self.assertEqual(replaced, "Le 03 barre oblique 04 barre oblique 05 point.")
132+
133+
134+
# A character in CLDR file but not in symbol file
135+
CHAR_IN_CLDR_FILE = '☺'
136+
CHAR_IN_CLDR_FILE_DESC = 'smiling face'
137+
# A character in symbol file but not in CLDR file
138+
CHAR_IN_SYMB_FILE = ' '
139+
CHAR_IN_SYMB_FILE_DESC = 'space'
140+
# A character in both CLDR and symbol file
141+
CHAR_IN_BOTH_FILES = '.'
142+
CHAR_IN_BOTH_FILES_DESC = 'dot'
143+
144+
145+
class TestUsingCLDR(unittest.TestCase):
146+
147+
def test_processSpeechSymbol_withoutSymbolFile(self):
148+
"""Test processSpeechSymbol with languages that have CLDR file but no symbol file.
149+
"""
150+
151+
languagesWithoutSymbolFile = [
152+
# The real list is:
153+
# 'af_ZA', 'am', 'as', 'gu', 'id', 'kok', 'ml', 'mni', 'ne', 'te', 'th', 'ur'
154+
# But 'mni' has only a few symbols in CLDR (and not the smiling face)
155+
'af_ZA', 'am', 'as', 'gu', 'id', 'kok', 'ml', 'ne', 'te', 'th', 'ur'
156+
]
157+
for locale in languagesWithoutSymbolFile:
158+
self.assertNotEqual(
159+
processSpeechSymbol(locale, CHAR_IN_CLDR_FILE),
160+
CHAR_IN_CLDR_FILE_DESC,
161+
msg=f'Test failure for locale={locale} with "{CHAR_IN_CLDR_FILE_DESC}"',
162+
)
163+
self.assertEqual(
164+
processSpeechSymbol(locale, CHAR_IN_SYMB_FILE),
165+
CHAR_IN_SYMB_FILE_DESC,
166+
msg=f'Test failure for locale={locale} with "{CHAR_IN_SYMB_FILE_DESC}"',
167+
)
168+
169+
def test_processSpeechSymbol_withSymbolFile(self):
170+
"""Test processSpeechSymbol with languages that have both CLDR and symbol file.
171+
"""
172+
173+
languagesWithSymbolFileAndCLDR = ['fr_FR']
174+
for locale in languagesWithSymbolFileAndCLDR:
175+
self.assertNotEqual(
176+
processSpeechSymbol(locale, CHAR_IN_CLDR_FILE),
177+
CHAR_IN_CLDR_FILE_DESC,
178+
msg=f'Test failure for locale={locale} with "{CHAR_IN_CLDR_FILE_DESC}"',
179+
)
180+
self.assertNotEqual(
181+
processSpeechSymbol(locale, CHAR_IN_SYMB_FILE),
182+
CHAR_IN_SYMB_FILE_DESC,
183+
msg=f'Test failure for locale={locale} with "{CHAR_IN_SYMB_FILE_DESC}"',
184+
)

user_docs/en/changes.t2t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ What's New in NVDA
4545
- In some rare cases, these settings used in profiles may be unexpectedly modified when installing this version of NVDA.
4646
- Please check these options in your profiles after upgrading NVDA to this version.
4747
-
48+
- Emojis should now be reported in more languages. (#14433)
4849
- The presence of an annotation is no longer missing in braille for some elements. (#13815)
4950
-
5051

0 commit comments

Comments
 (0)