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 (


 const hanziInputPage = `<html><body>

  <form method="post" action="/hokkienminnan">
  <p><h1>Hokkien(福建话)/Min-nan(閩南語) Pronounciations</h2></p>
  <p>Suggestion : [ {{.Suggestion}} ] Copy and paste below to try it out.</p>
  <textarea name="hanziinput" rows="4" cols="50"></textarea><br>
  <input type="submit" name="Find Hokkien Pronounciations" value="Find Hokkien Pronounciations">

 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.

  // randomly pick one beautiful girl(URL) from the URLs slice

  choosen := hokkienWords[rand.Intn(len(hokkienWords))]

  conditionsMap["Suggestion"] = choosen

  if err := hanziInputTemplate.Execute(w, conditionsMap); err != nil {

 func hokkienMinnan(w http.ResponseWriter, r *http.Request) {

  if r.FormValue("hanziinput") != "" {
 input := r.FormValue("hanziinput")

 header := `<!DOCTYPE html>
  function goBack() {

 <button onclick="goBack()">Go Back</button><br><br>`

 body := `<table border="1" style="width:100%">
 <th>Converted to Traditional Chinese</th>
 <th>Pronouciation at moedict.tw</th>

 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 :



  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.