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 May 3, 2024
1 parent 7a7dee8 commit 375a978
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 3 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 @@ -56,13 +56,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.5.17",
"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 @@ -92,6 +92,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 @@ -160,6 +161,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 @@ -130,3 +130,8 @@ export interface ObjectDifference {
oldValue: unknown;
newValue: unknown;
}

export enum AppLocale {
LOCALE_EN = 'en',
LOCALE_ES = 'es',
}
4 changes: 2 additions & 2 deletions src/common/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<v-row v-else no-gutters justify="space-around">
<v-col lg="4" xl="3" xxl="2">
<div class="d-flex text-h1 flex-wrap">
<span class="mx-1 my-2 pa-4 bg-purple">Bridging</span>
<span class="mx-1 my-2 pa-4 bg-purple">{{ $t('home.title.bridging') }}</span>
<span class="mx-1 my-2 pa-4 bg-orange">{{ environmentContext.getBtcTicker() }}</span>
<span class="mx-1 my-2 pa-4 bg-off-white">and</span>
<span class="mx-1 my-2 pa-4 bg-off-white">{{ $t('home.title.and') }}</span>
<span class="mx-1 my-2 pa-4 bg-green">{{ environmentContext.getRbtcTicker() }}</span>
</div>
</v-col>
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,
});
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"home": {
"title": {
"bridging": "Bridging",
"and": "and"
}
}
}
8 changes: 8 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"home": {
"title": {
"bridging": "Conectando",
"and": "y"
}
}
}
Loading

0 comments on commit 375a978

Please sign in to comment.