aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Lionel <lionelmiquel@sfr.fr>2021-02-11 12:19:43 +0100
committerMiquel Lionel <lionel@les-miquelots.net>2021-02-11 12:19:43 +0100
commit13f5e3696f3798d6069d27e67e91e90f6ec3e105 (patch)
treed3739ed44eb01a4497ff8056d1e4b09b5fa79524
parent10f7d14b51ab09aa8641605245e5eb576b29bb46 (diff)
downloadhonk_custom-13f5e3696f3798d6069d27e67e91e90f6ec3e105.tar.gz
honk_custom-13f5e3696f3798d6069d27e67e91e90f6ec3e105.zip
bloated and incomplete i18n implementation
- everything depends on the 'lang' cookie value - basic check if it's a 2 character long letter code - you use it in the views/*.html like the following : {{ i18n.Home }} will display the translation of "home" in the language decided by the lang cookie. - i still need to update the account.html view lol - if the cookie value is not recognized, defaults to english translation.
-rw-r--r--v0.9.5/patches/02_bloated_i18n_implementation.patch153
-rw-r--r--v0.9.5/patches/03_bloated_i18n_implementation.patch52
2 files changed, 205 insertions, 0 deletions
diff --git a/v0.9.5/patches/02_bloated_i18n_implementation.patch b/v0.9.5/patches/02_bloated_i18n_implementation.patch
new file mode 100644
index 0000000..4e22e8c
--- /dev/null
+++ b/v0.9.5/patches/02_bloated_i18n_implementation.patch
@@ -0,0 +1,153 @@
+diff --git a/bloat.go b/bloat.go
+index e89675f..ca4a76f 100644
+--- a/bloat.go
++++ b/bloat.go
+@@ -14,3 +14,148 @@
+ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ package main
++
++import (
++ "net/http"
++ "regexp"
++ "log"
++ "humungus.tedunangst.com/r/webs/login"
++)
++
++type i18n struct {
++ Home string
++ Atme string
++ First string
++ Combos string
++ Chatter string
++ Tags string
++ Events string
++ Longago string
++ Saved string
++ Honkers string
++ Hcfs string
++ Account string
++ Morestuff string
++ Myhonks string
++ About string
++ Front string
++ Funzone string
++ Xzone string
++ Help string
++ Search string
++ Login string
++
++ Newhonk string
++}
++
++func getLangCookie(r *http.Request) string {
++ langCookie, err := r.Cookie("lang")
++ if err != nil {
++ return "en"
++ }
++ return langCookie.Value
++}
++
++
++
++func setLangCookie (w http.ResponseWriter, r *http.Request) {
++ var lang string
++ lang = r.FormValue("lang")
++ var IsLetter = regexp.MustCompile(`^([a-z]+)$`).MatchString
++
++ if !IsLetter(lang) {
++ lang = "wrong" // so !=2 is triggered
++ if debugMode {
++ log.Printf("lang cookie value is not letters")
++ }
++ }
++
++ if len(lang) != 2 {
++ if debugMode {
++ log.Printf("lang cookie value is too long or too short. defaulting to eng")
++ }
++ lang = "en"
++ }
++
++ maxage := 3600 * 24 * 30 * 12
++ if !debugMode {
++ http.SetCookie(w, &http.Cookie{
++ Name: "lang",
++ Value: lang,
++ MaxAge: maxage,
++ Secure: true,
++ HttpOnly: true,
++ })
++ } else {
++ http.SetCookie(w, &http.Cookie{
++ Name: "lang",
++ Value: lang,
++ MaxAge: maxage,
++ Secure: false,
++ HttpOnly: true,
++ })
++ }
++
++
++ u := login.GetUserInfo(r)
++ if u == nil {
++ http.Redirect(w, r, "/", http.StatusSeeOther)
++ }
++}
++
++func setLangStr (lang string) interface{} {
++ switch lang {
++ case "fr" :
++ tlStr := i18n{
++ "accueil",
++ "mentions",
++ "premier (first)",
++ "combos",
++ "discutaille",
++ "balises",
++ "événements",
++ "il y a longtemps",
++ "sauvegardés",
++ "klaxonneurs",
++ "filtrer (hcfs)",
++ "compte",
++ "plus de choses",
++ "profil",
++ "à propos",
++ "tout le réseau connu",
++ "zone fun",
++ "récup",
++ "aide",
++ "rechercher",
++ "connexion",
++ "klaxonner",
++ }
++ return tlStr
++ default:
++ tlStr := i18n{
++ "home",
++ "@me",
++ "first",
++ "combos",
++ "chatter",
++ "tags",
++ "events",
++ "long ago",
++ "saved",
++ "honkers",
++ "filters",
++ "account",
++ "more stuff",
++ "my honks",
++ "about",
++ "front",
++ "funzone",
++ "xzone",
++ "help",
++ "search",
++ "login",
++ "new honk",
++ }
++ return tlStr
++ }
++}
diff --git a/v0.9.5/patches/03_bloated_i18n_implementation.patch b/v0.9.5/patches/03_bloated_i18n_implementation.patch
new file mode 100644
index 0000000..dff14f3
--- /dev/null
+++ b/v0.9.5/patches/03_bloated_i18n_implementation.patch
@@ -0,0 +1,52 @@
+diff --git a/web.go b/web.go
+index 11adf5b..8e42bae 100644
+--- a/web.go
++++ b/web.go
+@@ -85,6 +85,9 @@ func getInfo(r *http.Request) map[string]interface{} {
+ templinfo["IconName"] = iconName
+ templinfo["UserInfo"] = u
+ templinfo["UserSep"] = userSep
++ templinfo["Lang"] = getLangCookie(r)
++ templinfo["i18n"] = setLangStr(getLangCookie(r))
++
+ if u != nil {
+ var combos []string
+ combocache.Get(u.UserID, &combos)
+@@ -99,7 +102,7 @@ func homepage(w http.ResponseWriter, r *http.Request) {
+ var honks []*Honk
+ var userid int64 = -1
+
+- templinfo["ServerMessage"] = serverMsg
++ templinfo["ServerMessage"] = serverMsg
+ if u == nil || r.URL.Path == "/front" {
+ switch r.URL.Path {
+ case "/events":
+@@ -733,6 +736,8 @@ func showhonker(w http.ResponseWriter, r *http.Request) {
+ templinfo["PageArg"] = name
+ templinfo["ServerMessage"] = msg
+ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
++ templinfo["Lang"] = getLangCookie(r)
++
+ honkpage(w, u, honks, templinfo)
+ }
+
+@@ -1109,8 +1114,9 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
+ options.MapLink = ""
+ }
+ options.Reaction = r.FormValue("reaction")
+-
+- sendupdate := false
++ setLangCookie(w, r)
++
++ sendupdate := false
+ ava := re_avatar.FindString(whatabout)
+ if ava != "" {
+ whatabout = re_avatar.ReplaceAllString(whatabout, "")
+@@ -2436,6 +2442,7 @@ func serve() {
+ getters.HandleFunc("/server", serveractor)
+ posters.HandleFunc("/server/inbox", serverinbox)
+ posters.HandleFunc("/inbox", serverinbox)
++ posters.HandleFunc("/langcookie", setLangCookie)
+
+ getters.HandleFunc("/style.css", serveasset)
+ getters.HandleFunc("/local.css", serveasset)