Skip to content

Commit

Permalink
refactor: 优化文本翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Aug 9, 2023
1 parent 5a28bf1 commit d2143a0
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 124 deletions.
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"arrowParens": "avoid",
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "none"
"singleQuote": true
}
44 changes: 7 additions & 37 deletions src/components/custom-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,66 @@ const { t } = useI18n()
const appStore = useAppStore()
/** 导航选项 */
const navItems = computed(() => [
{
name: 'home',
label: t('app.nav.home'),
icon: 'i-mdi:home'
},
{
name: 'activation',
label: t('app.nav.activate'),
label: t('main.module.activate'),
icon: 'i-mdi:microsoft-windows'
},
{
name: 'detection',
label: t('app.nav.check'),
label: t('main.module.tools'),
icon: 'i-mdi:check-network'
},
{
name: 'download',
label: t('app.nav.download'),
icon: 'i-mdi:folder-download'
},
{
name: 'guide',
label: t('app.nav.guide'),
icon: 'i-mdi:document'
},
{
name: 'monitor',
label: t('app.nav.monitor'),
icon: 'i-mdi:monitor-dashboard'
}
])
/** 路由 */
const router = useRouter()
/** 跳转页面 */
const redirectPage = (name: string) => {
router.push({ path: name === 'home' ? '/' : '/' + name })
}
/** 路径解析 */
const pathName = location.pathname.match(/\b\w+\b/g)
/** 导航选中项 */
const navSelected = ref([!pathName?.[0] ? 'home' : pathName?.[0]])
/** 主题选项 */
const themeItems = computed(() => [
{
lable: t('app.theme.auto'),
lable: t('main.theme.auto'),
value: 'auto',
icon: 'i-ic:round-brightness-auto'
},
{
lable: t('app.theme.dark'),
lable: t('main.theme.dark'),
value: 'dark',
icon: 'i-ic:round-dark-mode'
},
{
lable: t('app.theme.light'),
lable: t('main.theme.light'),
value: 'light',
icon: 'i-ic:round-light-mode'
}
])
/** 主题图标 */
const themeIcon = computed(() => {
return themeItems.value.find(item => item.value === appStore.theme)?.icon
})
/** 切换主题 */
const themeChange = val => (appStore.theme = val)
/** 语言选项 */
const languagesItems = computed(() => [
{
lable: t('app.languages.zh-cn'),
lable: t('main.languages.zh-cn'),
value: 'zh-cn',
icon: 'i-flag:cn-4x3'
},
{
lable: t('app.languages.en-us'),
lable: t('main.languages.en-us'),
value: 'en-us',
icon: 'i-flag:us-4x3'
}
])
/** 切换语言 */
const languagesChange = val => (appStore.languages = val)
</script>

