Skip to content

Commit 5162db6

Browse files
committed
Internacionalization plugin
I've added the i18n plugin in order to correctly switch between the app laguages
1 parent e5e57e1 commit 5162db6

File tree

12 files changed

+285
-2
lines changed

12 files changed

+285
-2
lines changed

package-lock.json

Lines changed: 227 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
"tiny-secp256k1": "^1.1.6",
5757
"url": "^0.11.1",
5858
"vue": "^3.3.4",
59+
"vue-i18n": "^9.13.1",
5960
"vue-router": "^4.2.4",
6061
"vuetify": "^3.5.17",
6162
"vuex": "^4.1.0",
6263
"web3": "^1.10.0",
6364
"web3-eth-contract": "^1.10.0"
6465
},
6566
"devDependencies": {
67+
"@intlify/vue-i18n-loader": "^4.2.0",
6668
"@ledgerhq/hw-transport-mocker": "^6.28.5",
6769
"@mdi/font": "^7.2.96",
6870
"@types/big.js": "^6.2.0",

src/common/store/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const SESSION_ADD_BITCOIN_PRICE = 'SESSION_ADD_BITCOIN_PRICE';
9292
export const SESSION_CLEAR = 'SESSION_CLEAR';
9393
export const SESSION_ADD_TERMS_VALUE = 'SESSION_ADD_TERMS_VALUE';
9494
export const SESSION_ADD_TERMS_AND_CONDITIONS_ENABLED = 'SESSION_ADD_TERMS_AND_CONDITIONS_ENABLED';
95+
export const SESSION_SWITCH_LOCALE = 'SESSION_SWITCH_LOCALE';
9596

9697
// Pegin tx Mutations
9798
export const PEGIN_TX_SET_ADDRESS_LIST = 'PEGIN_TX_SET_ADDRESS_LIST';
@@ -160,6 +161,7 @@ export const SESSION_SET_BITCOIN_PRICE = 'SESSION_SET_BITCOIN_PRICE';
160161
export const SESSION_CLEAR_STATE = 'SESSION_CLEAR_STATE';
161162
export const SESSION_SET_TERMS_ACCEPTED = 'SESSION_SET_TERMS_ACCEPTED';
162163
export const SESSION_SET_TERMS_AND_CONDITIONS_ENABLED = 'SESSION_SET_TERMS_AND_CONDITIONS_ENABLED';
164+
export const SESSION_SET_LOCALE = 'SESSION_SET_LOCALE';
163165

164166
// Pegin tx getters
165167
export const WALLET_NAME = 'WALLET_NAME';

src/common/store/session/actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import axios, { AxiosResponse } from 'axios';
88
import * as constants from '@/common/store/constants';
99
import {
1010
TransactionType, SessionState, RootState, WeiBig,
11+
AppLocale,
1112
} from '@/common/types';
1213
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
1314
import { ApiService } from '@/common/services';
@@ -165,4 +166,7 @@ export const actions: ActionTree<SessionState, RootState> = {
165166
dispatch(constants.SESSION_ADD_TERMS_VALUE, false);
166167
}
167168
},
169+
[constants.SESSION_SWITCH_LOCALE]: ({ commit }, locale: AppLocale) => {
170+
commit(constants.SESSION_SET_LOCALE, locale);
171+
},
168172
};

src/common/store/session/mutations.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { MutationTree } from 'vuex';
22
import Web3 from 'web3';
33
import * as constants from '@/common/store/constants';
4-
import { WeiBig } from '@/common/types';
4+
import { AppLocale, WeiBig } from '@/common/types';
55
import { TransactionType, SessionState } from '@/common/types/session';
66
import { getClearSessionState } from '@/common/utils';
7+
import i18n from '@/i18n';
78

89
export const mutations: MutationTree<SessionState> = {
910
[constants.SESSION_SET_ACCOUNT]: (state, account: string) => {
@@ -48,4 +49,9 @@ export const mutations: MutationTree<SessionState> = {
4849
[constants.SESSION_SET_TERMS_AND_CONDITIONS_ENABLED]: (state, value) => {
4950
state.termsAndConditionsEnabled = value;
5051
},
52+
[constants.SESSION_SET_LOCALE]: (state, newLocale: AppLocale) => {
53+
if (newLocale && i18n.global.availableLocales.includes(newLocale)) {
54+
i18n.global.locale.value = newLocale;
55+
}
56+
},
5157
};

src/common/types/Common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ export interface ObjectDifference {
130130
oldValue: unknown;
131131
newValue: unknown;
132132
}
133+
134+
export enum AppLocale {
135+
LOCALE_EN = 'en',
136+
LOCALE_ES = 'es',
137+
}

src/common/views/Home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</v-col>
3535
</v-row>
3636
<v-row class="mx-0 mt-10 d-flex justify-center">
37-
<p>Select your token conversion</p>
37+
<p>{{ $t('main.subtitle-2') }}</p>
3838
</v-row>
3939
<v-row justify="center" class="mt-6">
4040
<v-col cols="4" class="d-flex justify-end pb-0">

src/i18n.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createI18n } from 'vue-i18n';
2+
import enLocale from './locales/en.json';
3+
import esLocale from './locales/es.json';
4+
5+
export default createI18n({
6+
locale: 'en',
7+
fallbackLocale: 'es',
8+
legacy: false,
9+
messages: {
10+
en: enLocale,
11+
es: esLocale,
12+
},
13+
globalInjection: true,
14+
});

src/locales/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"main": {
3+
"subtitle-2": "Select your token conversion"
4+
}
5+
}

src/locales/es.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"main": {
3+
"subtitle-2": "Selecciona tu conversion de token"
4+
}
5+
}

0 commit comments

Comments
 (0)