Changeset 20 in code for trunk/web


Ignore:
Timestamp:
Aug 31, 2023, 8:28:02 AM (22 months ago)
Author:
manerakai
Message:

Improved code

Location:
trunk/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/main.go

    r19 r20  
    9191                        "Engine":          engine,
    9292                        "enginesNames":    enginesNames,
    93                         "SourceLanguages": targetLanguages,
    94                         "TargetLanguages": sourceLanguages,
     93                        "SourceLanguages": sourceLanguages,
     94                        "TargetLanguages": targetLanguages,
    9595                        "OriginalText":    originalText,
    9696                        "TranslatedText":  translatedText,
     
    169169
    170170                lang := c.Query("lang")
    171                 if lang == "" {
    172                         lang = "en"
    173                 }
    174171
    175172                if url, err := engines.Engines[engine].Tts(text, lang); err != nil {
     
    189186        })
    190187
     188        app.Post("/switchlanguages", func(c *fiber.Ctx) error {
     189                if c.Cookies("from") != "" {
     190                        fromCookie := new(fiber.Cookie)
     191                        fromCookie.Name = "from"
     192                        fromCookie.Value = c.Cookies("to")
     193                        fromCookie.Expires = time.Now().Add(24 * time.Hour * 365)
     194
     195                        toCookie := new(fiber.Cookie)
     196                        toCookie.Name = "to"
     197                        toCookie.Value = c.Cookies("from")
     198                        toCookie.Expires = time.Now().Add(24 * time.Hour * 365)
     199
     200                        c.Cookie(fromCookie)
     201                        c.Cookie(toCookie)
     202                }
     203                return c.Redirect("/")
     204        })
     205
    191206        app.Static("/static", "./static")
    192207
  • trunk/web/views/index.html

    r19 r20  
    5858                <textarea autofocus class="item" id="input" name="text" dir="auto"
    5959                    placeholder="Enter Text Here">{{ .OriginalText }}</textarea>
    60                 <div class="center">
    61                     <audio controls>
    62                         <source type="audio/mpeg" src="{{ .TtsFrom }}">
    63                     </audio>
    64                 </div>
     60                {{if .TtsFrom}}
     61                <audio controls>
     62                    <source type="audio/mpeg" src="{{ .TtsFrom }}">
     63                </audio>
     64                {{end}}
    6565            </div>
    6666
     
    6868                <textarea id="output" class="translation item" dir="auto" placeholder="Translation"
    6969                    readonly>{{.TranslatedText}}</textarea>
     70                {{if .TtsTo}}
    7071                <audio controls>
    7172                    <source type="audio/mpeg" src="{{ .TtsTo }}">
    7273                </audio>
     74                {{end}}
    7375            </div>
    7476        </div>
Note: See TracChangeset for help on using the changeset viewer.