Expand Down
42 changes: 42 additions & 0 deletions src/locales/en/activate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export default {
button: {
copy: 'Copy Script',
create: 'Create Script',
download: 'Download Script',
},
form: {
label: {
edition: 'Edition',
cpuarch: 'CPU Arch',
license: 'License Key',
product: 'Product',
service: 'KMS Server',
version: 'Version',
},
placeholder: {
edition: 'Please select edition',
product: 'Please select product',
service: 'Please select kms server',
version: 'Please select version',
},
},
message: {
error: 'Copy Failed',
success: 'Copy Success',
},
radio: {
x64: 'x64',
x86: 'x86',
},
sider: {
system: 'System',
software: 'Software',
},
table: {
columns: {
edition: 'Edition',
license: 'License Key',
product: 'Product',
},
},
}
12 changes: 4 additions & 8 deletions src/locales/en/main.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
export default {
author: 'ikxin',
nav: {
module: {
activate: 'Activate',
check: 'Check',
download: 'Download',
guide: 'Guide',
home: 'Home',
monitor: 'Monitor'
tools: 'Tools'
},
theme: {
auto: 'Auto Mode',
dark: 'Dark Mode',
light: 'Light Mode'
},
languages: {
'en-us': 'English',
'zh-cn': 'Simplified Chinese'
en: 'English',
zhCn: 'Simplified Chinese'
}
}
4 changes: 2 additions & 2 deletions src/views/activation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const selectedKeys = ref(pathName)
<i class="i-mdi:chevron-down inline-block" />
</template>
<template #icon><i class="i-mdi:server" /></template>
<template #title>{{ t('activate.sidebar.system') }}</template>
<template #title>{{ t('activate.sider.system') }}</template>
<AMenuItem key="windows" @click="router.push({ path: '/activation/windows' })">
<template #icon><i class="i-mdi:microsoft-windows" /></template>
<span>Windows</span>
Expand All @@ -36,7 +36,7 @@ const selectedKeys = ref(pathName)
<i class="i-mdi:chevron-down inline-block" />
</template>
<template #icon><i class="i-mdi:application-brackets" /></template>
<template #title>{{ t('activate.sidebar.software') }}</template>
<template #title>{{ t('activate.sider.software') }}</template>
<AMenuItem key="office" @click="router.push({ path: '/activation/office' })">
<template #icon><i class="i-mdi:microsoft-office" /></template>
<span>Office</span>
Expand Down
52 changes: 23 additions & 29 deletions src/views/activation/office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,50 @@ import { useScript } from '@/composables/useScript'
const { t } = useI18n()
/** 表单数据 */
const formData = reactive({
version: '',
product: '',
is64bus: false,
cpuarch: false,
service: 'kms.moeclub.org',
license: ''
license: '',
})
watchEffect(() => (formData.license = formData.product))
/** 表单校验规则 */
const formRules = computed((): Record<string, FieldRule | FieldRule[]> => {
return {
version: {
required: true,
message: t('activate.office.form-item.version.placeholder')
message: t('activate.form.placeholder.version'),
},
product: {
required: true,
message: t('activate.office.form-item.product.placeholder')
message: t('activate.form.placeholder.product'),
},
service: {
required: true,
message: t('activate.office.form-item.service.placeholder')
}
message: t('activate.form.placeholder.service'),
},
}
})
/** 激活脚本 */
const activateScript = computed(() => {
const path = formData.is64bus
const path = formData.cpuarch
? 'cd C:\\Program Files\\Microsoft Office\\Office16'
: 'cd C:\\Program Files (x86)\\Microsoft Office\\Office16'
const fix = `cscript ospp.vbs /inpkey:${formData.license}`
const activate = `cscript ospp.vbs /sethst:${formData.service}\r\ncscript ospp.vbs /act`
return `${path}\r\n${fix}\r\n${activate}`
})
/** 激活脚本显示 */
const activateScriptVisible = ref<boolean>(false)
/** 表单提交 */
const handleSubmit = data => {
if (data.errors === undefined) {
activateScriptVisible.value = true
}
}
/** 表格数据 */
const tableData = computed(() => {
if (!gvlks[formData.version]) return []
return gvlks[formData.version]?.product.map(item => {
Expand All @@ -64,9 +58,9 @@ const tableData = computed(() => {
const tableColumns = computed(
(): Array<TableColumnData> => [
{ title: t('activate.office.table.columns.product'), dataIndex: 'product' },
{ title: t('activate.office.table.columns.license'), dataIndex: 'license' }
]
{ title: t('activate.table.columns.product'), dataIndex: 'product' },
{ title: t('activate.table.columns.license'), dataIndex: 'license' },
],
)
const { useScriptDownload, useScriptCopy } = useScript()
Expand All @@ -80,13 +74,13 @@ const copyScript = () => useScriptCopy(activateScript.value)
<div class="flex flex-col gap-4">
<ACard title="Office">
<AForm :model="formData" :rules="formRules" @submit="handleSubmit" auto-label-width>
<AFormItem :label="t('activate.office.form-item.version.label')" field="version">
<ASelect v-model="formData.version" :placeholder="t('activate.office.form-item.version.placeholder')">
<AFormItem :label="t('activate.form.label.version')" field="version">
<ASelect v-model="formData.version" :placeholder="t('activate.form.placeholder.version')">
<AOption v-for="(item, key) in gvlks" :key="key" :label="item.version" :value="key" />
</ASelect>
</AFormItem>
<AFormItem :label="t('activate.office.form-item.product.label')" field="product">
<ASelect v-model="formData.product" :placeholder="t('activate.office.form-item.product.placeholder')">
<AFormItem :label="t('activate.form.label.product')" field="product">
<ASelect v-model="formData.product" :placeholder="t('activate.form.placeholder.product')">
<AOption
v-for="(item, index) in gvlks[formData.version]?.product"
:key="index"
Expand All @@ -95,24 +89,24 @@ const copyScript = () => useScriptCopy(activateScript.value)
/>
</ASelect>
</AFormItem>
<AFormItem :label="t('activate.office.form-item.is64bus.label')" field="is64bus">
<ARadioGroup v-model="formData.is64bus" type="button">
<ARadio :value="false">{{ t('activate.office.form-item.is64bus.radio.x86') }}</ARadio>
<ARadio :value="true">{{ t('activate.office.form-item.is64bus.radio.x64') }}</ARadio>
<AFormItem :label="t('activate.form.label.cpuarch')" field="cpuarch">
<ARadioGroup v-model="formData.cpuarch" type="button">
<ARadio :value="false">{{ t('activate.radio.x86') }}</ARadio>
<ARadio :value="true">{{ t('activate.radio.x64') }}</ARadio>
</ARadioGroup>
</AFormItem>
<AFormItem :label="t('activate.office.form-item.service.label')" field="service">
<AFormItem :label="t('activate.form.label.service')" field="service">
<AInput v-model="formData.service" />
</AFormItem>
<AFormItem :label="t('activate.office.form-item.license.label')" field="license">
<AFormItem :label="t('activate.form.label.license')" field="license">
<AInput v-model="formData.license" disabled />
</AFormItem>
<AFormItem>
<ASpace size="small">
<AButton html-type="submit" type="primary">{{ t('activate.button.create-script') }}</AButton>
<AButton html-type="submit" type="primary">{{ t('activate.button.create') }}</AButton>
<template v-if="activateScriptVisible">
<AButton @click="downloadScript">{{ t('activate.button.download-script') }}</AButton>
<AButton @click="copyScript">{{ t('activate.button.copy-script') }}</AButton>
<AButton @click="downloadScript">{{ t('activate.button.download') }}</AButton>
<AButton @click="copyScript">{{ t('activate.button.copy') }}</AButton>
</template>
</ASpace>
</AFormItem>
Expand Down
Loading

0 comments on commit d2143a0

Please sign in to comment.