fix 修改国际化文件名称不规范问题,增加reqeust 国际化配置
This commit is contained in:
parent
4775803427
commit
20f64b54d5
@ -5,8 +5,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
<el-dropdown-item :disabled="appStore.language === 'zh-cn'" command="zh-cn"> 中文 </el-dropdown-item>
|
<el-dropdown-item :disabled="appStore.language === 'zh_CN'" command="zh_CN"> 中文 </el-dropdown-item>
|
||||||
<el-dropdown-item :disabled="appStore.language === 'en'" command="en"> English </el-dropdown-item>
|
<el-dropdown-item :disabled="appStore.language === 'en_US'" command="en_US"> English </el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</template>
|
</template>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
@ -20,14 +20,15 @@ import { useAppStore } from '@/store/modules/app';
|
|||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
||||||
function handleLanguageChange(lang: string) {
|
|
||||||
|
const message: any = {
|
||||||
|
zh_CN: '切换语言成功!',
|
||||||
|
en_US: 'Switch Language Successful!',
|
||||||
|
}
|
||||||
|
const handleLanguageChange = (lang: string) => {
|
||||||
locale.value = lang;
|
locale.value = lang;
|
||||||
appStore.changeLanguage(lang);
|
appStore.changeLanguage(lang);
|
||||||
if (lang == 'en') {
|
ElMessage.success(message[lang] || '切换语言成功!');
|
||||||
ElMessage.success('Switch Language Successful!');
|
|
||||||
} else {
|
|
||||||
ElMessage.success('切换语言成功!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
|
|
||||||
// 本地语言包
|
// 本地语言包
|
||||||
import enLocale from './en';
|
import enUSLocale from './en_US';
|
||||||
import zhCnLocale from './zh-cn';
|
import zhCNLocale from './zh_CN';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
'zh-cn': {
|
zh_CN: {
|
||||||
...zhCnLocale
|
...zhCNLocale
|
||||||
},
|
},
|
||||||
en: {
|
en_US: {
|
||||||
...enLocale
|
...enUSLocale
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ export const getLanguage = () => {
|
|||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'zh-cn';
|
return 'zh_CN';
|
||||||
};
|
};
|
||||||
|
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
import zhCN from 'element-plus/es/locale/lang/zh-cn';
|
||||||
import en from 'element-plus/es/locale/lang/en';
|
import enUS from 'element-plus/es/locale/lang/en';
|
||||||
|
|
||||||
export const useAppStore = defineStore('app', () => {
|
export const useAppStore = defineStore('app', () => {
|
||||||
const sidebarStatus = Cookies.get('sidebarStatus');
|
const sidebarStatus = Cookies.get('sidebarStatus');
|
||||||
@ -11,14 +11,18 @@ export const useAppStore = defineStore('app', () => {
|
|||||||
});
|
});
|
||||||
const device = ref<string>('desktop');
|
const device = ref<string>('desktop');
|
||||||
const size = ref(Cookies.get('size') || 'default');
|
const size = ref(Cookies.get('size') || 'default');
|
||||||
|
|
||||||
// 语言
|
// 语言
|
||||||
const language = ref(Cookies.get('language'));
|
const language = ref(Cookies.get('language'));
|
||||||
|
const languageObj: any = {
|
||||||
|
en_US: enUS,
|
||||||
|
zh_CN: zhCN
|
||||||
|
};
|
||||||
const locale = computed(() => {
|
const locale = computed(() => {
|
||||||
if (language.value == 'en') {
|
if (!language.value) {
|
||||||
return en;
|
return zhCN;
|
||||||
} else {
|
|
||||||
return zhCn;
|
|
||||||
}
|
}
|
||||||
|
return languageObj[language.value];
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleSideBar = (withoutAnimation?: boolean) => {
|
const toggleSideBar = (withoutAnimation?: boolean) => {
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
// translate router.meta.title, be used in breadcrumb sidebar tagsview
|
// translate router.meta.title, be used in breadcrumb sidebar tagsview
|
||||||
import i18n from '@/lang/index';
|
import i18n from '@/lang/index';
|
||||||
|
|
||||||
export const translateRouteTitleI18n = (title: string): string => {
|
/**
|
||||||
// 判断是否存在国际化配置,如果没有原生返回
|
* 获取国际化路由,如果不存在则原生返回
|
||||||
|
* @param title 路由名称
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export const translateRouteTitle = (title: string): string => {
|
||||||
const hasKey = i18n.global.te('route.' + title);
|
const hasKey = i18n.global.te('route.' + title);
|
||||||
if (hasKey) {
|
if (hasKey) {
|
||||||
const translatedTitle = i18n.global.t('route.' + title);
|
const translatedTitle = i18n.global.t('route.' + title);
|
||||||
|
@ -7,14 +7,13 @@ import { HttpStatus } from '@/enums/RespEnum';
|
|||||||
import { errorCode } from '@/utils/errorCode';
|
import { errorCode } from '@/utils/errorCode';
|
||||||
import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
|
import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
|
||||||
import FileSaver from 'file-saver';
|
import FileSaver from 'file-saver';
|
||||||
|
import { getLanguage } from '@/lang';
|
||||||
|
|
||||||
let downloadLoadingInstance: LoadingInstance;
|
let downloadLoadingInstance: LoadingInstance;
|
||||||
// 是否显示重新登录
|
// 是否显示重新登录
|
||||||
export const isRelogin = { show: false };
|
export const isRelogin = { show: false };
|
||||||
|
|
||||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
|
||||||
// 对应国际化资源文件后缀
|
|
||||||
axios.defaults.headers['Content-Language'] = 'zh_CN';
|
|
||||||
// 创建 axios 实例
|
// 创建 axios 实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||||
@ -24,6 +23,9 @@ const service = axios.create({
|
|||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
service.interceptors.request.use(
|
service.interceptors.request.use(
|
||||||
(config: InternalAxiosRequestConfig) => {
|
(config: InternalAxiosRequestConfig) => {
|
||||||
|
// 对应国际化资源文件后缀
|
||||||
|
config.headers['Content-Language'] = getLanguage();
|
||||||
|
|
||||||
const isToken = (config.headers || {}).isToken === false;
|
const isToken = (config.headers || {}).isToken === false;
|
||||||
// 是否需要防止数据重复提交
|
// 是否需要防止数据重复提交
|
||||||
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
|
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user