From 4eb9d98f7e32f84178ae9d1a43d1cfe4f93d40b7 Mon Sep 17 00:00:00 2001 From: Ken Perry Date: Sun, 18 Oct 2026 19:45:21 -0400 Subject: [PATCH] Add Spanish grade 2 braille profile BrailleBlaster only offered Spanish as grade 1 (SPANISH-US). The new SPANISH-US-CONTRACTED profile uses liblouis's Spanish grade 2 table, es-g2.ctb, which is already bundled, for literary text and for text in math books. Uncontracted and computer braille stay grade 1, the same split the UEB profiles use. The Translation settings menu and the --braille-profile option both list the brailleSettings files, so the new file is all they need. SPANISH-US is unchanged and stays grade 1, so existing documents and scripts keep working. SpanishProfilesTest checks both profiles' tables, that grade 2 contracts "estado de cuenta" to "$d d cu5ta", and that --braille-profile SPANISH-US-CONTRACTED parses and finds its file. --- .../SPANISH-US-CONTRACTED.brailleSettings.xml | 12 +++ .../settings/SpanishProfilesTest.kt | 87 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 brailleblaster-core/src/main/dist/programData/utd/SPANISH-US-CONTRACTED.brailleSettings.xml create mode 100644 brailleblaster-core/src/test/java/org/brailleblaster/settings/SpanishProfilesTest.kt diff --git a/brailleblaster-core/src/main/dist/programData/utd/SPANISH-US-CONTRACTED.brailleSettings.xml b/brailleblaster-core/src/main/dist/programData/utd/SPANISH-US-CONTRACTED.brailleSettings.xml new file mode 100644 index 00000000..40a9f83b --- /dev/null +++ b/brailleblaster-core/src/main/dist/programData/utd/SPANISH-US-CONTRACTED.brailleSettings.xml @@ -0,0 +1,12 @@ + + + NLS + us-table.dis,es-g2.ctb + true + es-g1.ctb + us-table.dis,es-g1.ctb + us-table.dis,es-g2.ctb + us-table.dis,nemeth.ctb + us-table.dis,nemeth_edit.ctb + Nemeth + \ No newline at end of file diff --git a/brailleblaster-core/src/test/java/org/brailleblaster/settings/SpanishProfilesTest.kt b/brailleblaster-core/src/test/java/org/brailleblaster/settings/SpanishProfilesTest.kt new file mode 100644 index 00000000..598774fa --- /dev/null +++ b/brailleblaster-core/src/test/java/org/brailleblaster/settings/SpanishProfilesTest.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2026 American Printing House for the Blind + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package org.brailleblaster.settings + +import org.brailleblaster.BBIni +import org.brailleblaster.bbx.BookToBBXConverter +import org.brailleblaster.cli.BrfCommand +import org.brailleblaster.utd.BrailleSettings +import org.brailleblaster.utd.config.UTDConfig +import org.testng.Assert.assertEquals +import org.testng.Assert.assertNotEquals +import org.testng.annotations.BeforeClass +import org.testng.annotations.Test +import picocli.CommandLine + +/** + * Spanish comes as grade 1 (SPANISH-US) and grade 2 (SPANISH-US-CONTRACTED). + * Both appear in the Translation settings menu and work with --braille-profile, + * which find profiles from their brailleSettings files. + */ +class SpanishProfilesTest { + @BeforeClass + fun init() { + BookToBBXConverter.devSetup(arrayOf()) + } + + private fun profile(name: String): BrailleSettings = + UTDConfig.loadBrailleSettings(BBIni.loadAutoProgramDataFile(UTDManager.UTD_FOLDER, name + UTDManager.BRAILLE_SETTINGS_NAME)) + + // UTDManager points liblouis at BrailleBlaster's tables + private fun translate(settings: BrailleSettings, text: String): String = + UTDManager().engine.brailleTranslator.translateString(settings.mainTranslationTable, text, 0) + + @Test + fun gradeOneProfileIsUnchanged() { + val settings = profile("SPANISH-US") + + assertEquals(settings.mainTranslationTable, "us-table.dis,es-g1.ctb") + assertEquals(settings.uncontractedTable, "us-table.dis,es-g1.ctb") + } + + @Test + fun gradeTwoProfileUsesContractedTable() { + val settings = profile("SPANISH-US-CONTRACTED") + + assertEquals(settings.mainTranslationTable, "us-table.dis,es-g2.ctb") + assertEquals(settings.mathTextTable, "us-table.dis,es-g2.ctb") + // uncontracted and computer braille stay grade 1 + assertEquals(settings.uncontractedTable, "us-table.dis,es-g1.ctb") + assertEquals(settings.computerBrailleTable, "es-g1.ctb") + assertEquals(settings.isUseAsciiBraille, true) + } + + @Test + fun gradeTwoContracts() { + val text = "estado de cuenta" + val gradeOne = translate(profile("SPANISH-US"), text) + val gradeTwo = translate(profile("SPANISH-US-CONTRACTED"), text) + + assertEquals(gradeOne.lowercase(), "estado de cuenta") + assertNotEquals(gradeTwo, gradeOne, "Grade 2 should contract '$text'") + assertEquals(gradeTwo.lowercase(), "\$d d cu5ta") + } + + @Test + fun commandLineAcceptsGradeTwoProfile() { + val command = BrfCommand() + + CommandLine(command).parseArgs("input.docx", "output.brf", "--braille-profile", "SPANISH-US-CONTRACTED") + + assertEquals(command.brailleProfile, "SPANISH-US-CONTRACTED") + BBIni.loadAutoProgramDataFile(UTDManager.UTD_FOLDER, command.brailleProfile + UTDManager.BRAILLE_SETTINGS_NAME) + } +}