-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmxConverter.sh
38 lines (36 loc) · 1.39 KB
/
tmxConverter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# this script converts a tab delimited text file into a tmx file.
#
inputTxtFile=$1; #argument: tab-delimited text file
outputTmxFile="${1//'.txt'/''}.tmx"
if [[ $# -eq 1 ]]; then
read -n 2 -p $'Enter source language (2 characters): ' sourceLang
read -n 2 -p $'\nEnter target language (2 characters): ' targetLang
echo $'\n\nsource: '$sourceLang''
echo $'target: '$targetLang''
echo $'A rerun would overwrite the existing file'
echo '<tmx version="1">
<header
creationtool="TMX_Linux_Bash" creationtoolversion="1"
datatype="PlainText" segtype="sentence"
adminlang="de" srclang="'$sourceLang'"/>
<body>' > $outputTmxFile
while IFS= read -r line; do
echo ' <tu>
<tuv xml:lang="'$sourceLang'"> ' >> $outputTmxFile
line=${line//'<'/'<'}
line=${line//'>'/'>'}
source=$(echo "$line" | cut -d $'\t' -f 1)
target=$(echo "$line" | cut -d $'\t' -f 2)
echo " <seg>$source</seg>" >> $outputTmxFile
echo ' </tuv>' >> $outputTmxFile
echo ' <tuv xml:lang="'$targetLang'">' >> $outputTmxFile
echo " <seg>$target</seg>" >> $outputTmxFile
echo ' </tuv>' >> $outputTmxFile
echo ' </tu>' >> $outputTmxFile
done < $1
echo ' </body>' >> $outputTmxFile
echo '</tmx>' >> $outputTmxFile
else
echo "Correct Usage: 'tmx tab-delimited-text.txt'"
fi