Skip to content

Commit

Permalink
Internacionalization plugin
Browse files Browse the repository at this point in the history
		I've added the i18n plugin in order to correctly switch between the app laguages
  • Loading branch information
ronaldsg20 committed Apr 30, 2024
1 parent a6102c1 commit 4404812
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 2 deletions.
227 changes: 227 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@
"tiny-secp256k1": "^1.1.6",
"url": "^0.11.1",
"vue": "^3.3.4",
"vue-i18n": "^9.13.1",
"vue-router": "^4.2.4",
"vuetify": "^3.3.11",
"vuex": "^4.1.0",
"web3": "^1.10.0",
"web3-eth-contract": "^1.10.0"
},
"devDependencies": {
"@intlify/vue-i18n-loader": "^4.2.0",
"@ledgerhq/hw-transport-mocker": "^6.28.5",
"@mdi/font": "^7.2.96",
"@types/big.js": "^6.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/common/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const SESSION_ADD_BITCOIN_PRICE = 'SESSION_ADD_BITCOIN_PRICE';
export const SESSION_CLEAR = 'SESSION_CLEAR';
export const SESSION_ADD_TERMS_VALUE = 'SESSION_ADD_TERMS_VALUE';
export const SESSION_ADD_TERMS_AND_CONDITIONS_ENABLED = 'SESSION_ADD_TERMS_AND_CONDITIONS_ENABLED';
export const SESSION_SWITCH_LOCALE = 'SESSION_SWITCH_LOCALE';

// Pegin tx Mutations
export const PEGIN_TX_SET_ADDRESS_LIST = 'PEGIN_TX_SET_ADDRESS_LIST';
Expand Down Expand Up @@ -136,6 +137,7 @@ export const SESSION_SET_BITCOIN_PRICE = 'SESSION_SET_BITCOIN_PRICE';
export const SESSION_CLEAR_STATE = 'SESSION_CLEAR_STATE';
export const SESSION_SET_TERMS_ACCEPTED = 'SESSION_SET_TERMS_ACCEPTED';
export const SESSION_SET_TERMS_AND_CONDITIONS_ENABLED = 'SESSION_SET_TERMS_AND_CONDITIONS_ENABLED';
export const SESSION_SET_LOCALE = 'SESSION_SET_LOCALE';

// Pegin tx getters
export const WALLET_NAME = 'WALLET_NAME';
Expand Down
4 changes: 4 additions & 0 deletions src/common/store/session/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import axios, { AxiosResponse } from 'axios';
import * as constants from '@/common/store/constants';
import {
TransactionType, SessionState, RootState, WeiBig,
AppLocale,
} from '@/common/types';
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
import { ApiService } from '@/common/services';
Expand Down Expand Up @@ -165,4 +166,7 @@ export const actions: ActionTree<SessionState, RootState> = {
dispatch(constants.SESSION_ADD_TERMS_VALUE, false);
}
},
[constants.SESSION_SWITCH_LOCALE]: ({ commit }, locale: AppLocale) => {
commit(constants.SESSION_SET_LOCALE, locale);
},
};
8 changes: 7 additions & 1 deletion src/common/store/session/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MutationTree } from 'vuex';
import Web3 from 'web3';
import * as constants from '@/common/store/constants';
import { WeiBig } from '@/common/types';
import { AppLocale, WeiBig } from '@/common/types';
import { TransactionType, SessionState } from '@/common/types/session';
import { getClearSessionState } from '@/common/utils';
import i18n from '@/i18n';

export const mutations: MutationTree<SessionState> = {
[constants.SESSION_SET_ACCOUNT]: (state, account: string) => {
Expand Down Expand Up @@ -48,4 +49,9 @@ export const mutations: MutationTree<SessionState> = {
[constants.SESSION_SET_TERMS_AND_CONDITIONS_ENABLED]: (state, value) => {
state.termsAndConditionsEnabled = value;
},
[constants.SESSION_SET_LOCALE]: (state, newLocale: AppLocale) => {
if (newLocale && i18n.global.availableLocales.includes(newLocale)) {
i18n.global.locale.value = newLocale;
}
},
};
5 changes: 5 additions & 0 deletions src/common/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ export interface NormalizedSummary {

export type AddressType = 'BITCOIN_LEGACY_ADDRESS' | 'BITCOIN_SEGWIT_ADDRESS' | 'BITCOIN_NATIVE_SEGWIT_ADDRESS' |
'BITCOIN_MULTISIGNATURE_ADDRESS' | 'BITCOIN_UNKNOWN_ADDRESS_TYPE';

export enum AppLocale {
LOCALE_EN = 'en',
LOCALE_ES = 'es',
}
2 changes: 1 addition & 1 deletion src/common/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</v-col>
</v-row>
<v-row class="mx-0 mt-10 d-flex justify-center">
<p>Select your token conversion</p>
<p>{{ $t('main.subtitle-2') }}</p>
</v-row>
<v-row justify="center" class="mt-6">
<v-col cols="4" class="d-flex justify-end pb-0">
Expand Down
14 changes: 14 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createI18n } from 'vue-i18n';
import enLocale from './locales/en.json';
import esLocale from './locales/es.json';

export default createI18n({
locale: 'en',
fallbackLocale: 'es',
legacy: false,
messages: {
en: enLocale,
es: esLocale,
},
globalInjection: true,
});
5 changes: 5 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": {
"subtitle-2": "Select your token conversion"
}
}
5 changes: 5 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": {
"subtitle-2": "Selecciona tu conversion de token"
}
}
Loading

0 comments on commit 4404812

Please sign in to comment.