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
+6.1k Golang : Calculate US Dollar Index (DXY)
+10.3k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+13k Golang : Handle or parse date string with Z suffix(RFC3339) example
+5.3k Golang : Intercept, inject and replay HTTP traffics from web server
+5.9k Golang : How to verify input is rune?
+24.4k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+29.2k Golang : Save map/struct to JSON or XML file
+14.2k Golang : How to convert a number to words
+12.2k Golang : Validate email address
+11k CodeIgniter : How to check if a session exist in PHP?
+9.8k Golang : Translate language with language package example
+14.9k Golang : Search folders for file recursively with wildcard support