diff --git a/.env.example b/.env.example index 88b56f8f8..bc165c2dc 100644 --- a/.env.example +++ b/.env.example @@ -6,4 +6,5 @@ VUE_APP_UNFILLABLE_REASONS=[{"id": "", "label": "No reason"}, {"id": "NOT_IN_STO VUE_APP_PRDT_IDENT_TYPE_ID=SHOPIFY_PROD_SKU VUE_APP_ORD_IDENT_TYPE_ID=SHOPIFY_ORD_NAME VUE_APP_BASE_URL= +VUE_APP_LOCALES={"en": "English", "ja": "日本語"} VUE_APP_ALIAS= \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1ec160449..c7a551329 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24149,4 +24149,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 9bd6ab07b..3b753370d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,7 @@ import { IonApp, IonRouterOutlet } from '@ionic/vue'; import { defineComponent } from 'vue'; import { loadingController } from '@ionic/vue'; import emitter from "@/event-bus" - +import { mapGetters } from 'vuex'; export default defineComponent({ name: 'App', @@ -42,6 +42,11 @@ export default defineComponent({ this.loader = null as any; } } + }, + computed: { + ...mapGetters({ + locale: 'user/getLocale' + }) }, async mounted() { // creating the loader on mounted as loadingController is taking too much time to create initially @@ -53,6 +58,7 @@ export default defineComponent({ }); emitter.on('presentLoader', this.presentLoader); emitter.on('dismissLoader', this.dismissLoader); + this.$i18n.locale = this.locale; }, unmounted() { emitter.off('presentLoader', this.presentLoader); diff --git a/src/locales/en.json b/src/locales/en.json index 625132b69..a1a188ca5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -4,6 +4,7 @@ "Catalog": "Catalog", "Cancel": "Cancel", "canceled from the order": "canceled from the order", + "Choose language": "Choose language", "City": "City", "Click the backdrop to dismiss.": "Click the backdrop to dismiss.", "Color": "Color", diff --git a/src/locales/ja.json b/src/locales/ja.json index 738f66527..98d17c7d8 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -4,6 +4,7 @@ "Catalog": "カタログ", "Cancel": "キャンセル", "canceled from the order": "オーダーからキャンセルされました", + "Choose language": "言語を選択", "City": "街", "Click the backdrop to dismiss.": "背景をクリックして閉じます。", "Color": "色", diff --git a/src/store/modules/user/UserState.ts b/src/store/modules/user/UserState.ts index 8142819d7..365ad5a38 100644 --- a/src/store/modules/user/UserState.ts +++ b/src/store/modules/user/UserState.ts @@ -4,4 +4,5 @@ export default interface UserState { currentFacility: object; instanceUrl: string; preference: any; + locale: string; } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index d57904fbf..4e2f990e8 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -4,7 +4,7 @@ import RootState from '@/store/RootState' import UserState from './UserState' import * as types from './mutation-types' import { hasError, showToast } from '@/utils' -import { translate } from '@/i18n' +import i18n, { translate } from '@/i18n' import moment from 'moment'; import emitter from '@/event-bus' import "moment-timezone"; @@ -110,6 +110,11 @@ const actions: ActionTree = { 'userPrefTypeId': 'BOPIS_PREFERENCE', 'userPrefValue': JSON.stringify(state.preference) }); - } + }, + + setLocale({ commit }, payload) { + i18n.global.locale = payload + commit(types.USER_LOCALE_UPDATED, payload) + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/user/getters.ts b/src/store/modules/user/getters.ts index 981bfea40..8dbe43a68 100644 --- a/src/store/modules/user/getters.ts +++ b/src/store/modules/user/getters.ts @@ -26,6 +26,9 @@ const getters: GetterTree = { }, showPackingSlip (state) { return state.preference.showPackingSlip; + }, + getLocale (state) { + return state.locale; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index c2f25aa2e..a5e49780a 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -15,7 +15,8 @@ const userModule: Module = { preference: { showShippingOrders: true, showPackingSlip: false - } + }, + locale: 'en', }, getters, actions, diff --git a/src/store/modules/user/mutation-types.ts b/src/store/modules/user/mutation-types.ts index b7c9cdfa0..3b71648d1 100644 --- a/src/store/modules/user/mutation-types.ts +++ b/src/store/modules/user/mutation-types.ts @@ -4,4 +4,5 @@ export const USER_END_SESSION = SN_USER + '/END_SESSION' export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED' export const USER_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED' export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED' -export const USER_PREFERENCE_UPDATED = SN_USER + '/PREFERENCE_UPDATED' \ No newline at end of file +export const USER_PREFERENCE_UPDATED = SN_USER + '/PREFERENCE_UPDATED' +export const USER_LOCALE_UPDATED = SN_USER + '/LOCALE_UPDATED' \ No newline at end of file diff --git a/src/store/modules/user/mutations.ts b/src/store/modules/user/mutations.ts index 5c948765a..4dde3684b 100644 --- a/src/store/modules/user/mutations.ts +++ b/src/store/modules/user/mutations.ts @@ -22,6 +22,9 @@ const mutations: MutationTree = { }, [types.USER_PREFERENCE_UPDATED] (state, payload) { state.preference = {...state.preference, ...payload}; + }, + [types.USER_LOCALE_UPDATED] (state, payload) { + state.locale = payload; } } export default mutations; \ No newline at end of file diff --git a/src/views/Settings.vue b/src/views/Settings.vue index abc46d2fb..50e11c374 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -34,6 +34,14 @@ {{ $t("OMS") }}

{{ baseURL ? baseURL : instanceUrl }}

+ + + + {{$t("Choose language")}} + + {{ locales[locale] }} + + @@ -48,7 +56,7 @@