Skip to content

Commit 2979751

Browse files
committed
feat(extension): 同步文档标题动态化功能
- 与 web 包保持一致,实现扩展popup的标题国际化 - 自动设置 HTML lang 属性
1 parent 5bca0c1 commit 2979751

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/extension/src/main.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createApp } from 'vue'
2-
import { installI18nOnly } from '@prompt-optimizer/ui'
1+
import { createApp, watch } from 'vue'
2+
import { installI18nOnly, i18n } from '@prompt-optimizer/ui'
33
import App from './App.vue'
44

55
import './style.css'
@@ -8,4 +8,18 @@ import '@prompt-optimizer/ui/dist/style.css'
88
const app = createApp(App)
99
// 只安装i18n插件,语言初始化将在App.vue中服务准备好后进行
1010
installI18nOnly(app)
11+
12+
// 同步文档标题和语言属性
13+
if (typeof document !== 'undefined') {
14+
const syncDocumentTitle = () => {
15+
document.title = i18n.global.t('common.appName')
16+
const currentLocale = String(i18n.global.locale.value || '')
17+
const htmlLang = currentLocale.startsWith('zh') ? 'zh' : 'en'
18+
document.documentElement.setAttribute('lang', htmlLang)
19+
}
20+
21+
syncDocumentTitle()
22+
watch(i18n.global.locale, syncDocumentTitle)
23+
}
24+
1125
app.mount('#app')

0 commit comments

Comments
 (0)