August 1, 2011

Quick and Dirty Plain text to ttx file generator.

I had the requirement for some tests to turn a big plain text file into a “more or less” formatted correctly ttx file.

Now, this is by no means something that you would want to open in Trados to start editing with etc, but it does surround the lines with Trados TTX tags in sufficient detail for me tests.

Get the script here:

Now I know, its messy, but I don’t care at the moment as it worked for me and saved me copying and pasting over 1400 tags to lines of text.

I also didn’t find anything online that would do this for me, hence me writing this. I’m not a programmer, and I know actually outputting XML using elementTree would be better, but it was more work to do that then I was willing to spend at the time.

This small piece of code would benefit from reading in language options from the user, and then slotting them into the tags and it would also benefit from a re-write to allow it to output XML correctly as at the moment it reads in the file stated, and outputs it wrapped.

Characters that are not valid XML still go through, for example if there is an & in the file, it will wrap that too, it doesn’t care. & isn’t valid XML amongst other characters and is commonly substituted with &

Call this script whatever you want, but I was calling it

So, what does it do?

Lets say you have a file with 3000 lines of text in it called mytesttext.txt, you would use this python script as follows:

python mytesttext.txt

this will then output it to screen for you to quickly check, then you can redirect the output to file like this to save it:

python mytesttext.txt > mytesttext.ttx

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.