feat(i18n): initialize internationalization and update Vite config for locale handling

- Added `initI18n` function call in `main.tsx` to bootstrap internationalization before rendering the app.
- Updated Vite configuration to handle specific locale files for English and Chinese.
This commit is contained in:
shuaiplus
2026-04-29 02:49:45 +08:00
parent 3c5f43ecc2
commit 29a846c562
12 changed files with 2138 additions and 1828 deletions
+27 -2
View File
@@ -382,12 +382,37 @@ export async function getPasswordHint(email: string): Promise<{ masterPasswordHi
export function createAuthedFetch(getSession: () => SessionState | null, setSession: SessionSetter) {
return async function authedFetch(input: string, init: RequestInit = {}): Promise<Response> {
const retryableRequest = async (headers: Headers): Promise<Response> => {
const maxAttempts = 3;
let lastError: unknown;
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
try {
const response = await fetch(input, { ...init, headers });
if (response.status !== 429 && (response.status < 500 || response.status >= 600)) {
return response;
}
lastError = new Error(`HTTP ${response.status}`);
if (attempt === maxAttempts - 1) {
return response;
}
} catch (error) {
lastError = error;
if (attempt === maxAttempts - 1) {
throw error;
}
}
const delayMs = 250 * (2 ** attempt) + Math.floor(Math.random() * 120);
await new Promise((resolve) => window.setTimeout(resolve, delayMs));
}
throw lastError instanceof Error ? lastError : new Error('Request failed');
};
const session = getSession();
if (!session?.accessToken) throw new Error('Unauthorized');
const headers = new Headers(init.headers || {});
headers.set('Authorization', `Bearer ${session.accessToken}`);
let resp = await fetch(input, { ...init, headers });
let resp = await retryableRequest(headers);
if (resp.status !== 401 || (!session.refreshToken && session.authMode !== 'web-cookie')) return resp;
const refreshed = await refreshAccessToken(session);
@@ -410,7 +435,7 @@ export function createAuthedFetch(getSession: () => SessionState | null, setSess
const retryHeaders = new Headers(init.headers || {});
retryHeaders.set('Authorization', `Bearer ${nextSession.accessToken}`);
resp = await fetch(input, { ...init, headers: retryHeaders });
resp = await retryableRequest(retryHeaders);
return resp;
};
}