Created
January 26, 2021 19:51
-
-
Save colorwebdesigner/ef2368b58411defc465772af25e56085 to your computer and use it in GitHub Desktop.
Bash transliteration script
This file contains hidden or 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 | |
# translit function | |
# ---------------------- | |
translit() { | |
local trs="${1// /-}" | |
trs=$(sed "y/абвгдезийклмнопрстуфхцы/abvgdezijklmnoprstufxcy/" <<< "${trs}") | |
trs=$(sed "y/АБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/ABVGDEZIJKLMNOPRSTUFXCY/" <<< "$trs") | |
trs=${trs//ч/ch} | |
trs=${trs//Ч/CH} | |
trs=${trs//ш/sh} | |
trs=${trs//Ш/SH} | |
trs=${trs//ё/hyo} | |
trs=${trs//Ё/HYO} | |
trs=${trs//ж/zh} | |
trs=${trs//Ж/ZH} | |
trs=${trs//щ/sh} | |
trs=${trs//Щ/SH} | |
trs=${trs//э/e} | |
trs=${trs//Э/E} | |
trs=${trs//ю/ju} | |
trs=${trs//Ю/JU} | |
trs=${trs//я/ja} | |
trs=${trs//Я/JA} | |
trs=${trs//ъ/} | |
trs=${trs//Ъ/} | |
trs=${trs//ь/} | |
trs=${trs//Ь/} | |
hash iconv &> /dev/null && trs=$(iconv -c -f UTF8 -t ASCII//TRANSLIT <<< "$trs") | |
echo "$trs"; | |
} | |
translit "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment