Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
Recently I've been busy enhancing my Jawi to Rumi converter and I found out that some Jawi words cannot be converted back to Rumi(Romanized) form if there's no available match in the map based dictionary. To tackle this type of problem, I've to devise a better way to convert the Jawi words to Rumi. One such way is to break the Jawi word into each individual characters and perform a map(a.k.a hash-table) search for the individual character.
Depending on the Jawi input, some Rumi results are easy to figure out. Words such as foto
or syampu
are easily comprehensible from their final Rumi result. However, some words will require the reader to have some ability to read Jawi. At the minimum, the reader needs to know about the placement rules of ا - alif
alphabet in a word.
Ok, here you go!
package main
import (
"log"
)
var jawiAlphabet = map[string]string{}
var rumiAlphabet = map[string]string{}
func main() {
// build the Jawi map
jawiAlphabet["ا"] = "alif"
jawiAlphabet["ب"] = "ba"
jawiAlphabet["ت"] = "ta"
jawiAlphabet["ث"] = "sa(tha)"
jawiAlphabet["ج"] = "jim"
jawiAlphabet["چ"] = "ca"
jawiAlphabet["ح"] = "ha(ḥa)"
jawiAlphabet["خ"] = "kha(khO)"
jawiAlphabet["د"] = "dal"
jawiAlphabet["ذ"] = "zal(dhal)"
jawiAlphabet["ر"] = "ra(rO)"
jawiAlphabet["ز"] = "zai"
jawiAlphabet["س"] = "sin"
jawiAlphabet["ش"] = "syin"
jawiAlphabet["ص"] = "sad(ṣod)"
jawiAlphabet["ض"] = "dad(ḍod)"
jawiAlphabet["ط"] = "ta(ṭo)"
jawiAlphabet["ظ"] = "za(ẓo)"
jawiAlphabet["ع"] = "ain"
jawiAlphabet["غ"] = "ghain"
jawiAlphabet["ڠ"] = "nga"
jawiAlphabet["ف"] = "fa"
jawiAlphabet["ڤ"] = "pa"
jawiAlphabet["ق"] = "qaf"
jawiAlphabet["ک"] = "kaf"
jawiAlphabet["ݢ"] = "ga"
jawiAlphabet["ل"] = "lam"
jawiAlphabet["م"] = "mim"
jawiAlphabet["ن"] = "nun"
jawiAlphabet["و"] = "wau"
jawiAlphabet["ۏ"] = "va"
jawiAlphabet["ه"] = "ha"
jawiAlphabet["ء"] = "hamzah"
jawiAlphabet["ي"] = "ya"
jawiAlphabet["ڽ"] = "nya"
jawiAlphabet["ى"] = "e(ye)"
// build the Rumi map
rumiAlphabet["ا"] = "a"
rumiAlphabet["ب"] = "b"
rumiAlphabet["ت"] = "t"
rumiAlphabet["ث"] = "t'"
rumiAlphabet["ج"] = "j"
rumiAlphabet["چ"] = "c"
rumiAlphabet["ح"] = "H"
rumiAlphabet["خ"] = "H'"
rumiAlphabet["د"] = "d"
rumiAlphabet["ذ"] = "d'"
rumiAlphabet["ر"] = "r"
rumiAlphabet["ز"] = "z"
rumiAlphabet["س"] = "s"
rumiAlphabet["ش"] = "s'"
rumiAlphabet["ص"] = "S"
rumiAlphabet["ض"] = "D"
rumiAlphabet["ط"] = "T"
rumiAlphabet["ظ"] = "Z"
rumiAlphabet["ع"] = "g"
rumiAlphabet["غ"] = "g'"
rumiAlphabet["ڠ"] = "N"
rumiAlphabet["ف"] = "f"
rumiAlphabet["ڤ"] = "p"
rumiAlphabet["ق"] = "q"
rumiAlphabet["ک"] = "k"
rumiAlphabet["ݢ"] = "k'"
rumiAlphabet["ل"] = "l"
rumiAlphabet["م"] = "m"
rumiAlphabet["ن"] = "n"
rumiAlphabet["و"] = "o"
rumiAlphabet["ۏ"] = "v"
rumiAlphabet["ه"] = "h"
rumiAlphabet["ء"] = "-"
rumiAlphabet["ي"] = "y"
rumiAlphabet["ڽ"] = "ñ"
rumiAlphabet["ى"] = "e"
testRumi := "cendawan"
testJawi := "چنداون"
//testRumi := "foto"
//testJawi := "فوتو"
//testRumi := "syampu"
//testJawi := "شمڤو"
log.Println("Breaking down :", testRumi + " --> " + testJawi)
var hurufResult []string
var rumiResult []string
for _,t := range testJawi {
j := jawiAlphabet[string(t)]
r := rumiAlphabet[string(t)]
log.Println(string(t),j,r)
hurufResult = append(hurufResult,j)
rumiResult = append(rumiResult,r)
}
log.Println("hurufResult : ", hurufResult)
log.Println("rumiResult : ", rumiResult)
}
Sample output:
2020/01/12 20:27:34 Breaking down : syampu --> شمڤو
2020/01/12 20:27:34 ش syin s'
2020/01/12 20:27:34 م mim m
2020/01/12 20:27:34 ڤ pa p
2020/01/12 20:27:34 و wau o
2020/01/12 20:27:34 hurufResult : [syin mim pa wau]
2020/01/12 20:27:34 rumiResult : [s' m p o]
Hope this helps and happy coding!
See also : Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+18.9k Golang : Populate dropdown with html/template example
+13.2k Golang : Get user input until a command or receive a word to stop
+13.7k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+13.3k Generate salted password with OpenSSL example
+12k Golang : 2 dimensional array example
+4.5k Golang : How to pass data between controllers with JSON Web Token
+12.1k Golang : Extract part of string with regular expression
+7.9k Golang : HttpRouter multiplexer routing example
+16.2k Golang : How to implement two-factor authentication?
+20.4k PHP : Convert(cast) int to double/float
+5k Golang : The Tao of importing package
+7.2k Golang : Check to see if *File is a file or directory