mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 23:04:24 +08:00
fix(i18n): use English runtime text and localize system UI
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getRuntimeTranslator, runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* API 错误类型定义
|
||||
*/
|
||||
@@ -22,7 +23,11 @@ export class ApiErrorBase extends Error {
|
||||
* 网络错误
|
||||
*/
|
||||
export class NetworkError extends ApiErrorBase {
|
||||
constructor(message = '网络连接失败,请检查您的网络') {
|
||||
constructor(
|
||||
message = runtimeText(
|
||||
'network_connection_failed_check_your_network_cbf47b07',
|
||||
),
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'NetworkError';
|
||||
Object.setPrototypeOf(this, NetworkError.prototype);
|
||||
@@ -33,7 +38,9 @@ export class NetworkError extends ApiErrorBase {
|
||||
* 超时错误
|
||||
*/
|
||||
export class TimeoutError extends ApiErrorBase {
|
||||
constructor(message = '请求超时,请稍后重试') {
|
||||
constructor(
|
||||
message = runtimeText('request_timed_out_try_again_later_6c3465f6'),
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'TimeoutError';
|
||||
Object.setPrototypeOf(this, TimeoutError.prototype);
|
||||
@@ -44,7 +51,7 @@ export class TimeoutError extends ApiErrorBase {
|
||||
* 未授权错误 (401)
|
||||
*/
|
||||
export class UnauthorizedError extends ApiErrorBase {
|
||||
constructor(message = '未授权,请先登录') {
|
||||
constructor(message = runtimeText('unauthorized_sign_in_first_466879f5')) {
|
||||
super(message, 'UNAUTHORIZED', 401);
|
||||
this.name = 'UnauthorizedError';
|
||||
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
||||
@@ -55,7 +62,11 @@ export class UnauthorizedError extends ApiErrorBase {
|
||||
* 权限不足错误 (403)
|
||||
*/
|
||||
export class ForbiddenError extends ApiErrorBase {
|
||||
constructor(message = '权限不足', code = 'FORBIDDEN', details?: unknown) {
|
||||
constructor(
|
||||
message = runtimeText('insufficient_permissions_5e3c8a26'),
|
||||
code = 'FORBIDDEN',
|
||||
details?: unknown,
|
||||
) {
|
||||
super(message, code, 403, details);
|
||||
this.name = 'ForbiddenError';
|
||||
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
||||
@@ -66,7 +77,9 @@ export class ForbiddenError extends ApiErrorBase {
|
||||
* 资源未找到错误 (404)
|
||||
*/
|
||||
export class NotFoundError extends ApiErrorBase {
|
||||
constructor(message = '请求的资源不存在') {
|
||||
constructor(
|
||||
message = runtimeText('the_requested_resource_was_not_found_aecc0681'),
|
||||
) {
|
||||
super(message, 'NOT_FOUND', 404);
|
||||
this.name = 'NotFoundError';
|
||||
Object.setPrototypeOf(this, NotFoundError.prototype);
|
||||
@@ -77,7 +90,10 @@ export class NotFoundError extends ApiErrorBase {
|
||||
* 服务器错误 (5xx)
|
||||
*/
|
||||
export class ServerError extends ApiErrorBase {
|
||||
constructor(message = '服务器内部错误,请稍后重试', statusCode = 500) {
|
||||
constructor(
|
||||
message = runtimeText('internal_server_error_try_again_later_4f0dd7e9'),
|
||||
statusCode = 500,
|
||||
) {
|
||||
super(message, 'SERVER_ERROR', statusCode);
|
||||
this.name = 'ServerError';
|
||||
Object.setPrototypeOf(this, ServerError.prototype);
|
||||
@@ -88,7 +104,10 @@ export class ServerError extends ApiErrorBase {
|
||||
* 验证错误 (400)
|
||||
*/
|
||||
export class ValidationError extends ApiErrorBase {
|
||||
constructor(message = '请求参数验证失败', details?: unknown) {
|
||||
constructor(
|
||||
message = runtimeText('request_parameter_validation_failed_60ef7c51'),
|
||||
details?: unknown,
|
||||
) {
|
||||
super(message, 'VALIDATION_ERROR', 400, details);
|
||||
this.name = 'ValidationError';
|
||||
Object.setPrototypeOf(this, ValidationError.prototype);
|
||||
@@ -107,6 +126,10 @@ export function isCancelError(error: unknown): boolean {
|
||||
(('__CANCEL__' in error &&
|
||||
(error as { __CANCEL__?: boolean }).__CANCEL__ === true) ||
|
||||
('message' in error &&
|
||||
(error as { message?: string }).message === '请求已被取消'))
|
||||
(['en', 'zh-CN'] as const).some(
|
||||
(locale) =>
|
||||
(error as { message?: string }).message ===
|
||||
getRuntimeTranslator(locale)('request_canceled_5892f9b1'),
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user