lang: add locale in django and login view

This commit is contained in:
AdrienLSH
2024-02-01 14:51:20 +01:00
parent a82cf1377b
commit 2786212b9c
8 changed files with 63 additions and 22 deletions

View File

@ -1,19 +1,19 @@
import { client } from "../index.js";
import { lang } from "../index.js";
import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js";
export default class extends AbstractAuthentificateView {
constructor(params) {
super(params, client.lang.get('homeWindowTitle', 'Home'));
super(params, lang.get('homeWindowTitle', 'Home'));
this.redirect_url = "/login"
}
async getHtml() {
return /* HTML */ `
<h1>${client.lang.get('homeTitle', 'Home')}</h1>
<a href="/matchmaking" data-link>${client.lang.get('homeOnline', 'Play online')}</a>
<a href="/games/offline" data-link>${client.lang.get('homeOffline', 'Play offline')}</a>
<a href="/me" data-link>${client.lang.get('homeMe', 'Me')}</a>
<a href="/logout" data-link>${client.lang.get('homeLogout', 'Logout')}</a>
<h1>${lang.get('homeTitle', 'Home')}</h1>
<a href="/matchmaking" data-link>${lang.get('homeOnline', 'Play online')}</a>
<a href="/games/offline" data-link>${lang.get('homeOffline', 'Play offline')}</a>
<a href="/me" data-link>${lang.get('homeMe', 'Me')}</a>
<a href="/logout" data-link>${lang.get('homeLogout', 'Logout')}</a>
`;
}
}

View File

@ -1,4 +1,4 @@
import { client, navigateTo } from "../../index.js";
import { client, lang, navigateTo } from "../../index.js";
import { clear, fill_errors } from "../../utils/formUtils.js";
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
@ -10,10 +10,10 @@ async function login(redirectTo = '/home')
let password = document.getElementById('passwordInput').value;
if (username === '') {
document.getElementById('username').innerHTML = 'This field may not be blank.';
document.getElementById('username').innerHTML = lang.get('errorEmptyField', 'This field may not be blank.');
}
if (password === '') {
document.getElementById('password').innerHTML = 'This field may not be blank.';
document.getElementById('password').innerHTML = lang.get('errorEmptyField', 'This field may not be blank.');
}
if (username === '' || password === '')
return;
@ -32,7 +32,7 @@ async function login(redirectTo = '/home')
export default class extends AbstractNonAuthentifiedView {
constructor(params, lastUrlBeforeLogin = '/home') {
super(params, "Login", lastUrlBeforeLogin);
super(params, lang.get('loginWindowTitle', 'Login'), lastUrlBeforeLogin);
this.redirectTo = lastUrlBeforeLogin;
}
@ -56,21 +56,21 @@ export default class extends AbstractNonAuthentifiedView {
return `
<div class='container-fluid'>
<form class='border border-2 rounded bg-light-subtle mx-auto p-2 col-md-7 col-lg-4'>
<h4 class='text-center fw-semibold mb-4'>Login</h4>
<h4 class='text-center fw-semibold mb-4'>${lang.get('loginFormTitle', 'Login')}</h4>
<div class='form-floating mb-2'>
<input type='text' class='form-control' id='usernameInput' placeholder='Username'>
<label for='usernameInput'>Username</label>
<label for='usernameInput'>${lang.get('loginFormUsername', 'Username')}</label>
<span class='text-danger' id='username'></span>
</div>
<div class='form-floating'>
<input type='password' class='form-control' id='passwordInput' placeholder='Password'>
<label for='passwordInput'>Password</label>
<label for='passwordInput'>${lang.get('loginFormPassword', 'Password')}</label>
<span class='text-danger' id='password'></span>
</div>
<div class='d-flex'>
<button type='button' class='btn btn-primary mt-3 mb-2' id='loginButton'>Login</button>
<button type='button' class='btn btn-primary mt-3 mb-2' id='loginButton'>${lang.get('loginFormButton', 'Login')}</button>
<span class='text-danger my-auto mx-2' id='login'></span>
<p class='ms-auto mt-auto'>No account yet? <a href='/register' data-link>Register</a></p>
<p class='ms-auto mt-auto'>${lang.get('loginNoAccount', 'No account yet?')} <a href='/register' data-link>${lang.get('loginRegister', 'Register')}</a></p>
</div>
</form>
</div>