mirror of https://github.com/hykilpikonna/AquaDX
[+] i18n
parent
52ec890e2c
commit
f3fabe1708
|
@ -0,0 +1,48 @@
|
|||
|
||||
const EN_REF = {
|
||||
'back': 'Back',
|
||||
'welcome.btn-login': 'Log in',
|
||||
'welcome.btn-signup': 'Sign up',
|
||||
'welcome.email-password-missing': 'Email and password are required',
|
||||
'welcome.username-missing': 'Username/email is required',
|
||||
'welcome.waiting-turnstile': 'Waiting for Turnstile to verify your network environment...',
|
||||
'welcome.turnstile-error': 'Error verifying your network environment. Please turn off your VPN and try again.',
|
||||
'welcome.turnstile-timeout': 'Network verification timed out. Please try again.',
|
||||
'welcome.verification-sent': 'A verification email has been sent to ${email}. Please check your inbox!',
|
||||
'welcome.verify-state-0': "You haven't verified your email. A verification email had been sent to your inbox less than a minute ago. Please check your inbox!",
|
||||
'welcome.verify-state-1': "You haven't verified your email. We've already sent 3 emails over the last 24 hours so we'll not send another one. Please check your inbox!",
|
||||
'welcome.verify-state-2': "You haven't verified your email. We just sent you another verification email. Please check your inbox!",
|
||||
'welcome.verifying': "Verifying your email... please wait.",
|
||||
'welcome.verified': "Your email has been verified! You can now log in now.",
|
||||
'welcome.verification-failed': 'Verification failed: ${message}. Please try again.',
|
||||
}
|
||||
|
||||
const msgs: { [index: string]: typeof EN_REF } = {
|
||||
en: EN_REF,
|
||||
zh: {
|
||||
'back': '返回',
|
||||
'welcome.btn-login': '登录',
|
||||
'welcome.btn-signup': '注册',
|
||||
'welcome.email-password-missing': '邮箱和密码必须填哦',
|
||||
'welcome.username-missing': '用户名/邮箱必须填哦',
|
||||
'welcome.waiting-turnstile': '正在验证网络环境...',
|
||||
'welcome.turnstile-error': '验证网络环境出错了,请关闭VPN后重试',
|
||||
'welcome.turnstile-timeout': '验证网络环境超时了,请重试',
|
||||
'welcome.verification-sent': '验证邮件已发送至 ${email},请翻翻收件箱',
|
||||
'welcome.verify-state-0': '您还没有验证邮箱哦!验证邮件一分钟内刚刚发到您的邮箱,请翻翻收件箱',
|
||||
'welcome.verify-state-1': '您还没有验证邮箱哦!我们在过去的24小时内已经发送了3封验证邮件,所以我们不会再发送了,请翻翻收件箱',
|
||||
'welcome.verify-state-2': '您还没有验证邮箱哦!我们刚刚又发送了一封验证邮件,请翻翻收件箱',
|
||||
'welcome.verifying': '正在验证邮箱...请稍等',
|
||||
'welcome.verified': '您的邮箱已经验证成功!您现在可以登录了',
|
||||
'welcome.verification-failed': '验证失败:${message}。请重试',
|
||||
}
|
||||
}
|
||||
|
||||
let lang = 'en'
|
||||
|
||||
export function t(key: keyof typeof EN_REF, variables?: { [index: string]: string }) {
|
||||
if (variables) {
|
||||
return msgs[lang][key].replace(/\${(.*?)}/g, (_, v) => variables[v])
|
||||
}
|
||||
return msgs[lang][key]
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
import { TURNSTILE_SITE_KEY } from "../libs/config";
|
||||
import Icon from "@iconify/svelte";
|
||||
import { USER } from "../libs/sdk";
|
||||
import { t } from "../libs/i18n"
|
||||
|
||||
let params = new URLSearchParams(window.location.search)
|
||||
|
||||
|
@ -22,19 +23,19 @@
|
|||
|
||||
if (params.get('confirm-email')) {
|
||||
state = 'verify'
|
||||
verifyMsg = "Verifying your email... please wait."
|
||||
verifyMsg = t("welcome.verifying")
|
||||
submitting = true
|
||||
|
||||
// Send request to server
|
||||
USER.confirmEmail(params.get('confirm-email')!)
|
||||
.then(() => {
|
||||
verifyMsg = "Your email has been verified! You can now log in now."
|
||||
verifyMsg = t('welcome.verified')
|
||||
submitting = false
|
||||
|
||||
// Clear the query param
|
||||
window.history.replaceState({}, document.title, window.location.pathname)
|
||||
})
|
||||
.catch(e => verifyMsg = `Email verification failed: ${e.message}`)
|
||||
.catch(e => verifyMsg = t('welcome.verification-failed', { message: e.message }))
|
||||
}
|
||||
|
||||
async function submit(): Promise<any> {
|
||||
|
@ -42,20 +43,20 @@
|
|||
|
||||
// Check if username and password are valid
|
||||
if (email === "" || password === "") {
|
||||
error = "Please fill in all fields."
|
||||
error = t("welcome.email-password-missing")
|
||||
return submitting = false
|
||||
}
|
||||
|
||||
if (turnstile === "") {
|
||||
// Sleep for 100ms to allow Turnstile to finish
|
||||
error = "Waiting for Turnstile to verify your network environment..."
|
||||
error = t("welcome.waiting-turnstile")
|
||||
return setTimeout(submit, 100)
|
||||
}
|
||||
|
||||
// Signup
|
||||
if (isSignup) {
|
||||
if (username === "") {
|
||||
error = "Please fill in all fields."
|
||||
error = t("welcome.username-missing")
|
||||
return submitting = false
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@
|
|||
|
||||
// Show verify email message
|
||||
state = 'verify'
|
||||
verifyMsg = `A verification email has been sent to ${email}. Please check your inbox!`
|
||||
verifyMsg = t("welcome.verification-sent", { email })
|
||||
}
|
||||
else {
|
||||
// Send request to server
|
||||
|
@ -77,15 +78,15 @@
|
|||
.catch(e => {
|
||||
if (e.message === 'Email not verified - STATE_0') {
|
||||
state = 'verify'
|
||||
verifyMsg = "You haven't verified your email. A verification email had been sent to your inbox less than a minute ago. Please check your inbox!"
|
||||
verifyMsg = t("welcome.verify-state-0")
|
||||
}
|
||||
else if (e.message === 'Email not verified - STATE_1') {
|
||||
state = 'verify'
|
||||
verifyMsg = "You haven't verified your email. We've already sent 3 emails over the last 24 hours so we'll not send another one. Please check your inbox!"
|
||||
verifyMsg = t("welcome.verify-state-1")
|
||||
}
|
||||
else if (e.message === 'Email not verified - STATE_2') {
|
||||
state = 'verify'
|
||||
verifyMsg = "You haven't verified your email. We just sent you another verification email. Please check your inbox!"
|
||||
verifyMsg = t("welcome.verify-state-2")
|
||||
}
|
||||
else {
|
||||
error = e.message
|
||||
|
@ -105,8 +106,8 @@
|
|||
<h1 id="title">AquaNet</h1>
|
||||
{#if state === "home"}
|
||||
<div class="btn-group" transition:slide>
|
||||
<button on:click={() => state = 'login'}>Log in</button>
|
||||
<button on:click={() => state = 'signup'}>Sign up</button>
|
||||
<button on:click={() => state = 'login'}>{t('welcome.btn-login')}</button>
|
||||
<button on:click={() => state = 'signup'}>{t('welcome.btn-signup')}</button>
|
||||
</div>
|
||||
{:else if state === "login" || state === "signup"}
|
||||
<div class="login-form" transition:slide>
|
||||
|
@ -116,7 +117,7 @@
|
|||
<div on:click={() => state = 'home'} on:keypress={() => state = 'home'}
|
||||
role="button" tabindex="0" class="clickable">
|
||||
<Icon icon="line-md:chevron-small-left" />
|
||||
<span>Back</span>
|
||||
<span>{t('back')}</span>
|
||||
</div>
|
||||
{#if isSignup}
|
||||
<input type="text" placeholder="Username" bind:value={username}>
|
||||
|
@ -127,20 +128,20 @@
|
|||
{#if submitting}
|
||||
<Icon icon="line-md:loading-twotone-loop"/>
|
||||
{:else}
|
||||
{isSignup ? "Sign up" : "Log in"}
|
||||
{isSignup ? t('welcome.btn-signup') : t('welcome.btn-login')}
|
||||
{/if}
|
||||
</button>
|
||||
<Turnstile siteKey={TURNSTILE_SITE_KEY} bind:reset={turnstileReset}
|
||||
on:turnstile-callback={e => console.log(turnstile = e.detail.token)}
|
||||
on:turnstile-error={_ => console.log(error = "Error verifying your network environment. Please turn off your VPN and try again.")}
|
||||
on:turnstile-error={_ => console.log(error = t("welcome.turnstile-error"))}
|
||||
on:turnstile-expired={_ => window.location.reload()}
|
||||
on:turnstile-timeout={_ => console.log(error = "Network verification timed out. Please try again.")} />
|
||||
on:turnstile-timeout={_ => console.log(error = t('welcome.turnstile-timeout'))} />
|
||||
</div>
|
||||
{:else if state === "verify"}
|
||||
<div class="login-form" transition:slide>
|
||||
<span>{verifyMsg}</span>
|
||||
{#if !submitting}
|
||||
<button on:click={() => state = 'home'} transition:slide>Back</button>
|
||||
<button on:click={() => state = 'home'} transition:slide>{t('back')}</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
@ -245,4 +246,4 @@
|
|||
@media (max-width: 500px)
|
||||
align-items: center
|
||||
padding-left: 0
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$font: Quicksand, Inter, system-ui, Avenir, Helvetica, Arial, sans-serif
|
||||
$font: Quicksand, Inter, Microsoft YaHei, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Avenir, Helvetica, Arial, sans-serif
|
||||
$c-main: #b3c6ff
|
||||
$c-good: #b3ffb9
|
||||
$c-darker: #646cff
|
||||
|
|
Loading…
Reference in New Issue