i18n: switch to fluent in login page

This commit is contained in:
nkanaev
2026-06-22 21:03:49 +01:00
parent 9e46014787
commit 6202451c7c
3 changed files with 36 additions and 17 deletions

View File

@@ -340,6 +340,11 @@
"zh": "登录", "zh": "登录",
"ru": "Вход" "ru": "Вход"
}, },
"login_error": {
"en": "Invalid username or password",
"zh": "用户名或密码错误",
"ru": "Неверное имя пользователя или пароль"
},
"username": { "username": {
"en": "Username", "en": "Username",
"zh": "用户名", "zh": "用户名",

View File

@@ -9,6 +9,7 @@
<link rel="alternate icon" href="./static/graphicarts/favicon.png" type="image/png"> <link rel="alternate icon" href="./static/graphicarts/favicon.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style> <style>
[v-cloak] { display: none }
form { form {
max-width: 300px; max-width: 300px;
margin: 0 auto; margin: 0 auto;
@@ -23,21 +24,33 @@
</style> </style>
</head> </head>
<body class="theme-{% .settings.theme_name %}"> <body class="theme-{% .settings.theme_name %}">
<form action="" method="post"> <div id="app" v-cloak>
<img src="./static/graphicarts/anchor.svg" alt=""> <form action="" method="post">
{% if .error %} <img src="./static/graphicarts/anchor.svg" alt="">
<div class="text-danger text-center my-3">{% .error %}</div> <div class="text-danger text-center my-3" v-if="hasError">{{ $t('login_error') }}</div>
{% end %} <div class="form-group">
<div class="form-group"> <label for="username">{{ $t('username') }}</label>
<label for="username">Username</label> <input name="username" class="form-control" id="username" autocomplete="off"
<input name="username" class="form-control" id="username" autocomplete="off" value="{% if .username %}{% .username %}{% end %}" required autofocus>
value="{% if .username %}{% .username %}{% end %}" required autofocus> </div>
</div> <div class="form-group">
<div class="form-group"> <label for="password">{{ $t('password') }}</label>
<label for="password">Password</label> <input name="password" class="form-control" id="password" type="password" required>
<input name="password" class="form-control" id="password" type="password" required> </div>
</div> <button class="btn btn-block btn-default" type="submit">{{ $t('login') }}</button>
<button class="btn btn-block btn-default" type="submit">Login</button> </form>
</form> </div>
<script src="./static/javascripts/vue.min.js"></script>
<script src="./static/javascripts/fluent.js"></script>
<script src="./static/javascripts/i18n.js"></script>
<script>
Vue.use(i18n)
new Vue({
data: { hasError: {% .hasError %} },
created: function () {
this.$setLang('{% .settings.language %}')
}
}).$mount('#app')
</script>
</body> </body>
</html> </html>

View File

@@ -46,13 +46,14 @@ func (m *Middleware) Handler(c *router.Context) {
} else { } else {
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]any{ c.HTML(http.StatusOK, assets.Template("login.html"), map[string]any{
"username": username, "username": username,
"error": "Invalid username/password", "hasError": true,
"settings": m.DB.GetSettings().Map(), "settings": m.DB.GetSettings().Map(),
}) })
return return
} }
} }
c.HTML(http.StatusOK, assets.Template("login.html"), map[string]any{ c.HTML(http.StatusOK, assets.Template("login.html"), map[string]any{
"hasError": false,
"settings": m.DB.GetSettings().Map(), "settings": m.DB.GetSettings().Map(),
}) })
} }