Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: |Worker| support multi language #584

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<!-- markdownlint-disable-file MD004 MD024 MD034 MD036 -->
# CHANGE LOG

## main(v0.8.7)
## main(v0.9.0)

- feat: | Worker | 支持多语言

## v0.8.7

- fix: |UI| 修复移动设备日期显示问题
- feat: |Worker| 支持通过 `SMTP` 发送邮件, 使用 [zou-yu/worker-mailer](https://github.com/zou-yu/worker-mailer/blob/main/README_zh-CN.md)
Expand Down
8 changes: 4 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudflare_temp_email",
"version": "0.8.7",
"version": "0.9.0",
"private": true,
"type": "module",
"scripts": {
Expand Down Expand Up @@ -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 changes: 208 additions & 284 deletions frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 1 addition & 12 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions pages/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "temp-email-pages",
"version": "0.8.7",
"version": "0.9.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -11,6 +11,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"wrangler": "^3.109.1"
"wrangler": "^3.109.2"
}
}
4 changes: 2 additions & 2 deletions vitepress-docs/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "temp-mail-docs",
"private": true,
"version": "0.8.7",
"version": "0.9.0",
"type": "module",
"devDependencies": {
"@types/node": "^22.13.4",
"vitepress": "^1.6.3",
"wrangler": "^3.109.1"
"wrangler": "^3.109.2"
},
"scripts": {
"dev": "vitepress dev docs",
Expand Down
Loading