feat(i18n): add localized content for authentication error

This commit is contained in:
neilchen0812 committed 2026-09-21 22:49:27 +09:30
1 parent bd1d5af699
commit 013a5acaa7
5 files changed
+46 -15

No files matched your search

+10
View File
@@ -55,5 +55,15 @@
"not_registered": "Don't have an account?",
"continue_as_guest": "Continue as Guest",
"password_rules": "At least 8 characters, including uppercase and lowercase letters and numbers"
},
"authform_error": {
"too_many_requests": "Too many requests, please try again in 2 minutes",
"unauthorized": "Invalid username or password",
"auth_failed": "Something went wrong",
"invalid_username": "Invalid username",
"invalid_email": "Invalid email",
"invalid_password": "Invalid password",
"username_taken": "Username is already taken",
"email_taken": "Email is already taken"
}
}
+10
View File
@@ -55,5 +55,15 @@
"not_registered": "還沒有帳號嗎?",
"continue_as_guest": "以訪客身分繼續",
"password_rules": "至少 8 個字元,包含數字及大小寫字母"
},
"authform_error": {
"too_many_requests": "太多請求,兩分鐘後再試一次",
"unauthorized": "無效的帳號名稱或密碼",
"auth_failed": "出了點問題",
"invalid_username": "無效的帳號名稱",
"invalid_email": "無效的電子郵件",
"invalid_password": "無效的密碼",
"username_taken": "帳號名稱已被使用",
"email_taken": "電子郵件已被使用"
}
}
+8 -3
View File
@@ -1,4 +1,5 @@
import api from './api'
import { i18n } from '../i18n'
import {
TooManyRequestsError,
@@ -32,11 +33,15 @@ function handleRequestError(err: {
const { path, msg } = errors[0]
switch (path) {
case 'username':
throw new ValidationError('Username is already taken')
throw new ValidationError(
i18n.global.t('authform_error.username_taken')
)
case 'email':
throw new ValidationError('Email is already taken')
throw new ValidationError(i18n.global.t('authform_error.email_taken'))
case 'password':
throw new ValidationError('Password is too weak')
throw new ValidationError(
i18n.global.t('authform_error.invalid_password')
)
default:
throw new ValidationError(msg)
}
+7 -4
View File
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import AuthForm from '../components/AuthForm.vue'
import DynamicBackground from '../components/DynamicBackground.vue'
import HeaderPart from '../components/header/HeaderPart.vue'
@@ -10,6 +11,8 @@ import {
} from '../utils/errors'
import { login } from '../utils/auth'
const { t } = useI18n()
const handleLogin = async ({
username,
password,
@@ -27,19 +30,19 @@ const handleLogin = async ({
if (isSuccess) success()
} catch (err) {
if (err instanceof TooManyRequestsError) {
error('太多請求,兩分鐘後再試一次。')
error(t('authform_error.too_many_requests'))
return
}
if (err instanceof UnauthorizedError) {
error('錯誤的帳號名稱或密碼。')
error(t('authform_error.unauthorized'))
return
}
if (err instanceof ValidationError) {
error('無效的帳號名稱或密碼。')
error(err.message)
return
}
console.error(err)
error('出了點問題。')
error(t('authform_error.auth_failed'))
}
}
</script>
+11 -8
View File
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import validator from 'validator'
import { isValidUsername } from '../../../packages/utils'
import { passwordPolicy } from '../../../packages/constants'
@@ -12,6 +13,8 @@ import {
ValidationError,
} from '../utils/errors'
const { t } = useI18n()
function handleRegister({
username,
email,
@@ -30,11 +33,11 @@ function handleRegister({
.then(success)
.catch((err) => {
if (err instanceof TooManyRequestsError) {
error('太多請求,兩分鐘後再試一次。')
error(t('authform_error.too_many_requests'))
return
}
if (err instanceof UnauthorizedError) {
error('無效的帳號名稱或密碼。')
error(t('authform_error.unauthorized'))
return
}
if (err instanceof ValidationError) {
@@ -42,7 +45,7 @@ function handleRegister({
return
}
console.error(err)
error('出了點問題。')
error(t('authform_error.auth_failed'))
})
}
@@ -59,15 +62,15 @@ async function check({
error: (msg: string) => void
}) {
if (username && !isValidUsername(username)) {
error('無效的帳號名稱')
error(t('authform_error.invalid_username'))
return
}
if (email && !validator.isEmail(email)) {
error('無效的電子郵件')
error(t('authform_error.invalid_email'))
return
}
if (password && !validator.isStrongPassword(password, passwordPolicy)) {
error('密碼必須超過8個字元,至少包含一個數字、一個大寫及一個小寫。')
error(t('authform_error.invalid_password'))
return
}
try {
@@ -78,11 +81,11 @@ async function check({
return
}
if (err instanceof TooManyRequestsError) {
error('太多請求,兩分鐘後再試一次。')
error(t('authform_error.too_many_requests'))
return
}
console.error(err)
error('出了點問題。')
error(t('authform_error.registration_failed'))
}
}
</script>