Created
December 29, 2015 02:17
-
-
Save cargabsj175/33f15af971b2ef4554a1 to your computer and use it in GitHub Desktop.
Transliteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Carlos Sanchez <cargabsj175 (at) gmail.com> | |
# Proyecto VegnuX 2007-2011 | |
# cirilyc to latin 0.1 GPL v3 | |
# cirilyc alphabet (russian) | |
c0="А" | |
c1="а" | |
c2="Б" | |
c3="б" | |
c4="В" | |
c5="в" | |
c6="Г" | |
c7="г" | |
c8="Д" | |
c9="д" | |
c10="Е" | |
c11="е" | |
c12="Ё" | |
c13="ё" | |
c14="Ж" | |
c15="ж" | |
c16="З" | |
c17="з" | |
c18="И" | |
c19="и" | |
c20="Й" | |
c21="й" | |
c22="К" | |
c23="к" | |
c24="Л" | |
c25="л" | |
c26="М" | |
c27="м" | |
c28="Н" | |
c29="н" | |
c30="О" | |
c31="о" | |
c32="П" | |
c33="п" | |
c34="Р" | |
c35="р" | |
c36="С" | |
c37="с" | |
c38="Т" | |
c39="т" | |
c40="У" | |
c41="у" | |
c42="Ф" | |
c43="ф" | |
c44="Х" | |
c45="х" | |
c46="Ц" | |
c47="ц" | |
c48="Ч" | |
c49="ч" | |
c50="Ш" | |
c51="ш" | |
c52="Щ" | |
c53="щ" | |
c54="Ы" | |
c55="ы" | |
c56="Э" | |
c57="э" | |
c58="Ю" | |
c59="ю" | |
c60="Я" | |
c61="я" | |
c62="Ь" | |
c63="ь" | |
c64="Ъ" | |
c65="ъ" | |
# latin alphabet (transliteration) | |
l0="A" | |
l1="a" | |
l2="B" | |
l3="b" | |
l4="V" | |
l5="v" | |
l6="G" | |
l7="g" | |
l8="D" | |
l9="d" | |
l10="E" | |
l11="e" | |
l12="Ë" | |
l13="ë" | |
l14="ZH" | |
l15="zh" | |
l16="Z" | |
l17="z" | |
l18="I" | |
l19="i" | |
l20="Ĭ" | |
l21="ĭ" | |
l22="K" | |
l23="k" | |
l24="L" | |
l25="l" | |
l26="M" | |
l27="m" | |
l28="N" | |
l29="n" | |
l30="O" | |
l31="o" | |
l32="P" | |
l33="p" | |
l34="R" | |
l35="r" | |
l36="S" | |
l37="s" | |
l38="T" | |
l39="t" | |
l40="U" | |
l41="u" | |
l42="F" | |
l43="f" | |
l44="J" | |
l45="j" | |
l46="TS" | |
l47="ts" | |
l48="CH" | |
l49="ch" | |
l50="SH" | |
l51="sh" | |
l52="SHCH" | |
l53="shch" | |
l54="Y" | |
l55="y" | |
l56="E" | |
l57="e" | |
l58="YU" | |
l59="yu" | |
l60="YA" | |
l61="ya" | |
l62="'" | |
l63="'" | |
l64="\"" | |
l65="\"" | |
cir2lat () { | |
sed -i "s#${c0}#${l0}#g" $fileout | |
sed -i "s#${c1}#${l1}#g" $fileout | |
sed -i "s#${c2}#${l2}#g" $fileout | |
sed -i "s#${c3}#${l3}#g" $fileout | |
sed -i "s#${c4}#${l4}#g" $fileout | |
sed -i "s#${c5}#${l5}#g" $fileout | |
sed -i "s#${c6}#${l6}#g" $fileout | |
sed -i "s#${c7}#${l7}#g" $fileout | |
sed -i "s#${c8}#${l8}#g" $fileout | |
sed -i "s#${c9}#${l9}#g" $fileout | |
sed -i "s#${c10}#${l10}#g" $fileout | |
sed -i "s#${c11}#${l11}#g" $fileout | |
sed -i "s#${c12}#${l12}#g" $fileout | |
sed -i "s#${c13}#${l13}#g" $fileout | |
sed -i "s#${c14}#${l14}#g" $fileout | |
sed -i "s#${c15}#${l15}#g" $fileout | |
sed -i "s#${c16}#${l16}#g" $fileout | |
sed -i "s#${c17}#${l17}#g" $fileout | |
sed -i "s#${c18}#${l18}#g" $fileout | |
sed -i "s#${c19}#${l19}#g" $fileout | |
sed -i "s#${c20}#${l20}#g" $fileout | |
sed -i "s#${c21}#${l21}#g" $fileout | |
sed -i "s#${c22}#${l22}#g" $fileout | |
sed -i "s#${c23}#${l23}#g" $fileout | |
sed -i "s#${c24}#${l24}#g" $fileout | |
sed -i "s#${c25}#${l25}#g" $fileout | |
sed -i "s#${c26}#${l26}#g" $fileout | |
sed -i "s#${c27}#${l27}#g" $fileout | |
sed -i "s#${c28}#${l28}#g" $fileout | |
sed -i "s#${c29}#${l29}#g" $fileout | |
sed -i "s#${c30}#${l30}#g" $fileout | |
sed -i "s#${c31}#${l31}#g" $fileout | |
sed -i "s#${c32}#${l32}#g" $fileout | |
sed -i "s#${c33}#${l33}#g" $fileout | |
sed -i "s#${c34}#${l34}#g" $fileout | |
sed -i "s#${c35}#${l35}#g" $fileout | |
sed -i "s#${c36}#${l36}#g" $fileout | |
sed -i "s#${c37}#${l37}#g" $fileout | |
sed -i "s#${c38}#${l38}#g" $fileout | |
sed -i "s#${c39}#${l39}#g" $fileout | |
sed -i "s#${c40}#${l40}#g" $fileout | |
sed -i "s#${c41}#${l41}#g" $fileout | |
sed -i "s#${c42}#${l42}#g" $fileout | |
sed -i "s#${c43}#${l43}#g" $fileout | |
sed -i "s#${c44}#${l44}#g" $fileout | |
sed -i "s#${c45}#${l45}#g" $fileout | |
sed -i "s#${c46}#${l46}#g" $fileout | |
sed -i "s#${c47}#${l47}#g" $fileout | |
sed -i "s#${c48}#${l48}#g" $fileout | |
sed -i "s#${c49}#${l49}#g" $fileout | |
sed -i "s#${c50}#${l50}#g" $fileout | |
sed -i "s#${c51}#${l51}#g" $fileout | |
sed -i "s#${c52}#${l52}#g" $fileout | |
sed -i "s#${c53}#${l53}#g" $fileout | |
sed -i "s#${c54}#${l54}#g" $fileout | |
sed -i "s#${c55}#${l55}#g" $fileout | |
sed -i "s#${c56}#${l56}#g" $fileout | |
sed -i "s#${c57}#${l57}#g" $fileout | |
sed -i "s#${c58}#${l58}#g" $fileout | |
sed -i "s#${c59}#${l59}#g" $fileout | |
sed -i "s#${c60}#${l60}#g" $fileout | |
sed -i "s#${c61}#${l61}#g" $fileout | |
sed -i "s#${c62}#${l62}#g" $fileout | |
sed -i "s#${c63}#${l63}#g" $fileout | |
sed -i "s#${c64}#${l64}#g" $fileout | |
sed -i "s#${c65}#${l65}#g" $fileout | |
} | |
lat2cir (){ | |
# Combinated latin characters | |
sed -i "s#${l52}#${c52}#g" $fileout | |
sed -i "s#${l53}#${c53}#g" $fileout | |
sed -i "s#${l14}#${c14}#g" $fileout | |
sed -i "s#${l15}#${c15}#g" $fileout | |
sed -i "s#${l46}#${c46}#g" $fileout | |
sed -i "s#${l47}#${c47}#g" $fileout | |
sed -i "s#${l48}#${c48}#g" $fileout | |
sed -i "s#${l49}#${c49}#g" $fileout | |
sed -i "s#${l50}#${c50}#g" $fileout | |
sed -i "s#${l51}#${c51}#g" $fileout | |
sed -i "s#${l58}#${c58}#g" $fileout | |
sed -i "s#${l59}#${c59}#g" $fileout | |
sed -i "s#${l60}#${c60}#g" $fileout | |
sed -i "s#${l61}#${c61}#g" $fileout | |
# As is | |
sed -i "s#${l0}#${c0}#g" $fileout | |
sed -i "s#${l1}#${c1}#g" $fileout | |
sed -i "s#${l2}#${c2}#g" $fileout | |
sed -i "s#${l3}#${c3}#g" $fileout | |
sed -i "s#${l4}#${c4}#g" $fileout | |
sed -i "s#${l5}#${c5}#g" $fileout | |
sed -i "s#${l6}#${c6}#g" $fileout | |
sed -i "s#${l7}#${c7}#g" $fileout | |
sed -i "s#${l8}#${c8}#g" $fileout | |
sed -i "s#${l9}#${c9}#g" $fileout | |
sed -i "s#${l10}#${c10}#g" $fileout | |
sed -i "s#${l11}#${c11}#g" $fileout | |
sed -i "s#${l12}#${c12}#g" $fileout | |
sed -i "s#${l13}#${c13}#g" $fileout | |
sed -i "s#${l16}#${c16}#g" $fileout | |
sed -i "s#${l17}#${c17}#g" $fileout | |
sed -i "s#${l18}#${c18}#g" $fileout | |
sed -i "s#${l19}#${c19}#g" $fileout | |
sed -i "s#${l20}#${c20}#g" $fileout | |
sed -i "s#${l21}#${c21}#g" $fileout | |
sed -i "s#${l22}#${c22}#g" $fileout | |
sed -i "s#${l23}#${c23}#g" $fileout | |
sed -i "s#${l24}#${c24}#g" $fileout | |
sed -i "s#${l25}#${c25}#g" $fileout | |
sed -i "s#${l26}#${c26}#g" $fileout | |
sed -i "s#${l27}#${c27}#g" $fileout | |
sed -i "s#${l28}#${c28}#g" $fileout | |
sed -i "s#${l29}#${c29}#g" $fileout | |
sed -i "s#${l30}#${c30}#g" $fileout | |
sed -i "s#${l31}#${c31}#g" $fileout | |
sed -i "s#${l32}#${c32}#g" $fileout | |
sed -i "s#${l33}#${c33}#g" $fileout | |
sed -i "s#${l34}#${c34}#g" $fileout | |
sed -i "s#${l35}#${c35}#g" $fileout | |
sed -i "s#${l36}#${c36}#g" $fileout | |
sed -i "s#${l37}#${c37}#g" $fileout | |
sed -i "s#${l38}#${c38}#g" $fileout | |
sed -i "s#${l39}#${c39}#g" $fileout | |
sed -i "s#${l40}#${c40}#g" $fileout | |
sed -i "s#${l41}#${c41}#g" $fileout | |
sed -i "s#${l42}#${c42}#g" $fileout | |
sed -i "s#${l43}#${c43}#g" $fileout | |
sed -i "s#${l44}#${c44}#g" $fileout | |
sed -i "s#${l45}#${c45}#g" $fileout | |
sed -i "s#${l54}#${c54}#g" $fileout | |
sed -i "s#${l55}#${c55}#g" $fileout | |
sed -i "s#${l56}#${c56}#g" $fileout | |
sed -i "s#${l57}#${c57}#g" $fileout | |
sed -i "s#${l62}#${c62}#g" $fileout | |
sed -i "s#${l63}#${c63}#g" $fileout | |
sed -i "s#${l64}#${c64}#g" $fileout | |
sed -i "s#${l65}#${c65}#g" $fileout | |
#misc | |
sed -i "s#C#${c22}#g" $fileout | |
sed -i "s#c#${c23}#g" $fileout | |
} | |
function help(){ | |
echo "cirilyc2latin 0.1 - Proyecto VegnuX 2007-2011 (GPLv3)" | |
echo "" | |
echo "Uso: cirilyc2latin [ARGUMENTO] [Archivo de texto plano] ..." | |
echo "" | |
echo "-h, --help: Muestra esta información." | |
echo "-c, --to-cirilyc: Translitera el texto en ruso al alfabeto latino." | |
echo "-l, --to-latin: Revierte el texto a ruso desde uno transliterado." | |
echo "" | |
} | |
html (){ | |
RuSsIaN=$(cat $fileorig) | |
LaTiN=$(cat $fileout) | |
htmlout="${fileorig}".html | |
cat > $htmlout << "EOF" | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>uname</title> | |
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> | |
<meta name="generator" content="Geany 0.19.1" /> | |
<style type="text/css"> | |
.columna { | |
width: 45%; | |
margin-right: 2%; | |
float: left; | |
} | |
</style> | |
</head> | |
<body> | |
<div align="justify" class="columna"> | |
EOF | |
echo $RuSsIaN >> $htmlout | |
cat >> $htmlout << "EOF" | |
</div> | |
<div align="justify" class="columna"> | |
EOF | |
echo $LaTiN >> $htmlout | |
cat >> $htmlout << "EOF" | |
</div> | |
<div style="clear:both"></div> | |
</body> | |
</html> | |
EOF | |
} | |
if [ "$1" = "-c" ]; then | |
cp $2 $2.tcr 2> /dev/null | |
fileorig=$2 | |
fileout=$2.tcr | |
if [ -f $fileout ]; then | |
echo "Transcribiendo del ruso al latino ..." | |
cir2lat 2> /dev/null | |
echo "Generando documento HTML ..." | |
html | |
echo "'¡Listo!" | |
exit 0 | |
else | |
echo "¡No hay nada que transcribir! :(" | |
exit 0 | |
fi | |
elif [ "$1" = "--to-cirilyc" ]; then | |
cp $2 $2.tcr 2> /dev/null | |
fileorig=$2 | |
fileout=$2.tcr | |
if [ -f $fileout ]; then | |
echo "Transcribiendo del ruso al latino ..." | |
cir2lat 2> /dev/null | |
echo "Generando documento HTML ..." | |
html | |
echo "'¡Listo!" | |
exit 0 | |
else | |
echo "¡No hay nada que transcribir! :(" | |
exit 0 | |
fi | |
elif [ "$1" = "-l" ]; then | |
cp $2 $2.tla 2> /dev/null | |
fileorig=$2 | |
fileout=$2.tla | |
if [ -f $fileout ]; then | |
echo "Transcribiendo del latino al ruso ..." | |
lat2cir 2> /dev/null | |
echo "'¡Listo!" | |
exit 0 | |
else | |
echo "¡No hay nada que transcribir! :(" | |
exit 0 | |
fi | |
elif [ "$1" = "--to-latin" ]; then | |
cp $2 $2.tla 2> /dev/null | |
fileorig=$2 | |
fileout=$2.tla | |
if [ -f $fileout ]; then | |
echo "Transcribiendo del latino al ruso ..." | |
lat2cir 2> /dev/null | |
echo "'¡Listo!" | |
exit 0 | |
else | |
echo "¡No hay nada que transcribir! :(" | |
exit 0 | |
fi | |
elif [ "$1" = "-h" ]; then | |
help | |
exit 0 | |
elif [ "$1" = "--help" ]; then | |
help | |
exit 0 | |
fi | |
echo "Requiere un argumento. :)" | |
echo "" | |
echo "Use \"--help\" para más detalles." | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment