Hello Everyone,
This is a Python program. It works nicely on Linux. On Windows it has trouble
importing the liblouis Python bindikngs.
I've pasted it into this message above my signature. It indents paragraphs, it
works
very well with text files derived from pdfs.
Note that the program handles plain text only. It is possible to add handling
of other formats, but I think it is better to convert them separately.
The program also makes greater use of object-oriented programming. If you share
it please do not delete the docstring at the beginning. It explains what the
program does and how to use it. It is part of the program.
""" This program, lou_transtext.py, takes a plain text input file, translates
it with liblouis according to the tablelist variable
and formats it with a line length given in the lineLength variable.
Paragraphs are shown by an indentation of two blank spaces.
If the file you wish to translate is not in plain text you must convert it with
a conversion program.
This program asks for the names of the input file and the output file.
As provided, tableList is ["en-ueb-g2.ctb] Note that it is a Python list.
lineLength is currently set to 38. You can set tableList and lineLength
according to your preferences.
"""
tableList = ["en-ueb-g2.ctb"]
lineLength = 38
import louis
from re import match
import textwrap
fileIn = input ("Please enter the input file name: ")
fileOut = input ("Please enter the output file name: ")
inputFile = open (fileIn, "rt")
outputFile = open (fileOut, "wt", newline='\r\n')
p = [' '] # p is for paragraph
prevBlank = True #blank line
while True:
line = inputFile.readline()
if line == "":
break
line2 = line.strip()
if line2 == "":
prevBlank = True
continue
if not (match('[a-z]', line2) == None and prevBlank):
prevblank = False
p.append(line2)
continue
else:
line = ' '.join(p)
translation = louis.translateString (tableList, line, 0, 0)
outputFile.write (textwrap.fill (translation, lineLength))
outputFile.write("\n")
p = [' ']
p.append(line2)
prevBlank = False
inputFile.close()
outputFile.close()
print ("Done.")
--
John J. Boyer
Email: john.boyer@xxxxxxxxxxxxxxxxx
website: http://www.abilitiessoft.org
Status: Company dissolved but website and email addresses live.
Location: Madison, Wisconsin, USA
Mission: developing assistive technology software and providing STEM services
that are available at no cost
For a description of the software, to download it and links to
project pages go to http://liblouis.org
Donate: http://liblouis.org/sponsoring