Refactor PWA install steps to use dynamic translation keys

Co-authored-by: jxxghp <jxxghp@163.com>
This commit is contained in:
Cursor Agent
2025-07-08 06:19:07 +00:00
parent 59ee3d8ceb
commit 396ab64874
6 changed files with 18110 additions and 1879 deletions

16626
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -62,31 +62,7 @@ const dismissBanner = () => {
localStorage.setItem('pwa-install-dismissed', new Date().toISOString()) localStorage.setItem('pwa-install-dismissed', new Date().toISOString())
} }
// 从编译对象中提取文本
const extractText = (obj: any): string => {
// 如果是字符串直接返回
if (typeof obj === 'string') return obj
// 如果是对象,尝试多种方式获取文本
if (obj) {
// 尝试获取编译对象中的静态文本
if (obj.body?.static) return obj.body.static
// 尝试获取源文本
if (obj.source) return obj.source
// 尝试获取文本属性
if (obj.text) return obj.text
// 尝试获取值属性
if (obj.value) return obj.value
// 如果对象可以转换为字符串
if (obj.toString && typeof obj.toString === 'function' && obj.toString() !== '[object Object]') {
return obj.toString()
}
}
// 如果都获取不到,返回空字符串
console.warn('Failed to extract text from object:', obj)
return ''
}
// 获取平台特定的安装说明 // 获取平台特定的安装说明
const instructions = computed(() => { const instructions = computed(() => {
@@ -96,11 +72,26 @@ const instructions = computed(() => {
// 获取平台显示名称 // 获取平台显示名称
const platformName = t(`pwa.platforms.${platformKey}`) const platformName = t(`pwa.platforms.${platformKey}`)
// 获取安装步骤 // 直接使用t函数获取安装步骤避免编译对象的问题
const currentLocale = unref(locale) as string const steps = []
const currentMessages = messages.value[currentLocale] || messages.value['zh-CN'] const maxSteps = 10 // 最大步骤数,防止无限循环
const rawSteps = (currentMessages as any).pwa?.installSteps?.[platformKey] || []
const steps = Array.isArray(rawSteps) ? rawSteps.map(extractText) : [] for (let i = 0; i < maxSteps; i++) {
try {
const stepKey = `pwa.installSteps.${platformKey}.${i}`
const stepText = t(stepKey)
// 如果返回的是键名本身,说明没有找到对应的翻译
if (stepText === stepKey) {
break
}
steps.push(stepText)
} catch (error) {
// 如果出现错误,说明没有更多步骤
break
}
}
return { return {
platform: platformName, platform: platformName,

View File

@@ -171,51 +171,51 @@ export default {
}, },
// Installation steps // Installation steps
installSteps: { installSteps: {
ios: [ ios: {
'Tap the share button at the bottom of the browser', 0: 'Tap the share button at the bottom of the browser',
'Select "Add to Home Screen"', 1: 'Select "Add to Home Screen"',
'Tap "Add" to confirm installation', 2: 'Tap "Add" to confirm installation',
], },
android: [ android: {
'Tap the browser menu (three dots)', 0: 'Tap the browser menu (three dots)',
'Select "Add to Home Screen" or "Install App"', 1: 'Select "Add to Home Screen" or "Install App"',
'Tap "Install" to confirm', 2: 'Tap "Install" to confirm',
], },
chrome: [ chrome: {
'Click the install icon in the address bar', 0: 'Click the install icon in the address bar',
'Or click "Install MoviePilot" in the browser menu', 1: 'Or click "Install MoviePilot" in the browser menu',
'Click "Install" to confirm', 2: 'Click "Install" to confirm',
], },
edge: [ edge: {
'Click the app icon in the address bar', 0: 'Click the app icon in the address bar',
'Select "Install this site as an app"', 1: 'Select "Install this site as an app"',
'Click "Install" to confirm', 2: 'Click "Install" to confirm',
], },
firefox: [ firefox: {
'Click the install icon in the address bar', 0: 'Click the install icon in the address bar',
'Select "Install"', 1: 'Select "Install"',
'Confirm installation to desktop', 2: 'Confirm installation to desktop',
], },
safari: [ safari: {
'Click the share button', 0: 'Click the share button',
'Select "Add to Home Screen"', 1: 'Select "Add to Home Screen"',
'Tap "Add" to confirm', 2: 'Tap "Add" to confirm',
], },
desktop: [ desktop: {
'Click the install icon in the address bar', 0: 'Click the install icon in the address bar',
'Select "Install App"', 1: 'Select "Install App"',
'Follow the prompts to complete installation', 2: 'Follow the prompts to complete installation',
], },
mobile: [ mobile: {
'Tap the browser menu', 0: 'Tap the browser menu',
'Select "Add to Home Screen"', 1: 'Select "Add to Home Screen"',
'Confirm installation', 2: 'Confirm installation',
], },
other: [ other: {
'Look for "Install" option in your browser', 0: 'Look for "Install" option in your browser',
'Usually in the address bar or menu', 1: 'Usually in the address bar or menu',
'Follow the prompts to complete installation', 2: 'Follow the prompts to complete installation',
], },
}, },
}, },
login: { login: {

View File

@@ -171,51 +171,51 @@ export default {
}, },
// 安装步骤 // 安装步骤
installSteps: { installSteps: {
ios: [ ios: {
'点击浏览器底部的分享按钮', 0: '点击浏览器底部的分享按钮',
'选择"添加到主屏幕"', 1: '选择"添加到主屏幕"',
'点击"添加"确认安装', 2: '点击"添加"确认安装',
], },
android: [ android: {
'点击浏览器菜单(三个点)', 0: '点击浏览器菜单(三个点)',
'选择"添加到主屏幕"或"安装应用"', 1: '选择"添加到主屏幕"或"安装应用"',
'点击"安装"确认', 2: '点击"安装"确认',
], },
chrome: [ chrome: {
'点击地址栏右侧的安装图标', 0: '点击地址栏右侧的安装图标',
'或者点击浏览器菜单中的"安装 MoviePilot"', 1: '或者点击浏览器菜单中的"安装 MoviePilot"',
'点击"安装"确认', 2: '点击"安装"确认',
], },
edge: [ edge: {
'点击地址栏右侧的"应用可用"图标', 0: '点击地址栏右侧的"应用可用"图标',
'在弹出的面板中点击"安装"按钮', 1: '在弹出的面板中点击"安装"按钮',
'在确认对话框中点击"安装"', 2: '在确认对话框中点击"安装"',
], },
firefox: [ firefox: {
'点击地址栏右侧的安装图标', 0: '点击地址栏右侧的安装图标',
'选择"安装"', 1: '选择"安装"',
'确认安装到桌面', 2: '确认安装到桌面',
], },
safari: [ safari: {
'点击分享按钮', 0: '点击分享按钮',
'选择"添加到主屏幕"', 1: '选择"添加到主屏幕"',
'点击"添加"确认', 2: '点击"添加"确认',
], },
desktop: [ desktop: {
'点击地址栏右侧的安装图标', 0: '点击地址栏右侧的安装图标',
'选择"安装应用"', 1: '选择"安装应用"',
'按照提示完成安装', 2: '按照提示完成安装',
], },
mobile: [ mobile: {
'点击浏览器菜单', 0: '点击浏览器菜单',
'选择"添加到主屏幕"', 1: '选择"添加到主屏幕"',
'确认安装', 2: '确认安装',
], },
other: [ other: {
'查找浏览器中的"安装"选项', 0: '查找浏览器中的"安装"选项',
'通常在地址栏或菜单中', 1: '通常在地址栏或菜单中',
'按照提示完成安装', 2: '按照提示完成安装',
], },
}, },
}, },
login: { login: {

View File

@@ -172,51 +172,51 @@ export default {
}, },
// 安裝步驟 // 安裝步驟
installSteps: { installSteps: {
ios: [ ios: {
'點擊瀏覽器底部的分享按鈕', 0: '點擊瀏覽器底部的分享按鈕',
'選擇"添加到主屏幕"', 1: '選擇"添加到主屏幕"',
'點擊"添加"確認安裝', 2: '點擊"添加"確認安裝',
], },
android: [ android: {
'點擊瀏覽器菜單(三個點)', 0: '點擊瀏覽器菜單(三個點)',
'選擇"添加到主屏幕"或"安裝應用"', 1: '選擇"添加到主屏幕"或"安裝應用"',
'點擊"安裝"確認', 2: '點擊"安裝"確認',
], },
chrome: [ chrome: {
'點擊地址欄右側的安裝圖標', 0: '點擊地址欄右側的安裝圖標',
'或者點擊瀏覽器菜單中的"安裝 MoviePilot"', 1: '或者點擊瀏覽器菜單中的"安裝 MoviePilot"',
'點擊"安裝"確認', 2: '點擊"安裝"確認',
], },
edge: [ edge: {
'點擊地址欄右側的應用圖標', 0: '點擊地址欄右側的應用圖標',
'選擇"安裝此站點為應用"', 1: '選擇"安裝此站點為應用"',
'點擊"安裝"確認', 2: '點擊"安裝"確認',
], },
firefox: [ firefox: {
'點擊地址欄右側的安裝圖標', 0: '點擊地址欄右側的安裝圖標',
'選擇"安裝"', 1: '選擇"安裝"',
'確認安裝到桌面', 2: '確認安裝到桌面',
], },
safari: [ safari: {
'點擊分享按鈕', 0: '點擊分享按鈕',
'選擇"添加到主屏幕"', 1: '選擇"添加到主屏幕"',
'點擊"添加"確認', 2: '點擊"添加"確認',
], },
desktop: [ desktop: {
'點擊地址欄右側的安裝圖標', 0: '點擊地址欄右側的安裝圖標',
'選擇"安裝應用"', 1: '選擇"安裝應用"',
'按照提示完成安裝', 2: '按照提示完成安裝',
], },
mobile: [ mobile: {
'點擊瀏覽器菜單', 0: '點擊瀏覽器菜單',
'選擇"添加到主屏幕"', 1: '選擇"添加到主屏幕"',
'確認安裝', 2: '確認安裝',
], },
other: [ other: {
'查找瀏覽器中的"安裝"選項', 0: '查找瀏覽器中的"安裝"選項',
'通常在地址欄或菜單中', 1: '通常在地址欄或菜單中',
'按照提示完成安裝', 2: '按照提示完成安裝',
], },
}, },
}, },
login: { login: {

3044
yarn.lock

File diff suppressed because it is too large Load Diff