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
+12k Golang : How to check if a string starts or ends with certain characters or words?
+6.4k Golang : Skip or discard items of non-interest when iterating example
+6.6k Golang : Pat multiplexer routing example
+22.6k Golang : Test file read write permission example
+7.7k Swift : Convert (cast) String to Float
+28.1k Golang : Read, Write(Create) and Delete Cookie example
+7.2k Golang : Convert source code to assembly language
+38.7k Golang : How to iterate over a []string(array)
+12.9k Golang : How to get a user home directory path?
+9.4k Random number generation with crypto/rand in Go
+4.1k Javascript : How to show different content with noscript?
+17.6k Golang : How to log each HTTP request to your web server?