Ejemplo n.º 1
0
Archivo: pali.go Proyecto: siongui/pali
func main() {
	// add pali input method to input text element
	imepali.BindPaliInputMethodToInputTextElementById("word")

	// init variables
	word = js.Global.Get("document").Call("getElementById", "word")
	mainContent = js.Global.Get("document").Call("getElementById", "main-content")

	// init trie for words suggestion
	bits.SetAllowedCharacters("abcdeghijklmnoprstuvyāīūṁṃŋṇṅñṭḍḷ…'’° -")
	frozenTrie = bits.FrozenTrie{}
	frozenTrie.Init(succinctTrieDataBlob, rankDirectoryDataBlob, succinctTrieNodeCount)

	// input suggest menu
	sg.BindSuggest("word", func(w string) []string {
		return frozenTrie.GetSuggestedWords(w, 30)
	})

	setupNavbar()
	setupSetting()

	// show language according to NavigatorLanguages API
	supportedLocales := []string{"en_US", "zh_TW", "vi_VN", "fr_FR"}
	initialLocale := jsgettext.DetermineLocaleByNavigatorLanguages(navigatorLanguages, supportedLocales)
	if initialLocale != "en_US" {
		jsgettext.Translate(initialLocale)
		langSelect := js.Global.Get("document").Call("getElementById", "lang-select")
		langSelect.Set("value", initialLocale)
	}

	word.Call("addEventListener", "keyup", handleInputKeyUp, false)
}
Ejemplo n.º 2
0
func main() {
	jsgettext.SetupTranslationMapping(jsonData)

	d := js.Global.Get("document")
	nodeList := d.Call("querySelectorAll", "button")
	length := nodeList.Get("length").Int()
	for i := 0; i < length; i++ {
		btn := nodeList.Call("item", i)
		btn.Call("addEventListener", "click", func() {
			jsgettext.Translate(btn.Get("value").String())
		})
	}
}