feat: |Worker| support multi language (#584)

This commit is contained in:
Dream Hunter
2025-02-20 00:37:39 +08:00
committed by GitHub
parent 2426e0b51a
commit 7889d2edea
23 changed files with 911 additions and 850 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "cloudflare_temp_email",
"version": "0.8.7",
"version": "0.9.0",
"private": true,
"type": "module",
"scripts": {
@@ -40,13 +40,13 @@
"@vicons/material": "^0.13.0",
"@vitejs/plugin-vue": "^5.2.1",
"unplugin-auto-import": "^19.1.0",
"unplugin-vue-components": "^28.1.0",
"vite": "^6.1.0",
"unplugin-vue-components": "^28.4.0",
"vite": "^6.1.1",
"vite-plugin-pwa": "^0.21.1",
"vite-plugin-top-level-await": "^1.5.0",
"vite-plugin-wasm": "^3.4.1",
"workbox-build": "^7.3.0",
"workbox-window": "^7.3.0",
"wrangler": "^3.109.1"
"wrangler": "^3.109.2"
}
}

492
frontend/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,8 @@ import { useGlobalState } from '../store'
import { h } from 'vue'
import axios from 'axios'
import i18n from '../i18n'
const API_BASE = import.meta.env.VITE_API_BASE || "";
const {
loading, auth, jwt, settings, openSettings,
@@ -22,6 +24,7 @@ const apiFetch = async (path, options = {}) => {
method: options.method || 'GET',
data: options.body || null,
headers: {
'x-lang': i18n.global.locale.value,
'x-user-token': userJwt.value,
'x-user-access-token': userSettings.value.access_token,
'x-custom-auth': auth.value,
@@ -32,14 +35,12 @@ const apiFetch = async (path, options = {}) => {
});
if (response.status === 401 && path.startsWith("/admin")) {
showAdminAuth.value = true;
throw new Error("Unauthorized, your admin password is wrong")
}
if (response.status === 401 && openSettings.value.auth) {
showAuth.value = true;
throw new Error("Unauthorized, you access password is wrong")
}
if (response.status >= 300) {
throw new Error(`${response.status} ${response.data}` || "error");
throw new Error(`[${response.status}]: ${response.data}` || "error");
}
const data = response.data;
return data;

15
frontend/src/i18n.ts Normal file
View File

@@ -0,0 +1,15 @@
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
legacy: false, // you must set `false`, to use Composition API
locale: 'zh', // set locale
fallbackLocale: 'en', // set fallback locale
'en': {
messages: {}
},
'zh': {
messages: {}
}
})
export default i18n;

View File

@@ -1,20 +1,9 @@
import { createApp } from 'vue'
import App from './App.vue'
import { createI18n } from 'vue-i18n'
import router from './router'
import { createHead } from '@unhead/vue'
const i18n = createI18n({
legacy: false, // you must set `false`, to use Composition API
locale: 'zh', // set locale
fallbackLocale: 'en', // set fallback locale
'en': {
messages: {}
},
'zh': {
messages: {}
}
})
import i18n from './i18n'
router.beforeEach((to, from) => {
if (to.params.lang && ['en', 'zh'].includes(to.params.lang)) {