Repository: nvaccess/nvda

Issue:
Braille/Liblouis 3: provide a way to detect and change table names if old tables are no longer included
Hi,
Part of #6109:

As noted in the following LibLouis issue:
https://github.com/liblouis/liblouis/issues/182

There might be instances where NVDA's own tables tuple may refer to deleted tables. If this happens, the following may result:
1. Braille Settings: no table seems to be selected. This is a minor thing (for about 99 percent of tables, table names are the same).
2. Runtime translation issues are noted due to the fact that some tables rely on other tables.

Thus it would be handy to provide the following migration strategy:
1. Add config checker in braille.initialize that reads in config.conf["braille"]["*Table"] key.
2. Based on the name of the file it read, look up a dictionary which tells NVDA the new filename for the given table.
3. Replace the old name with the new name.

Potential problems:
- What if no replacements are provided? In this case, tell users to specify the new table from braille settings.
- Do we know which tables are gone or renamed? We need to wait until LibLouis 3 beta comes out before proceeding.

The needed change(s) will be committed as part of #6109 branch (#6110 for PR). Comments are appreciated. Thanks.



Discussion:

Resolving patch:
diff --git a/source/braille.py b/source/braille.py
--- a/source/braille.py
+++ b/source/braille.py
@@ -2,7 +2,7 @@
 #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-2016 NV Access Limited
+#Copyright (C) 2008-2016 NV Access Limited, Joseph Lee
 
 import sys
 import itertools
@@ -55,10 +55,10 @@
 	("cz-cz-g1.utb", _("Czech grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("da-dk-g16.utb", _("Danish 6 dot grade 1"), False),
+	("da-dk-g16.ctb", _("Danish 6 dot grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("da-dk-g18.utb", _("Danish 8 dot grade 1"), False),
+	("da-dk-g18.ctb", _("Danish 8 dot grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
 	("da-dk-g26.ctb", _("Danish 6 dot grade 2"), False),
@@ -205,13 +205,13 @@
 	("mr-in-g1.utb", _("Marathi grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("nl-BE-g1.ctb", _("Dutch (Belgium) grade 1"), False),
+	("nl-BE-g0.utb", _("Dutch (Belgium)"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("nl-NL-g1.ctb", _("Dutch (Netherlands) grade 1"), False),
+	("nl-NL-g0.utb", _("Dutch (Netherlands)"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("no-no.ctb", _("Norwegian 8 dot computer braille"), True),
+	("no-no-comp8.ctb", _("Norwegian 8 dot computer braille"), True),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
 	("No-No-g0.utb", _("Norwegian grade 0"), False),
@@ -262,7 +262,7 @@
 	("Se-Se-g1.utb", _("Swedish grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("sk-sk-g1.utb", _("Slovak grade 1"), False),
+	("sk-g1.ctb", _("Slovak grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
 	("sl-si-g1.utb", _("Slovene grade 1"), False),
@@ -274,16 +274,16 @@
 	("ta-ta-g1.ctb", _("Tamil grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("te-in-g1.utb", _("Telegu grade 1"), False),
+	("te-in-g1.utb", _("Telugu grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
 	("tr.ctb", _("Turkish grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("UEBC-g1.utb", _("Unified English Braille Code grade 1"), False),
+	("en-ueb-g1.ctb", _("Unified English Braille Code grade 1"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
-	("UEBC-g2.ctb", _("Unified English Braille Code grade 2"), False),
+	("en-ueb-g2.ctb", _("Unified English Braille Code grade 2"), False),
 	# Translators: The name of a braille table displayed in the
 	# braille settings dialog.
 	("zh-hk.ctb", _("Chinese (Hong Kong, Cantonese)"), False),
@@ -295,6 +295,18 @@
 #: Braille tables that support input (only computer braille tables yet).
 INPUT_TABLES = tuple(t for t in TABLES if t[2])
 
+#: Maps old table names to new table names for tables renamed in newer versions of liblouis.
+RENAMED_TABLES = {
+	"da-dk-g16.utb":"da-dk-g16.ctb",
+	"da-dk-g18.utb":"da-dk-g18.ctb",
+	"nl-BE-g1.ctb":"nl-BE-g0.utb",
+	"nl-NL-g1.ctb":"nl-NL-g0.utb",
+	"no-no.ctb":"no-no-comp8.ctb",
+	"sk-sk-g1.utb":"sk-g1.ctb",
+	"UEBC-g1.ctb":"en-ueb-g1.ctb",
+	"UEBC-g2.ctb":"en-ueb-g2.ctb",
+}
+
 roleLabels = {
 	# Translators: Displayed in braille for an object which is an
 	# editable text field.
@@ -1764,6 +1776,11 @@ def initialize():
 	global handler
 	config.addConfigDirsToPythonPackagePath(brailleDisplayDrivers)
 	log.info("Using liblouis version %s" % louis.version())
+	# #6140: Migrate to new table names as smoothly as possible.
+	oldTableName = config.conf["braille"]["translationTable"]
+	newTableName = RENAMED_TABLES.get(oldTableName)
+	if newTableName:
+		config.conf["braille"]["translationTable"] = newTableName
 	handler = BrailleHandler()
 	handler.setDisplayByName(config.conf["braille"]["display"])
 


Test patch: