Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
I built this tool for my own use and use it to teach my kids Hokkien a.k.a Min-nan language. At the same time, I also want to learn how to write the corresponding Hanzi(漢字) as it sounds in Hokkien. If you're learning Hokkien. I hope that this simple tool can be useful to you as a teaching tool.
Basically, it will convert the Hanzi input and change it to Traditional Chinese fonts and provide a link to https://www.moedict.tw/ together with the individual Hanzi.
If you don't know Hokkien, then this video should explain what this tutorial trying to do:
Alright, here we go!
package main
import (
"fmt"
"html/template"
"log"
"math/rand"
"net/http"
"regexp"
"strconv"
"strings"
"time"
"unicode"
"github.com/siongui/gojianfan"
)
const hanziInputPage = `<html><body>
<form method="post" action="/hokkienminnan">
<p><h1>Hokkien(福建话)/Min-nan(閩南語) Pronounciations</h2></p>
<p>
<p>Suggestion : [ {{.Suggestion}} ] Copy and paste below to try it out.</p>
<textarea name="hanziinput" rows="4" cols="50"></textarea><br>
</p>
<p>
<input type="submit" name="Find Hokkien Pronounciations" value="Find Hokkien Pronounciations">
</p>
</form>
</body></html>`
var hanziInputTemplate = template.Must(template.New("").Parse(hanziInputPage))
func hanziInputPageHandler(w http.ResponseWriter, r *http.Request) {
conditionsMap := map[string]interface{}{}
hokkienWords := []string{
"毋著",
"無招",
"无招",
"牛囝毋捌虎",
"家婆",
"教豬教狗,不如家己走",
"干焦真好食",
"按呢死人款",
"臭大肥",
"無x脬子", // x is for the lan character, but it will screw up the markdown here.
"我x呃",
"膣屄",
"食老番顛",
"畫虎x",
"拍水銃",
"扶x脬",
"查埔人",
"查某人",
"查埔囝",
"查某囝",
"衰潲",
"惡人無膽",
"戇",
"逐家",
"囡仔囝",
"做生日",
"雞卵糕",
"廟",
"會使用",
"三牲囝",
"歹囝",
"做牛著拖,做人著磨",
"棚頂做甲流汗,棚跤嫌甲流瀾",
"甘願做牛,毋驚無犁通拖",
"好食好睏",
"空頭",
"了錢生理無人做,刣頭生理有人做",
"發達",
"愈濟愈好",
"濟濟",
"骨力食栗,貧惰吞瀾",
"時到時擔當,無米才煮番薯湯",
"一枝草,一點露",
"趁也著趁,食也著食",
"臭款",
"拍無去",
"趁甲痟",
"了甲落褲",
"愛飯癮飯",
"紅毛鬼",
"做鬼做怪",
"垃儳鬼",
"筊鬼",
"貪食鬼",
"找錢",
"人客",
"家伙",
"有夠",
"老人毋講古,少年毋捌寶",
"大人愛趁錢,囡仔愛過年",
}
// randomly pick one beautiful girl(URL) from the URLs slice
rand.Seed(time.Now().UnixNano())
choosen := hokkienWords[rand.Intn(len(hokkienWords))]
conditionsMap["Suggestion"] = choosen
if err := hanziInputTemplate.Execute(w, conditionsMap); err != nil {
log.Println(err)
}
}
func hokkienMinnan(w http.ResponseWriter, r *http.Request) {
if r.FormValue("hanziinput") != "" {
input := r.FormValue("hanziinput")
header := `<!DOCTYPE html>
<html>
<head>
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<button onclick="goBack()">Go Back</button><br><br>`
body := `<table border="1" style="width:100%">
<tr>
<th>#</th>
<th>Original</th>
<th>Converted to Traditional Chinese</th>
<th>Pronouciation at moedict.tw</th>
</tr>`
w.Write([]byte(fmt.Sprintf("%s", header)))
w.Write([]byte(fmt.Sprintf("%s", body)))
for k, v := range input {
// convert to string
s := string(v)
w.Write([]byte(fmt.Sprintf("%s", "<tr>")))
w.Write([]byte(fmt.Sprintf("%s", "<th>"+strconv.Itoa(k)+"</th>")))
w.Write([]byte(fmt.Sprintf("%s", "<th>"+s+"</th>")))
converted := gojianfan.S2T(s)
w.Write([]byte(fmt.Sprintf("%s", "<th>"+converted+"</th>")))
re := regexp.MustCompile("^[a-zA-Z0-9_]*$")
if !re.MatchString(string(v)) && !unicode.IsPunct(v) && !unicode.IsSpace(v) {
w.Write([]byte(fmt.Sprintf("%s", "<th><a target='_blank' href=\""+"https://www.moedict.tw/'"+converted+"\">https://www.moedict.tw/'"+converted+"</a></th>")))
}
w.Write([]byte(fmt.Sprintf("%s", "</tr>")))
}
footer := `</table></body></html>`
w.Write([]byte(fmt.Sprintf("%s", footer)))
}
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", hanziInputPageHandler)
mux.HandleFunc("/hokkienminnan", hokkienMinnan)
http.ListenAndServe(":8888", mux)
}
References :
https://github.com/siongui/gojianfan
https://www.socketloop.com/tutorials/golang-randomly-pick-an-item-from-a-slice-array-example
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
+13.9k Golang : Convert IP version 6 address to integer or decimal number
+13.2k Generate salted password with OpenSSL example
+24.8k Golang : Storing cookies in http.CookieJar example
+9.9k Golang : cannot assign type int to value (type uint8) in range error
+7k Golang : Calculate how many weeks left to go in a given year
+29.5k Golang : How to get HTTP request header information?
+7.3k Golang : Mapping Iban to Dunging alphabets
+9.6k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+19.3k Golang : Set or Add HTTP Request Headers
+18.9k Mac OSX : Homebrew and Golang
+11.8k Golang : Simple client-server HMAC authentication without SSL example
+29.8k Golang : How to verify uploaded file is image or allowed file types