feat: add localizable error messages
This commit is contained in:
1 parent
cee02cbc99
commit
f386ba94a6
5 files changed
+51
-3
No files matched your search
@@ -780,5 +780,19 @@
|
|||||||
"description": "Display debug information"
|
"description": "Display debug information"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"incorrect_login": "Incorrect login credentials. Please try again.",
|
||||||
|
"incorrect_login_2": "Incorrect login credentials. Try again.",
|
||||||
|
"incorrect_login_3": "Incorrect, again. Try a few more times.",
|
||||||
|
"incorrect_login_4": "Those still aren't the right credentials. Keep trying.",
|
||||||
|
"incorrect_login_5": "I swear, you need to look at the keys you're pressing.",
|
||||||
|
"incorrect_login_6": "Is this a joke to you?",
|
||||||
|
"incorrect_login_7": "Either you struggle with typing or you're harassing me at this point.",
|
||||||
|
"incorrect_login_8": "I give up.",
|
||||||
|
"incorrect_login_9": "Each of these requests you make are sending data through via an incredible technology. And you're using it to make failed logins.",
|
||||||
|
"incorrect_login_10": "Think about this. The poor instance admins have to maintain their server just for you to make these useless requests.",
|
||||||
|
"incorrect_login_11": "I give up, for real this time.",
|
||||||
|
"incorrect_login_12": "..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
|
export function errorMessage(error: any, instance?: string): string {
|
||||||
|
try {
|
||||||
|
if (error?.body?.message) {
|
||||||
|
error = JSON.parse(error?.body?.message).error
|
||||||
|
} else if (error?.message) {
|
||||||
|
error = error?.message
|
||||||
|
}
|
||||||
|
if (!error) throw error
|
||||||
|
|
||||||
|
return t.get(`error.${error}`)
|
||||||
|
} catch (e) {
|
||||||
|
return error as any
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,13 @@
|
|||||||
themeVars,
|
themeVars,
|
||||||
} from '$lib/ui/colors.js'
|
} from '$lib/ui/colors.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
import {
|
||||||
|
Button,
|
||||||
|
ModalContainer,
|
||||||
|
Spinner,
|
||||||
|
toast,
|
||||||
|
ToastContainer,
|
||||||
|
} from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { Forward, Icon } from 'svelte-hero-icons'
|
import { Forward, Icon } from 'svelte-hero-icons'
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
import { MINIMUM_VERSION } from '$lib/version.js'
|
import { MINIMUM_VERSION } from '$lib/version.js'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: DEFAULT_INSTANCE_URL,
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
password: '',
|
password: '',
|
||||||
totp: '',
|
totp: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
|
attempts: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logIn() {
|
async function logIn() {
|
||||||
@@ -56,16 +58,26 @@
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
content: error as any,
|
content:
|
||||||
|
JSON.parse((error as any)?.body?.message ?? '{}')?.error ==
|
||||||
|
'incorrect_login'
|
||||||
|
? errorMessage(
|
||||||
|
'incorrect_login' +
|
||||||
|
(data.attempts == 0 || data.attempts >= 12
|
||||||
|
? ''
|
||||||
|
: `_${data.attempts + 1}`)
|
||||||
|
)
|
||||||
|
: errorMessage(error),
|
||||||
type: 'error',
|
type: 'error',
|
||||||
})
|
})
|
||||||
|
data.attempts++
|
||||||
}
|
}
|
||||||
data.loading = false
|
data.loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Login</title>
|
<title>{$t('account.login')}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="max-w-xl w-full mx-auto h-max my-auto">
|
<div class="max-w-xl w-full mx-auto h-max my-auto">
|
||||||
|
|||||||
Reference in new issue
Block a user