Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
A simple example on how to use Golang's map to build a Jawi(Malays in Arabic script) to Rumi translation dictionary. My knowledge of Jawi became lost over the years(I studied it back in primary 1 and 2) and created this tool to help me in regaining back my ability to read and write Jawi.
Please download the translation file at [https://raw.githubusercontent.com/mohdzamrimurah/rumi-jawi/master/rumi-jawi-unicode.txt][1] before running this program. If you are unable to download the dictionary file from the link above, try navigating to the most recent dictionary at [https://github.com/mohdzamrimurah/rumi-jawi][2]
Here you go!
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
// one map for each dictionary
jawiRumi := map[string]string{}
rumiJawi := map[string]string{}
fileName := "rumi-jawi-unicode.txt"
//fileName := "rumi-jawi-unicode-3-1-2019.txt"
fileBytes, err := ioutil.ReadFile(fileName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
lines := strings.Split(string(fileBytes), "\n")
// build the dictionaries
for _, line := range lines {
if len(line) > 0 {
split := strings.Split(line, ",")
rumi := split[0]
jawi := split[1]
jawiRumi[jawi] = rumi
rumiJawi[rumi] = jawi
}
}
//to translate
//jawi := "کيت مستي جادي ماءنسي يڠ برويباوا "
//jawi := "سابن هاري کيت مستي جاݢ ڤرتوتورن دان تيڠکت لاکو کيت "
jawi := "بلاجر جاوي تق روݢي بيلا کنا ماکي مماکي بوليهله فهم"
fmt.Println("Translating : [", jawi, "]")
//get rid of empty spaces in front and back
jawi = strings.TrimPrefix(jawi, " ")
jawi = strings.TrimSuffix(jawi, " ")
//chunk them
jawiWords := strings.Split(jawi, " ")
for _, word := range jawiWords {
fmt.Println(jawiRumi[string(word)] + " >> " + word)
}
fmt.Println(jawi)
rumi := ""
for _, word := range jawiWords {
rumi = rumi + " " + jawiRumi[string(word)]
}
fmt.Println(rumi)
//translate rumi(latin/romanized) back to Jawi/Yawi
// get rid of empty spaces in front and back
rumi = strings.TrimPrefix(rumi, " ")
rumi = strings.TrimSuffix(rumi, " ")
rumiWords := strings.Split(rumi, " ")
for _, word := range rumiWords {
fmt.Println(rumiJawi[word] + " >> " + string(word))
}
}
// jawi source :
// http://juong-journal.blogspot.com/2014/07/convert-tulisan-rumi-ke-jawi-secara.html
Output:
Translating : [ حکايت مروڠ مها وڠسا ]
hikayat >> حکايت
merong >> مروڠ
maha >> مها
wangsa >> وڠسا
حکايت مروڠ مها وڠسا
hikayat merong maha wangsa
حکايت >> hikayat
مروڠ >> merong
مها >> maha
وڠسا >> wangsa
See also : Golang : Gargish-English language translator
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
+7.1k Golang : Individual and total number of words counter example
+15.3k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+8.5k Golang : Heap sort example
+19.5k Golang : Append content to a file
+12.4k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+25.5k Golang : missing Mercurial command
+4.5k Facebook : How to place save to Facebook button on your website
+6.1k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+18.4k Unmarshal/Load CSV record into struct in Go
+15.4k Golang : Get current time from the Internet time server(ntp) example
+5.5k Fix yum-complete-transaction error
+7k Golang : How to fix html/template : "somefile" is undefined error?