aboutsummaryrefslogtreecommitdiff
path: root/i18n.go
blob: 9e9126e747ec7d71dbfb94a81c597d9c779dd407 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
//
// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// 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
    SetLang string
    Pwd string
    Refresh string
    ScrollDown string

    Username string
    Logout string
    Aboutme string
    Slayout string
    NoImg string
    MentionAll string
    AppleMapsLinks string
    Reaction string
    LanguageLabel string
    UpdateSettings string
    ChangePwd string
    OldPwd string
    NewPwd string
    ChangePwdBtn string

    NewChatter string
    Target string
    Noise string
    Chonk string
    Attach string
    Attachment string
    ExtAttachment string

    Onts string

    Original string
    Convoy string
    InReplyTo string
    Time string
    Location string
    Image string
    Unbonk string
    Bonk string
    Nope string
    HonkBack string
    EvenMore string
    Zonk string
    Deack string
    Ack string
    Unsave string
    Save string
    Untagged string
    UntagMe string
    Edit string
    Mute string
    Duration string
    HonkingTime string
    MakeNoise string
    MoreOptions string
    Description string
    GonBHonked string
    Cancel string
    Start string
    AddTime string
    Checkin string
    Preview string
    Actions string

    Newhonk string

    Version string
    Memory string
    Uptime string
    Cputime string

    AddNewHonker string
    Name string
    SkipSub string
    AddHonkerBtn string
    Expand string
    Unsub string
    Delete string
    Resub string
    Notes string
    Flavor string
    Optional string

    MoarHonks string

    Import string
    Fetch string
    Honks string
    HonksFrom string

    FunZoneGreet string

    Hfcs string
    NewFilter string
    FilterName string
    Matches string
    WhoWhere string
    IncludeAudience string
    TextMatches string
    IsAnnounce string
    AnnounceOf string
    Action string
    Reject string
    SkipMedia string
    Hide string
    Collapse string
    Rewrite string
    Replace string
    Expiration string
    BanHammerBtn string
    Date string
    Who string
    Pardon 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: false,
       })
  } else {
       http.SetCookie(w, &http.Cookie{
            Name:     "lang",
            Value:    lang,
            MaxAge:   maxage,
            Secure:   false,
            HttpOnly: false,
       })
  }


  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",
                "changer langue",
                "mot de passe",
                "rafraîchir",
                "bas de page",

                "nom d'utilisateur",
                "déconnexion",
                "à propos de moi",
                "plus mince",
                "pas d'images",
                "mentionner tout le monde",
                "liens apple maps",
                "réaction",
                "langage",
                "enregistrer paramètres",
                "changer le mot de passe",
                "ancien mdp",
                "nouveau mdp",
                "mettre à jour le mot de passe",

                "nouvelle discussion",
                "cible",
                "bruit",
                "et zlou",
                "joindre",
                "pièce jointe",
                "pièce jointe externe",

                "ontologies d'intérêts",

                "original",
                "convoi",
                "en réponse à",
                "temps",
                "lieu",
                "image",
                "départager",
                "partager",
                "nop",
                "klaxonner en retour",
                "encore plus",
                "suppr",
                "marquer comme non lu",
                "marquer comme lu",
                "oublier",
                "s'en souvenir",
                "débalisé",
                "me débaliser",
                "éditer",
                "sourdine",
                "durée",
                "il est temps de klaxonner",
                "faisons un peu d'bruit",
                "plus d'options",
                "description",
                "ça sera klaxonné",
                "annuler",
                "commence",
                "ajouter temps",
                "localiser",
                "aperçu",
                "Actions",

                "klaxonner",

                "version",
                "mémoire",
                "actif depuis",
                "cputime",

                "ajouter un klaxonneur",
                "pseudo",
                "ne pas suivre",
                "ajouter klaxonneur",
                "déplier",
                "se désabonner",
                "supprimer",
                "resuivre",
                "notes",
                "type",
                "optionnel",

                "un klaxon et peut être plus",

                "importer",
                "récupérer",
                "klaxons",
                "de",

                "Bienvenue dans la zone fun !",

                "Système de censure et filtrage de honk",
                "nouveau filtre",
                "nom du filtre",
                "correspondances",
                "qui ou où",
                "inclure l'audience",
                "texte contient",
                "est annoncé",
                "annonce à partir de",
                "mesures",
                "rejeter",
                "omettre médias",
                "cacher",
                "replier",
                "réécrire",
                "par",
                "expiration",
                "imposez votre volonté",
                "Date",
                "Qui",
                "pardonner",
           }
           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",
                "set lang",
                "password",
                "refresh",
                "scroll down",

                "username",
                "logout",
                "about me",
                "skinny layout",
                "omit images",
                "mention all",
                "apple maps links",
                "reaction",
                "language",
                "update settings",
                "change password",
                "oldpass",
                "newpass",
                "update password",

                "new chatter",
                "target",
                "noise",
                "chonk",
                "attach",
                "Attachment",
                "External Attachment",

                "ontologies of interest",

                "original",
                "convoy",
                "in reply to ",
                "Time",
                "Location",
                "Image",
                "unbonk",
                "bonk",
                "nope",
                "honk back",
                "even more",
                "zonk",
                "deack",
                "ack",
                "unsave",
                "save",
                "untagged",
                "untag me",
                "edit",
                "mute",
                "duration",
                "it's honking time",
                "let's make some noise",
                "more options",
                "description",
                "it's gonna be honked",
                "cancel",
                "start",
                "add time",
                "checkin",
                "preview",
                "Actions",

                "new honk",

                "version",
                "memory",
                "uptime",
                "cputime",

                "add a new honker",
                "name",
                "skip sub",
                "add honker",
                "expand",
                "unsub",
                "delete",
                "resub",
                "notes",
                "flavor",
                "optional",

                "one honk maybe more",

                "import",
                "fetch",
                "honks",
                "from",

                "Welcome to the fun zone !",

                "Honk Filtering and Censorship System",
                "new filter",
                "filter name",
                "match",
                "who or where",
                "include audience",
                "text matches",
                "is announce",
                "announce of",
                "action",
                "reject",
                "skip media",
                "hide",
                "collapse",
                "rewrite",
                "replace",
                "expiration",
                "impose your will",
                "Date",
                "Who",
                "pardon",
          }
          return tlStr
   }
}