More settings localization

This commit is contained in:
Sean Morley
2024-11-03 15:45:29 -05:00
parent 4bbbc10097
commit c0aaec1436
13 changed files with 464 additions and 284 deletions

View File

@@ -10,7 +10,7 @@ export const actions: Actions = {
const email = formData.get('email') as string | null | undefined;
if (!email) {
return fail(400, { message: 'Email is required' });
return fail(400, { message: 'missing_email' });
}
let res = await fetch(`${endpoint}/auth/password/reset/`, {

View File

@@ -1,29 +1,29 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { page } from '$app/stores';
import { t } from 'svelte-i18n';
</script>
<h1 class="text-center font-extrabold text-4xl mb-6">Reset Password</h1>
<h1 class="text-center font-extrabold text-4xl mb-6">{$t('settings.reset_password')}</h1>
<div class="flex justify-center">
<form method="post" action="?/forgotPassword" class="w-full max-w-xs" use:enhance>
<label for="email">Email</label>
<label for="email">{$t('auth.email')}</label>
<input
name="email"
type="email"
id="email"
class="block mb-2 input input-bordered w-full max-w-xs"
/><br />
<button class="py-2 px-4 btn btn-primary mr-2">Reset Password</button>
<button class="py-2 px-4 btn btn-primary mr-2">{$t('settings.reset_password')}</button>
{#if $page.form?.message}
<div class="text-center text-error mt-4">
{$page.form?.message}
{$t(`settings.${$page.form?.message}`)}
</div>
{/if}
{#if $page.form?.success}
<div class="text-center text-success mt-4">
If the email address you provided is associated with an account, you will receive an email
with instructions to reset your password!
{$t('settings.possible_reset')}
</div>
{/if}
</form>

View File

@@ -25,11 +25,11 @@ export const actions: Actions = {
const uid = formData.get('uid') as string;
if (!new_password1 || !new_password2) {
return fail(400, { message: 'Password is required' });
return fail(400, { message: 'settings.password_is_required' });
}
if (new_password1 !== new_password2) {
return fail(400, { message: 'Passwords do not match' });
return fail(400, { message: 'settings.password_does_not_match' });
}
if (!token || !uid) {
@@ -48,9 +48,7 @@ export const actions: Actions = {
})
});
if (!response.ok) {
let responseJson = await response.json();
const key = Object.keys(responseJson)[0];
return fail(response.status, { message: responseJson[key] });
return fail(response.status, { message: 'settings.invalid_token' });
} else {
return redirect(302, '/login');
}

View File

@@ -3,14 +3,15 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import type { PageData } from './$types';
import { t } from 'svelte-i18n';
export let data: PageData;
</script>
<h1 class="text-center font-bold text-4xl mb-4">Change Password</h1>
<h1 class="text-center font-bold text-4xl mb-4">{$t('settings.change_password')}</h1>
{#if data.props.token && data.props.uid}
<p class="text-center">You will then be redirected to the login page.</p>
<p class="text-center">{$t('settings.login_redir')}</p>
<div
class="modal-action items-center"
style="display: flex; flex-direction: column; align-items: center; width: 100%;"
@@ -25,7 +26,7 @@
class="input input-bordered w-full"
id="new_password1"
name="new_password1"
placeholder="New Password"
placeholder={$t('settings.new_password')}
/>
</div>
<div class="mb-2 w-full">
@@ -34,13 +35,13 @@
class="input input-bordered w-full"
id="new_password2"
name="new_password2"
placeholder="Confirm Password"
placeholder={$t('settings.confirm_new_password')}
/>
</div>
<button type="submit" class="btn btn-primary w-full">Submit</button>
<button type="submit" class="btn btn-primary w-full">{$t('settings.submit')}</button>
{#if $page.form?.message}
<div class="text-center text-error mt-4">
{$page.form?.message}
{$t($page.form?.message)}
</div>
{/if}
</form>
@@ -48,10 +49,10 @@
{:else}
<div class="flex justify-center">
<div class="items-center justify-center">
<p class="text-center">Token and UID are required for password reset.</p>
<p class="text-center">{$t('settings.token_required')}</p>
<button class="btn btn-neutral" on:click={() => goto('/settings/forgot-password')}>
Reset Password
{$t('settings.reset_password')}
</button>
</div>
</div>