feat: add localizable error messages

This commit is contained in:
Xylight committed 2024-07-31 20:27:47 -07:00
1 parent cee02cbc99
commit f386ba94a6
5 files changed
+51 -3

No files matched your search

BIN
View File
Binary file not shown.
+14
View File
@@ -780,5 +780,19 @@
"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": "..."
}
}
+16
View File
@@ -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
}
}
+7 -1
View File
@@ -16,7 +16,13 @@
themeVars,
} from '$lib/ui/colors.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 { browser } from '$app/environment'
import { Forward, Icon } from 'svelte-hero-icons'
+14 -2
View File
@@ -20,6 +20,7 @@
import { MINIMUM_VERSION } from '$lib/version.js'
import { t } from '$lib/translations'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { errorMessage } from '$lib/lemmy/error'
let data = {
instance: DEFAULT_INSTANCE_URL,
@@ -27,6 +28,7 @@
password: '',
totp: '',
loading: false,
attempts: 0,
}
async function logIn() {
@@ -56,16 +58,26 @@
}
} catch (error) {
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',
})
data.attempts++
}
data.loading = false
}
</script>
<svelte:head>
<title>Login</title>
<title>{$t('account.login')}</title>
</svelte:head>
<div class="max-w-xl w-full mx-auto h-max my-auto">