-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathChangeLanguage.vue
89 lines (86 loc) · 1.96 KB
/
ChangeLanguage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<a-dropdown :trigger="['click']">
<a
class="ant-dropdown-link"
@click="(e) => e.preventDefault()"
:style="{ color: titleColor, fontSize: titleSize }"
>
{{ i18n.languageName }}<DownOutlined
/></a>
<template v-slot:overlay>
<a-menu class="dropdown-panel">
<a-menu-item
v-for="(value, key) of LanguageNameList"
:key="key"
@click="changeLanguage"
>
<span :style="{ color: textColor }">{{ LanguageNameList[key] }}</span>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
<script>
import { defineComponent } from 'vue'
import { setLang, i18nInstance, LanguageNameList } from '../i18n/index'
import { message } from 'ant-design-vue'
import { DownOutlined } from '@ant-design/icons-vue'
export default defineComponent({
props: {
titleColor: {
type: String,
default: '#fff'
},
textColor: {
type: String,
default: '#fff'
},
titleSize: {
type: String,
default: '16px'
}
},
components: {
DownOutlined
},
setup() {
const { i18n } = i18nInstance
const changeLanguage = (e) => {
const lang = e.key
setLang(lang).then((result) => {
if (result === lang) {
message.success(
`${i18n.value['Current Language:']} ${i18n.value.languageName}`
)
}
})
}
return {
LanguageNameList,
changeLanguage,
i18n
}
}
})
</script>
<style lang="less" scoped>
.dropdown-panel {
background: rgba(255, 255, 255, 0.3);
margin-top: 10px;
/deep/ .ant-dropdown-menu-item-active {
background: transparent;
transform: translateX(2px);
transition: all 0.2s ease-in-out;
}
}
.dropdown-panel::before {
content: '';
display: block;
border: 10px solid transparent;
border-bottom-color: rgba(255, 255, 255, 0.3);
position: absolute;
top: -20px;
left: 50%;
transform: translateX(-50%);
}
</style>