-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented: support to use i18n through dxp, added language switcher, and defined a store for saving the selected locale(#141)
- Loading branch information
Showing
6 changed files
with
184 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<ion-card> | ||
<ion-card-header> | ||
<ion-card-title> | ||
{{ $t("Language") }} | ||
</ion-card-title> | ||
</ion-card-header> | ||
<ion-card-content> | ||
{{ $t('Select your preferred language.') }} | ||
</ion-card-content> | ||
<ion-item lines="none"> | ||
<ion-label>{{ $t("Choose language") }}</ion-label> | ||
<ion-select interface="popover" :value="currentLocale" @ionChange="setLocale($event.detail.value)"> | ||
<ion-select-option v-for="locale in Object.keys(locales)" :key="locale" :value="locale">{{ locales[locale] }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
</ion-card> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { IonCard, IonCardContent, IonCardHeader, IonItem, IonLabel, IonSelect, IonSelectOption, IonCardTitle } from '@ionic/vue'; | ||
import { computed } from "vue"; | ||
import { useUserStore } from '../store/user' | ||
const userStore = useUserStore(); | ||
const locales = computed(() => userStore.getLocaleOptions); | ||
const currentLocale = computed(() => userStore.getLocale); | ||
const setLocale = (locale: any) => { | ||
userStore.setLocale(locale) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineStore } from "pinia"; | ||
import { i18n } from "src"; | ||
|
||
declare let process: any; | ||
|
||
export const useUserStore = defineStore('user', { | ||
state: () => { | ||
return { | ||
locale: '', | ||
localeOptions: process.env.VUE_APP_LOCALES ? JSON.parse(process.env.VUE_APP_LOCALES) : { "en": "English" } | ||
} | ||
}, | ||
getters: { | ||
getLocale: (state) => state.locale, | ||
getLocaleOptions: (state) => state.localeOptions | ||
}, | ||
actions: { | ||
setLocale(payload: string) { | ||
// update locale in state and globally | ||
i18n.global.locale = payload | ||
this.locale = payload | ||
} | ||
} | ||
}) |