Commit 7ce99de2 authored by Siong-Ui Te's avatar Siong-Ui Te

dic: move common frontend code to libfrontend

parent dc9bfb2d
......@@ -13,16 +13,44 @@ addons:
- make
- git
- gettext
install:
- cd tipitaka/
- make install
script:
- make make-sutta
deploy:
- provider: pages
repo: siongui/tipitaka.sutta.org
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: tipitaka/website
on:
branch: master
# https://docs.travis-ci.com/user/build-matrix/
jobs:
include:
# for dictionary.online-dhamma.net
- env: TARGET_WEBSITE=dhamma
install:
- cd dictionary/
- make install
script:
- make make-dhamma
after_success:
- make custom_dhamma_deploy
# for dictionary.sutta.org
- env: TARGET_WEBSITE=sutta
install:
- cd dictionary/
- make install
script:
- make make-sutta
after_success:
- make custom_sutta_deploy
# dpl v2 (not working for lots of symlinks)
#deploy:
# - provider: pages:git
# repo: siongui/dictionary.sutta.org
# keep_history: false
# token: $GITHUB_TOKEN
# local_dir: website
# on:
# branch: master
# edge: true
# verbose: true
# dpl v1 (not working for lots of symlinks)
#deploy:
# - provider: pages
# repo: siongui/dictionary.sutta.org
# skip_cleanup: true
# github_token: $GITHUB_TOKEN
# local_dir: website
# on:
# branch: master
......@@ -265,7 +265,6 @@ install: lib_pali lib_gtmpl lib_gopherjs_input_suggest lib_gopherjs
lib_pali:
@echo "\033[92mInstalling common lib used in this project ...\033[0m"
go get -u github.com/siongui/gopalilib/dicutil
go get -u github.com/siongui/gopalilib/lib/jsgettext
go get -u github.com/siongui/gopaliwordvfs
go get -u github.com/siongui/gopalilib/libfrontend/velthuis
go get -u github.com/siongui/gopalilib/libfrontend/setting
......
......@@ -7,18 +7,9 @@ import (
"github.com/siongui/gopalilib/lib/dicmgr"
dic "github.com/siongui/gopalilib/lib/dictionary"
"github.com/siongui/gopalilib/lib/jsgettext"
"github.com/siongui/gopalilib/libfrontend"
)
var supportedLocales = []string{"en_US", "zh_TW", "vi_VN", "fr_FR"}
func TranslateDocument(locale string) {
elms := Document.QuerySelectorAll("[data-default-string]")
for _, elm := range elms {
str := elm.Get("dataset").Get("defaultString").String()
elm.Set("textContent", jsgettext.Gettext(locale, str))
}
}
func setDocumentTitle(titleLocale string, typ dic.PageType, wordOrPrefix string) {
//title := jsgettext.Gettext(titleLocale, "Pali Dictionary | Pāli to English, Chinese, Japanese, Vietnamese, Burmese Dictionary")
title := jsgettext.Gettext(titleLocale, "Pāli Dictionary")
......@@ -34,19 +25,10 @@ func setDocumentTitle(titleLocale string, typ dic.PageType, wordOrPrefix string)
Document.Set("title", title)
}
func getFinalShowLocale() string {
// show language according to site url and NavigatorLanguages API
locale := Document.GetElementById("site-info").Dataset().Get("locale").String()
if locale == "" {
return jsgettext.DetermineLocaleByNavigatorLanguages(Window.Navigator().Languages(), supportedLocales)
}
return locale
}
func setupContentAccordingToUrlPath() {
// show language according to NavigatorLanguages API
titleLocale := getFinalShowLocale()
TranslateDocument(titleLocale)
titleLocale := libfrontend.GetFinalShowLocale()
libfrontend.TranslateDocument(titleLocale)
up := Window.Location().Pathname()
typ := dic.DeterminePageType(up)
......@@ -97,7 +79,3 @@ func setupBrowseDictionary() {
}
pl.SetInnerHTML(all)
}
func isOffline() bool {
return Window.Location().Hostname() == "localhost" && Window.Location().Port() == "8080"
}
......@@ -25,13 +25,13 @@ func httpGetWordJson(w string, changeUrl bool) {
wi, err := lib.HttpGetWordJson(libfrontend.HttpWordJsonPath(w))
if err != nil {
mainContent.Set("innerHTML", err.Error()+"<br>"+"No Such Word or Internet Connection Error")
mainContent.Set("innerHTML", "No Such Word or Internet Connection Error"+"<br>"+err.Error())
return
}
if changeUrl {
Window.History().PushState(w, "", dic.WordUrlPath(w))
setDocumentTitle(getFinalShowLocale(), dic.WordPage, w)
setDocumentTitle(libfrontend.GetFinalShowLocale(), dic.WordPage, w)
}
mainContent.RemoveAllChildNodes()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment