aboutsummaryrefslogtreecommitdiff
path: root/v0.9.5/patches/02_bloated_i18n_implementation.patch
blob: 4e22e8c89312b45fbbea0ea4d77270b461dc882b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
+   }
+}