Skip to content

Commit

Permalink
Fixi18n (#453)
Browse files Browse the repository at this point in the history
* feat: console i18n can not select issue

* docs: update CHANGELOG.MD
  • Loading branch information
chivehao committed Oct 2, 2023
1 parent 8a011a2 commit 8d00e9f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## 新功能

- web端多主题支持 #450
- Console端支持切换语言到英文:

## 国际化

Expand Down
3 changes: 3 additions & 0 deletions console/src/layouts/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Hamburger from './components/Hamburger.vue';
import Avatar from './components/Avatar.vue';
import Breadcrumb from './components/Breadcrumb.vue';
import LanguageSelect from './components/LanguageSelect.vue';
</script>

<template>
Expand All @@ -10,6 +11,8 @@ import Breadcrumb from './components/Breadcrumb.vue';
<Breadcrumb />

<div class="navbar-right">
<LanguageSelect />
&nbsp;&nbsp;&nbsp;&nbsp;
<Avatar class="navbar-item" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion console/src/layouts/components/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const layoutStore = useLayoutStore();
const { t } = useI18n();
const userStore = useUserStore();
const avatarSrcUrl = 'https://ikaros.run/logo.png';
const avatarSrcUrl = 'https://docs.ikaros.run/img/favicon.ico';
const router = useRouter();
const toUserProfile = () => {
Expand Down
30 changes: 30 additions & 0 deletions console/src/layouts/components/LanguageSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { ElSelect, ElOption } from 'element-plus';
import { ref } from 'vue';
import { locales, changeI18nLocal } from '@/locales';
const { locale } = useI18n();
const selectedLanguage = ref(locale);
const changeLanguage = () => {
changeI18nLocal(selectedLanguage.value);
};
</script>

<template>
<el-select
v-model="selectedLanguage"
:style="{ width: '100px' }"
@change="changeLanguage"
>
<el-option
v-for="language in locales.filter((ele) => ele.name)"
:key="language.code"
:label="language.name"
:value="language.code"
></el-option>
</el-select>
</template>

<style lang="scss" scoped></style>
7 changes: 5 additions & 2 deletions console/src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export function getBrowserLanguage(): string {
const language = messages[browserLanguage]
? browserLanguage
: browserLanguage.split('-')[0];
// return language in messages ? language : 'zh-CN';
return 'en';
return language in messages ? language : 'zh-CN';
}

export function changeI18nLocal(val) {
i18n.global.locale = val;
}

export function setupI18n(app: App) {
Expand Down

0 comments on commit 8d00e9f

Please sign in to comment.