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
+23.9k Golang : Upload to S3 with official aws-sdk-go package
+9k Golang : Intercept and compare HTTP response code example
+7.6k Golang : Test if an input is an Armstrong number example
+7.8k Javascript : How to check a browser's Do Not Track status?
+5.7k Golang : Find change in a combination of coins example
+15.3k Golang : ROT47 (Caesar cipher by 47 characters) example
+5.3k Golang *File points to a file or directory ?
+12.7k Golang : Convert int(year) to time.Time type
+24.4k Golang : Time slice or date sort and reverse sort example
+12.3k Elastic Search : Return all records (higher than default 10)
+8.9k Golang : automatically figure out array length(size) with three dots
+6.7k Android Studio : Hello World example