feat(script): add i18n script
This commit is contained in:
parent
58932b9870
commit
e035c525d1
|
@ -23,5 +23,5 @@ ENV = 'development'
|
|||
#VUE_APP_BASE_API = 'http://192.168.31.159:8080'
|
||||
|
||||
#测试
|
||||
#VUE_APP_BASE_API = 'http://a1.hzs413.com/prod-api'
|
||||
VUE_APP_BASE_API = 'http://127.0.0.1:8080'
|
||||
VUE_APP_BASE_API = 'http://a1.hzs413.com/prod-api'
|
||||
# VUE_APP_BASE_API = 'http://127.0.0.1:8080'
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { glob } = require('glob')
|
||||
|
||||
// 读取中文语言包
|
||||
const zhCN = require('../i8n.js')
|
||||
|
||||
// 递归获取所有需要处理的文件
|
||||
async function getAllFiles(dir, patterns) {
|
||||
console.log('搜索目录:', dir)
|
||||
console.log('搜索模式:', patterns)
|
||||
const files = await glob(patterns, {
|
||||
cwd: dir,
|
||||
ignore: ['node_modules/**', 'dist/**', '**/i18n/**', '**/languages/**']
|
||||
})
|
||||
console.log('找到的文件数量:', files.length)
|
||||
return files
|
||||
}
|
||||
|
||||
// 获取嵌套对象的值
|
||||
function getNestedValue(obj, path) {
|
||||
return path.split('.').reduce((current, key) => current && current[key], obj)
|
||||
}
|
||||
|
||||
// 替换文件内容
|
||||
function replaceContent(content) {
|
||||
// 替换模板中的 $t('key')
|
||||
content = content.replace(
|
||||
/(?<!this\.|that\.)\$t\(['"]([^'"]+)['"]\)/g,
|
||||
(match, key) => {
|
||||
const value = getNestedValue(zhCN, key)
|
||||
return value ? `'${value}'` : match
|
||||
}
|
||||
)
|
||||
|
||||
// 替换 JavaScript 中的 this.$t('key')
|
||||
content = content.replace(/this\.\$t\(['"]([^'"]+)['"]\)/g, (match, key) => {
|
||||
const value = getNestedValue(zhCN, key)
|
||||
return value ? `'${value}'` : match
|
||||
})
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
// 主函数
|
||||
async function main() {
|
||||
try {
|
||||
const srcPath = path.resolve(__dirname, '../src')
|
||||
console.log('源文件目录:', srcPath)
|
||||
|
||||
// 只处理 views 和 components 目录
|
||||
const patterns = [
|
||||
'views/**/*.vue',
|
||||
'views/**/*.js',
|
||||
'views/**/*.ts',
|
||||
'components/**/*.vue',
|
||||
'components/**/*.js',
|
||||
'components/**/*.ts'
|
||||
]
|
||||
|
||||
const files = await getAllFiles(srcPath, patterns)
|
||||
|
||||
if (files.length === 0) {
|
||||
console.log('警告:没有找到匹配的文件!')
|
||||
return
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.resolve(srcPath, file)
|
||||
console.log('处理文件:', filePath)
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf8')
|
||||
const newContent = replaceContent(content)
|
||||
|
||||
if (newContent !== content) {
|
||||
fs.writeFileSync(filePath, newContent, 'utf8')
|
||||
console.log(`已处理文件: ${file}`)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('所有文件处理完成!')
|
||||
} catch (error) {
|
||||
console.error('处理过程中出错:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
|
@ -7,24 +7,34 @@
|
|||
<template>
|
||||
<div class="page">
|
||||
<div class="main">
|
||||
<el-form :model="ruleForm"
|
||||
:rules="rules"
|
||||
<el-form
|
||||
ref="ruleForm"
|
||||
:model="ruleForm"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
class="demo-ruleForm">
|
||||
<el-form-item :label="$t('MN_F_T_286')"
|
||||
prop="name">
|
||||
<el-radio-group v-model="ruleForm.functionType"
|
||||
@change="getRadio">
|
||||
<el-radio :label="item.value"
|
||||
:disabled="lookOver"
|
||||
class="demo-ruleForm"
|
||||
>
|
||||
<el-form-item
|
||||
:label="$t('MN_F_T_286')"
|
||||
prop="name"
|
||||
>
|
||||
<el-radio-group
|
||||
v-model="ruleForm.functionType"
|
||||
@change="getRadio"
|
||||
>
|
||||
<el-radio
|
||||
v-for="item in funcList"
|
||||
:key="item.value">{{ item.label }}</el-radio>
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:disabled="lookOver"
|
||||
>{{ item.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
|
||||
</el-form-item>
|
||||
<el-form-item label=""
|
||||
prop="name">
|
||||
<el-form-item
|
||||
label=""
|
||||
prop="name"
|
||||
>
|
||||
<!-- <el-checkbox-group v-model="ruleForm.websiteTypes">
|
||||
<el-checkbox :label="item.value"
|
||||
v-for="item in webList"
|
||||
|
@ -32,139 +42,187 @@
|
|||
)"
|
||||
:key="item.value">{{ item.label }}</el-checkbox>
|
||||
</el-checkbox-group> -->
|
||||
<el-radio-group v-model="ruleForm.websiteType"
|
||||
@change="getRadios">
|
||||
<el-radio :label="item.value"
|
||||
<el-radio-group
|
||||
v-model="ruleForm.websiteType"
|
||||
@change="getRadios"
|
||||
>
|
||||
<el-radio
|
||||
v-for="item in webList"
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:disabled="lookOver||(item.value==2&&ruleForm.functionType == 2
|
||||
)"
|
||||
v-for="item in webList"
|
||||
:key="item.value">{{ item.label }}</el-radio>
|
||||
>{{ item.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-row>
|
||||
<el-col :span="22">
|
||||
<el-form-item :label="$t('MN_F_T_287')"
|
||||
prop="name">
|
||||
<el-input clearable
|
||||
<el-form-item
|
||||
:label="$t('MN_F_T_287')"
|
||||
prop="name"
|
||||
>
|
||||
<el-input
|
||||
v-model="ruleForm.title"
|
||||
:disabled="lookOver"></el-input>
|
||||
clearable
|
||||
:disabled="lookOver"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('w_0445')"
|
||||
prop="name">
|
||||
<el-date-picker :disabled="lookOver"
|
||||
<el-form-item
|
||||
:label="$t('w_0445')"
|
||||
prop="name"
|
||||
>
|
||||
<el-date-picker
|
||||
v-model="ruleForm.effectiveDate"
|
||||
:disabled="lookOver"
|
||||
type="datetime"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
:placeholder="$t('CK_KS_38')"
|
||||
default-time="00:00:00">
|
||||
</el-date-picker>
|
||||
default-time="00:00:00"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item :label="$t('w_0437')"
|
||||
prop="name">
|
||||
<el-date-picker :disabled="lookOver"
|
||||
<el-form-item
|
||||
:label="$t('w_0437')"
|
||||
prop="name"
|
||||
>
|
||||
<el-date-picker
|
||||
v-model="ruleForm.ruleFormTime"
|
||||
@change="changeTime"
|
||||
:disabled="lookOver"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
type="datetimerange"
|
||||
:range-separator="$t('w_0139')"
|
||||
:start-placeholder="$t('CK_KS_4')"
|
||||
:end-placeholder="$t('CK_KS_5')">
|
||||
</el-date-picker>
|
||||
:end-placeholder="$t('CK_KS_5')"
|
||||
@change="changeTime"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="6"
|
||||
v-show="ruleForm.websiteType == 1">
|
||||
<el-col
|
||||
v-show="ruleForm.websiteType == 1"
|
||||
:span="6"
|
||||
>
|
||||
<el-form-item :label="$t('MN_F_T_290')">
|
||||
<el-select clearable
|
||||
<el-select
|
||||
v-model="ruleForm.publishLocations"
|
||||
clearable
|
||||
:disabled="lookOver"
|
||||
:placeholder="$t('CK_KS_38')"
|
||||
multiple
|
||||
v-model="ruleForm.publishLocations">
|
||||
<el-option v-for="item in localList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in localList"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"></el-option>
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6"
|
||||
v-show="ruleForm.websiteType == 1">
|
||||
<el-col
|
||||
v-show="ruleForm.websiteType == 1"
|
||||
:span="6"
|
||||
>
|
||||
<el-form-item :label="$t('ENU_NOTICE_TYPE_1')">
|
||||
<el-select clearable
|
||||
<el-select
|
||||
v-model="ruleForm.grades"
|
||||
clearable
|
||||
:disabled="lookOver"
|
||||
:placeholder="$t('CK_KS_38')"
|
||||
multiple
|
||||
v-model="ruleForm.grades">
|
||||
<el-option v-for="item in gradeList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in gradeList"
|
||||
:key="item.pkId"
|
||||
:label="item.gradeName"
|
||||
:value="item.pkId"></el-option>
|
||||
:value="item.pkId"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6"
|
||||
v-show="ruleForm.websiteType == 2">
|
||||
<el-col
|
||||
v-show="ruleForm.websiteType == 2"
|
||||
:span="6"
|
||||
>
|
||||
<el-form-item :label="$t('MN_F_T_291')">
|
||||
<el-select clearable
|
||||
<el-select
|
||||
v-model="ruleForm.role"
|
||||
clearable
|
||||
:placeholder="$t('CK_KS_38')"
|
||||
v-model="ruleForm.role">
|
||||
<el-option v-for="item in jsList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in jsList"
|
||||
:key="item.roleId"
|
||||
:label="item.roleName"
|
||||
:value="item.roleId"></el-option>
|
||||
:value="item.roleId"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('MN_F_T_292')">
|
||||
<el-select clearable
|
||||
<el-select
|
||||
v-model="ruleForm.isPopScreen"
|
||||
clearable
|
||||
:disabled="lookOver"
|
||||
:placeholder="$t('CK_KS_38')"
|
||||
v-model="ruleForm.isPopScreen">
|
||||
<el-option v-for="item in popList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in popList"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"></el-option>
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="22">
|
||||
<el-form-item :label="$t('MN_F_T_295')"
|
||||
v-if="lookOver">
|
||||
<editor ref="sptwEditor"
|
||||
:readOnly="lookOver"
|
||||
<el-form-item
|
||||
v-if="lookOver"
|
||||
:label="$t('MN_F_T_295')"
|
||||
>
|
||||
<editor
|
||||
ref="sptwEditor"
|
||||
v-model="ruleForm.content"
|
||||
:read-only="lookOver"
|
||||
:min-height="196"
|
||||
:uploadUrl="uploadImgUrl" />
|
||||
:upload-url="uploadImgUrl"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('MN_F_T_295')"
|
||||
v-else>
|
||||
<editor ref="sptwEditor"
|
||||
<el-form-item
|
||||
v-else
|
||||
:label="$t('MN_F_T_295')"
|
||||
>
|
||||
<editor
|
||||
ref="sptwEditor"
|
||||
v-model="ruleForm.content"
|
||||
:min-height="196"
|
||||
:uploadUrl="uploadImgUrl" />
|
||||
:upload-url="uploadImgUrl"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<el-button size="small"
|
||||
class="thebtn2"> {{ $t('ENU_P_TYPE0') }}</el-button>
|
||||
<el-button size="small"
|
||||
@click="submit"
|
||||
<el-button
|
||||
size="small"
|
||||
class="thebtn2"
|
||||
> {{ $t('ENU_P_TYPE0') }}</el-button>
|
||||
<el-button
|
||||
v-has-buttons="['EmailedAdd']"
|
||||
class="thebtn1"> {{ $t('MN_F_32') }}</el-button>
|
||||
size="small"
|
||||
class="thebtn1"
|
||||
@click="submit"
|
||||
> {{ $t('MN_F_32') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -174,7 +232,7 @@ import Editor from '@/components/Editor'
|
|||
import * as api from '@/api/notice.js'
|
||||
export default {
|
||||
components: {
|
||||
Editor,
|
||||
Editor
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -185,7 +243,7 @@ export default {
|
|||
endTime: '',
|
||||
websiteTypes: [],
|
||||
publishLocations: [],
|
||||
grades: [],
|
||||
grades: []
|
||||
},
|
||||
rules: {},
|
||||
localList: [],
|
||||
|
@ -196,13 +254,13 @@ export default {
|
|||
funcList: [],
|
||||
jsList: [],
|
||||
isAdmin: false,
|
||||
lookOver: false,
|
||||
lookOver: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.pkId = this.$route.query.pkId || ''
|
||||
this.isAdmin = this.$route.query.isAdmin || false
|
||||
this.lookOver = this.$route.query.type == 1 ? true : false
|
||||
this.lookOver = this.$route.query.type == 1
|
||||
this.getData()
|
||||
if (this.pkId != '') {
|
||||
this.getDetails()
|
||||
|
@ -229,7 +287,7 @@ export default {
|
|||
getDetails() {
|
||||
api
|
||||
.noticeDetails({
|
||||
pkId: this.pkId,
|
||||
pkId: this.pkId
|
||||
})
|
||||
.then((res) => {
|
||||
this.ruleForm = res.data
|
||||
|
@ -248,7 +306,7 @@ export default {
|
|||
|
||||
this.$set(this.ruleForm, 'ruleFormTime', [
|
||||
this.ruleForm.startTime,
|
||||
this.ruleForm.endTime,
|
||||
this.ruleForm.endTime
|
||||
])
|
||||
this.$forceUpdate()
|
||||
})
|
||||
|
@ -280,7 +338,7 @@ export default {
|
|||
this.ruleForm.grade = this.ruleForm.grades.join(',')
|
||||
this.ruleForm.publishLocation = this.ruleForm.publishLocations.join(',')
|
||||
this.ruleForm.websiteType
|
||||
let obj = Object.assign({}, this.ruleForm, { pkId: this.pkId })
|
||||
const obj = Object.assign({}, this.ruleForm, { pkId: this.pkId })
|
||||
let urlRequest = ''
|
||||
|
||||
if (this.pkId != '') {
|
||||
|
@ -292,11 +350,11 @@ export default {
|
|||
urlRequest(obj).then((res) => {
|
||||
this.$message({
|
||||
message: this.$t('MN_F_T_477'),
|
||||
type: 'success',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
this.$router.replace({
|
||||
path: '/announcement/email',
|
||||
path: '/announcement/email'
|
||||
})
|
||||
|
||||
// console.log(
|
||||
|
@ -305,8 +363,8 @@ export default {
|
|||
// res
|
||||
// )
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ module.exports = {
|
|||
'enUS': 'enUS',
|
||||
'zhTC': 'zhTC',
|
||||
'ruRU': 'ruRU',
|
||||
'frFR':'frFR',
|
||||
'frFR': 'frFR'
|
||||
}
|
||||
},
|
||||
chainWebpack(config) {
|
||||
|
|
Loading…
Reference in New Issue