Add localisation and french locale to registration menu

This commit is contained in:
Edralo 2024-04-23 01:40:57 +02:00
parent 923aea0c64
commit b5677f7cc4
4 changed files with 31 additions and 16 deletions

View File

@ -18,10 +18,17 @@ export const menu: SimpleTranslationEntries = {
"login": "Login", "login": "Login",
"register": "Register", "register": "Register",
"emptyUsername": "Username must not be empty", "emptyUsername": "Username must not be empty",
"invalidUsername": "The provided username is invalid", "invalidLoginUsername": "The provided username is invalid",
"invalidPassword": "The provided password is invalid", "invalidRegisterUsername": "Username must only contain letters, numbers, or underscores",
"invalidLoginPassword": "The provided password is invalid",
"invalidRegisterPassword": "Password must be 6 characters or longer",
"usernameAlreadyUsed": "The provided username is already in use",
"accountNonExistent": "The provided user does not exist", "accountNonExistent": "The provided user does not exist",
"unmatchingPassword": "The provided password does not match", "unmatchingPassword": "The provided password does not match",
"passwordNotMatchingConfirmPassword": "Password must match confirm password",
"confirmPassword": "Confirm Password",
"registrationAgeWarning": "By registering, you confirm you are of 13 years of age or older.",
"backToLogin": "Back to Login",
"failedToLoadSaveData": "Failed to load save data. Please reload the page.\nIf this continues, please contact the administrator.", "failedToLoadSaveData": "Failed to load save data. Please reload the page.\nIf this continues, please contact the administrator.",
"sessionSuccess": "Session loaded successfully.", "sessionSuccess": "Session loaded successfully.",
"failedToLoadSession": "Your session data could not be loaded.\nIt may be corrupted.", "failedToLoadSession": "Your session data could not be loaded.\nIt may be corrupted.",

View File

@ -12,11 +12,18 @@ export const menu: SimpleTranslationEntries = {
"password": "Mot de passe", "password": "Mot de passe",
"login": "Connexion", "login": "Connexion",
"register": "S'inscrire", "register": "S'inscrire",
"emptyUsername": "Le nom d'utilisateur ne doit pas être vide", "emptyUsername": "Le nom d'utilisateur est manquant",
"invalidUsername": "Le nom d'utilisateur n'est pas valide", "invalidLoginUsername": "Le nom d'utilisateur n'est pas valide",
"invalidPassword": "Le mot de passe n'est pas valide", "invalidRegisterUsername": "Le nom d'utilisateur ne doit contenir que \ndes lettres, chiffres ou traits bas",
"invalidLoginPassword": "Le mot de passe n'est pas valide",
"invalidRegisterPassword": "Le mot de passe doit contenir 6 caractères ou plus",
"usernameAlreadyUsed": "Le nom d'utilisateur est déjà utilisé",
"accountNonExistent": "Le nom d'utilisateur n'existe pas", "accountNonExistent": "Le nom d'utilisateur n'existe pas",
"unmatchingPassword": "Le mot de passe n'est pas correct", "unmatchingPassword": "Le mot de passe n'est pas correct",
"passwordNotMatchingConfirmPassword": "Les mots de passe ne correspondent pas",
"confirmPassword": "Confirmer le MDP",
"registrationAgeWarning": "Vous confirmez en vous inscrivant que vous avez 13 ans ou plus.",
"backToLogin": "Retour",
"failedToLoadSaveData": "Échec du chargement des données. Veuillez recharger la page.\nSi cela continue, veuillez contacter l'administrateur.", "failedToLoadSaveData": "Échec du chargement des données. Veuillez recharger la page.\nSi cela continue, veuillez contacter l'administrateur.",
"sessionSuccess": "Session chargée avec succès.", "sessionSuccess": "Session chargée avec succès.",
"failedToLoadSession": "Vos données de session n'ont pas pu être chargées.\nElles pourraient être corrompues.", "failedToLoadSession": "Vos données de session n'ont pas pu être chargées.\nElles pourraient être corrompues.",

View File

@ -31,9 +31,9 @@ export default class LoginFormUiHandler extends FormModalUiHandler {
error = error.slice(0, colonIndex); error = error.slice(0, colonIndex);
switch (error) { switch (error) {
case 'invalid username': case 'invalid username':
return i18next.t('menu:invalidUsername'); return i18next.t('menu:invalidLoginUsername');
case 'invalid password': case 'invalid password':
return i18next.t('menu:invalidPassword'); return i18next.t('menu:invalidLoginPassword');
case 'account doesn\'t exist': case 'account doesn\'t exist':
return i18next.t('menu:accountNonExistent'); return i18next.t('menu:accountNonExistent');
case 'password doesn\'t match': case 'password doesn\'t match':

View File

@ -3,14 +3,15 @@ import { ModalConfig } from "./modal-ui-handler";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { Mode } from "./ui"; import { Mode } from "./ui";
import { TextStyle, addTextObject } from "./text"; import { TextStyle, addTextObject } from "./text";
import i18next from '../plugins/i18n';
export default class RegistrationFormUiHandler extends FormModalUiHandler { export default class RegistrationFormUiHandler extends FormModalUiHandler {
getModalTitle(config?: ModalConfig): string { getModalTitle(config?: ModalConfig): string {
return 'Register'; return i18next.t('menu:register');
} }
getFields(config?: ModalConfig): string[] { getFields(config?: ModalConfig): string[] {
return [ 'Username', 'Password', 'Confirm Password' ]; return [ i18next.t('menu:username'), i18next.t('menu:password'), i18next.t('menu:confirmPassword') ];
} }
getWidth(config?: ModalConfig): number { getWidth(config?: ModalConfig): number {
@ -26,7 +27,7 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
} }
getButtonLabels(config?: ModalConfig): string[] { getButtonLabels(config?: ModalConfig): string[] {
return [ 'Register', 'Back to Login' ]; return [ i18next.t('menu:register'), i18next.t('menu:backToLogin') ];
} }
getReadableErrorMessage(error: string): string { getReadableErrorMessage(error: string): string {
@ -35,11 +36,11 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
error = error.slice(0, colonIndex); error = error.slice(0, colonIndex);
switch (error) { switch (error) {
case 'invalid username': case 'invalid username':
return 'Username must only contain letters, numbers, or underscores'; return i18next.t('menu:invalidRegisterUsername');
case 'invalid password': case 'invalid password':
return 'Password must be 6 characters or longer'; return i18next.t('menu:invalidRegisterPassword');
case 'failed to add account record': case 'failed to add account record':
return 'The provided username is already in use'; return i18next.t('menu:usernameAlreadyUsed');
} }
return super.getReadableErrorMessage(error); return super.getReadableErrorMessage(error);
@ -48,7 +49,7 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
setup(): void { setup(): void {
super.setup(); super.setup();
const label = addTextObject(this.scene, 10, 87, 'By registering, you confirm you are of 13 years of age or older.', TextStyle.TOOLTIP_CONTENT, { fontSize: '42px' }); const label = addTextObject(this.scene, 10, 87, i18next.t('menu:registrationAgeWarning'), TextStyle.TOOLTIP_CONTENT, { fontSize: '42px' });
this.modalContainer.add(label); this.modalContainer.add(label);
} }
@ -68,11 +69,11 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
this.scene.ui.playError(); this.scene.ui.playError();
}; };
if (!this.inputs[0].text) if (!this.inputs[0].text)
return onFail('Username must not be empty'); return onFail(i18next.t('menu:emptyUsername'));
if (!this.inputs[1].text) if (!this.inputs[1].text)
return onFail(this.getReadableErrorMessage('invalid password')); return onFail(this.getReadableErrorMessage('invalid password'));
if (this.inputs[1].text !== this.inputs[2].text) if (this.inputs[1].text !== this.inputs[2].text)
return onFail('Password must match confirm password'); return onFail(i18next.t('menu:passwordNotMatchingConfirmPassword'));
const contentType = 'application/x-www-form-urlencoded'; const contentType = 'application/x-www-form-urlencoded';
const headers = { const headers = {
'Content-Type': contentType, 'Content-Type': contentType,