Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elsanussi-s-mneina/56e2ed760c32c27d3ab0ab544a9d5c67 to your computer and use it in GitHub Desktop.
Save elsanussi-s-mneina/56e2ed760c32c27d3ab0ab544a9d5c67 to your computer and use it in GitHub Desktop.
Converting Arabic text to Cyrillic. The Arabic text is written in the Arabic script. The Cyrillic text is a transliteration system I made without much design and is non-standard. This transliteration system is based on how Russian is written in Cyrillic, and a Turkic language that has interdental fricatives.
package main
import (
"fmt"
"strings"
)
var table = [][2]string{
{"ا", "-"},
{"أ", "-"},
{"إِ", "и"},
{"إ", "и"},
{"بّ", "бб"},
{"ب", "б"},
{"تّ", "тт"},
{"ت", "т"},
{"ثّ", "ҫҫ"},
{"ث", "ҫ"},
{"جّ", "дждж"},
{"ج", "дж"},
{"حّ", "хъхъ"},
{"ح", "хъ"},
{"خّ", "хх"},
{"خ", "х"},
{"دّ", "дд"},
{"د", "д"},
{"ذّ", "ҙҙ"},
{"ذ", "ҙ"},
{"رّ", "рр"},
{"ر", "р"},
{"زّ", "зз"},
{"ز", "з"},
{"سّ", "сс"},
{"س", "с"},
{"شّ", "шш"},
{"ش", "ш"},
{"صّ", "съсъ"},
{"ص", "съ"},
{"ضّ", "дъдъ"},
{"ض", "дъ"},
{"طّ", "тътъ"},
{"ط", "тъ"},
{"ظّ", "ҙъҙъ"},
{"ظ", "ҙъ"},
{"عّ", "аъаъ"},
{"ع", "аъ"},
{"غّ", "ғғ"},
{"غ", "ғ"},
{"فّ", "фф"},
{"ف", "ф"},
{"قّ", "ҡҡ"},
{"ق", "ҡ"},
{"كّ", "кк"},
{"ك", "к"},
{"لّ", "лл"},
{"ل", "л"},
{"مّ", "мм"},
{"م", "м"},
{"نّ", "нн"},
{"ن", "н"},
{"هّ", "һһ"},
{"ه", "һ"},
{"وّ", "ўў"},
{"و", "ў"},
{"يّ", "йй"},
{"ي", "й"},
{"ء", ""},
{"َ", "а"},
{"ً", "а-н"},
{"َا", "аа"},
{"ٍ", "и-н"},
{"ِ", "и"},
{"ٌ", "у-н"},
{"ُ", "у"},
{"ْ", ""},
{"ّ", ""},
{"ة", "-т"},
{"َى", "аэ"},
{"ى", "аэ"},
{"أ", " "},
{"إ", ""},
{"ئ", ""},
{"ؤ", ""}}
const ARABIC = 0 // the first column of table
const CYRILLIC = 1 // the second column
func transliterate(table [][2]string, input string) string {
var cyrillic string
for len(input) > 0 {
var foundMatch bool
for _, row := range table {
if strings.HasPrefix(input, row[ARABIC]) {
foundMatch = true
cyrillic += row[CYRILLIC]
input = strings.TrimPrefix(input, row[ARABIC])
break
}
}
if !foundMatch {
inputRunes := []rune(input)
firstRune := inputRunes[0]
firstRuneAsString := string(firstRune)
cyrillic += firstRuneAsString
input = strings.TrimPrefix(input, firstRuneAsString)
}
}
return cyrillic
}
func main() {
fmt.Println("Arabic to Cyrillic transliteration")
var arabicText = "مَرْحَبًا إِلَى قَنَاتِيْ"
var cyrillicText = transliterate(table, arabicText)
fmt.Println("Arabic Text:")
fmt.Println(arabicText)
fmt.Println("Cyrillic Text:")
fmt.Println(cyrillicText)
fmt.Println("Program ended normally, please watch more at youtube.com/GrassDewMorning")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment