跳转到内容

Mall4j-国际化说明

跨境多商户版 · Mall4j-国际化说明

前端国际化使用 vue-i18n 插件,项目已集成配置

// 后台管理
src\i18n\langs
// PC项目
\locales

使用键值对声明当前语言下key对应的值,页面将显示当前语言下对应键名的值。 注:PC项目语言包文件格式为 JSON 使用方法相同

en.js

const en = {
index: 'Home',
user: {
userName: 'User Name'
}
}
export default en

zh_CN.js

const zhCn = {
index: '首页',
user: {
userName: '用户名'
}
}
export default zhCn

在模版中使用

<template>
<div class="index">
{{ $t('index') }} <!-- 首页 || Home -->
<div class="user">
{{ $t('user.userName') }} <!-- 用户名 || User Name -->
</div>
<!-- :bind -->
<input :placeholder="$t('user.userName')" />
</div>
</template>

在 JS 中使用

fun() {
console.log(this.$t('user.userName')) // 用户名 || User Name
// console.log(this.$i8n.t('user.userName'))
// $i8n.t 等同于 $t
}
src\utils\lang

使用键值对声明当前语言下key对应的值,页面将显示当前语言下对应键名的值。

在模板文件计算属性中引入 i18n

computed: {
i18n() {
return this.$t('index')
}
}

在模版中使用

<template>
<div class="index">
{{ i18n.index }} <!-- 首页 || Home -->
<div class="user">
{{ i18n.user.userName }} <!-- 用户名 || User Name -->
</div>
<!-- :bind -->
<input :placeholder="i18n.user.userName" />
</div>
</template>

在 JS 中使用

fun() {
console.log(this.i18n.user.userName) // 用户名 || User Name
}

后端国际化使用 spring boot的国际化

yami-shop-common 模块中的resources文件夹

img.png

yami-shop-common 模块中src\main\java\com\yami\shop\common\i18n包下

img_1.png

1.messages_en.properties、messages_zh.propertie语言配置文件中添加参数
Section titled “1.messages_en.properties、messages_zh.propertie语言配置文件中添加参数”

img_2.png

yami-shop-common 模块中的resources文件夹

String fileName = I18nMessage.getMessage("yami.excel.user.info");
throw new YamiShopBindException("yami.order.no.exist");

img_3.png

1.新增一个messages_xxx.propertie语言配置文件, 按照已有的参数填充对应的翻译信息
Section titled “1.新增一个messages_xxx.propertie语言配置文件, 按照已有的参数填充对应的翻译信息”

img_4.png

img_5.png

3.把LanguageEnum枚举类中新语言配置的language给前端,前端请求头中携带该参数即可
Section titled “3.把LanguageEnum枚举类中新语言配置的language给前端,前端请求头中携带该参数即可”

数据库中以_lang结尾的表就是国际化语言表,添加新语言时,不需要进行改动

img_6.png