当前位置:网站首页>Uni app internationalization
Uni app internationalization
2022-07-29 03:42:00 【linzhiji】
Reference resources
Add folder and path

index.js
// internationalization json file , See the following example for the contents of the file
import en from './en.json'
import zhHans from './zh-Hans.json' // Chinese simplified
import zhHant from './zh-Hant.json' // Chinese traditional
export default {
en,
'zh-Hans': zhHans,
'zh-Hant': zhHant,
}
main.js
// Added content
// internationalization
import messages from './locale/index'
import {getLang} from "./utils/lang";
let i18nConfig = {
locale: getLang(),
messages
}
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
const app = new Vue({
i18n,
store,
...App
});
Dynamic language switching


lang.vue
<template>
<view class="body">
<!-- <u-cell-item icon="setting-fill" title=" Personal settings "></u-cell-item> -->
<u-cell-item title="English" :arrow="false" @click="changeLang('en')">
<u-icon slot="right-icon" size="32" name="checkmark" v-if="isEn"></u-icon>
</u-cell-item>
<u-cell-item title=" chinese " :arrow="false" @click="changeLang('zh-Hans')">
<u-icon slot="right-icon" size="32" name="checkmark" v-if="isZh"></u-icon>
</u-cell-item>
</view>
</template>
<script>
import {getLang, setLang} from "@/utils/lang.js";
export default {
data() {
return {
isEn: false,
isZh: false
};
},
onLoad() {
console.log(getLang())
let lang=getLang()
this.updateLang(lang)
},
methods: {
updateLang(srcLang){
if(srcLang == "zh-Hans"){
this.isEn=false
this.isZh=true
}else if(srcLang == "en"){
this.isEn=true
this.isZh=false
}
},
changeLang(srcLange){
setLang(srcLange)
console.log("change language:" + srcLange)
this.updateLang(srcLange)
}
}
}
</script>
<style lang="scss" scoped>
</style>
Use
vue page
import {initVueI18n} from '@dcloudio/uni-i18n'
import messages from '../../locale/index';
const { t } = initVueI18n(messages)#vue In the page
{
{$t('index.title')}}
#page page
"navigationBarTitleText": "%index.language%",
#page page , label <>
<u-input v-model="content" type="textarea" height="250" auto-height :placeholder="$t('wit.publish_tip')"/>
// 1. vue Use of component templates
<div>{
{$t('message.zh')}}</div>
// 2. vue Use of component template data binding
<input :placeholder="$t('message.zh')"/>
// 3.vue Components data The use of assignment in
data:{
msg:this.$t('message.zh');
}nvue page
nvue Page references i18n_Dai_ Generations of blogs -CSDN Blog
stay app.vue Inside
globalData: {
$t: ''
},
onLaunch(){
this.globalData.$t = val => {
return this.$t(val);
};
},stay nvue Page using
<view>{
{ $t('conn.phone') }}</view>
# stay script
let app = getApp().globalData;
methods:{
$t(text) {
return app.$t(text);
},
}
#nvue Text
{
{$t('tab.friend')}边栏推荐
- Process tracking of ribbon principle
- Naive Bayes -- continuous data
- Swing V2: towards a larger model with larger capacity and higher resolution
- How do programmers use code to completely end those things in the system?
- 3.1 common neural network layer (I) image correlation layer
- Rdkit: introduce smiles code, smart code and Morgan fingerprint (ECFP)
- Precautions for using latex
- sql
- exness:鸽派决议帮助黄金反弹,焦点转向美国GDP
- Suffix automata (SAM) board from Jly
猜你喜欢
![Machine learning [numpy]](/img/6b/3e7f08c5d379ce35687e4f14545929.png)
Machine learning [numpy]

Producer consumer model of concurrent model

Raft protocol - process demonstration

Why does the 20 bit address bus determine the storage space of 1MB

暴力递归到动态规划 01 (机器人移动)

@Configuration (proxybeanmethods = false) what's the use of setting this to false

Pp-yoloe details

容斥原理

Configure vscade to realize ROS writing

1. Mx6u driver development-2-led driver
随机推荐
后缀自动机(sam)板子 from jly
Excel splicing database statement
In depth C language (2) -- definition and use of structure
CUB_200鸟类数据集关键点可视化
Sleuth+zipkin to track distributed service links
Numpy acceleration -- > cupy installation
1.5 nn. Module neural network (III)
深入C语言(3)—— C的输入输出流
three.js 第五十四用如何给shader传递结构体数组
最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口
In depth C language (4) -- definition and use of switch
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
3.2 model saving and loading
exness:鸽派决议帮助黄金反弹,焦点转向美国GDP
Why is continuous integration and deployment important in development?
Various minor problems of jupyter notebook, configuration environment, code completion, remote connection, etc
Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment
Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules
How to understand "page storage management scheme"
Inclusion exclusion principle