Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-1091] Convert I18n language files from TS to JSON #1098

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/EmptyValidator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const EmptyValidator = ({ icon, title, message, isDataEmpty, validatorTit
...FontMedium,
paddingTop: 8,
}}>
{i18n.message.unableToFetchInformation(validatorTitle)}
{i18n.formatString(i18n.message.unableToFetchInformation, validatorTitle)}
</Text>
<Button type={'ghost'} size={'sm'} onPress={handleReload}>
<Typography.Text style={{ ...FontMedium, color: theme.colorPrimary }}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Field/ValidatorSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ValidatorSelectorField = ({
const valueList = value.split(',');

if (valueList.length > 1) {
return <Text style={textStyle}>{i18n.message.selectedXValidator(valueList.length)}</Text>;
return <Text style={textStyle}>{i18n.formatString(i18n.message.selectedXValidator, valueList.length)}</Text>;
}

return <Text style={textStyle}>{valueList[0].split('___')[1] || toShort(valueList[0].split('___')[0])}</Text>;
Expand Down
13 changes: 8 additions & 5 deletions src/components/Modal/common/ValidatorSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const ValidatorSelector = forwardRef(
disabled={!chain || !from || disabled}
applyBtn={{
icon: CheckCircle,
label: i18n.buttonTitles.applyValidators(changeValidators.length),
label: i18n.formatString(i18n.buttonTitles.applyValidators, changeValidators.length),
onPressApplyBtn: () => {
onApplyChangeValidators();
validatorSelectModalRef?.current?.closeModal && validatorSelectModalRef?.current?.closeModal();
Expand All @@ -257,9 +257,12 @@ export const ValidatorSelector = forwardRef(
onPressLightningBtn={() => validatorSelectModalRef?.current?.onOpenModal()}
onPressBookBtn={() => validatorSelectModalRef?.current?.onOpenModal()}
value={selectedValidator}
label={i18n.common.selectStakingValidator(getValidatorLabel(chain).toLowerCase())}
label={i18n.formatString(i18n.common.selectStakingValidator, getValidatorLabel(chain).toLowerCase())}
loading={validatorLoading}
placeholder={i18n.common.selectStakingValidator(getValidatorLabel(chain).toLowerCase())}
placeholder={i18n.formatString(
i18n.common.selectStakingValidator,
getValidatorLabel(chain).toLowerCase(),
)}
/>
)}
rightIconOption={{
Expand All @@ -268,8 +271,8 @@ export const ValidatorSelector = forwardRef(
}}
renderCustomItem={renderItem}
searchFunc={searchFunction}
placeholder={i18n.common.searchStakingValidator(getValidatorLabel(chain).toLowerCase())}
title={i18n.common.selectStakingValidator(getValidatorLabel(chain).toLowerCase())}>
placeholder={i18n.formatString(i18n.common.searchStakingValidator, getValidatorLabel(chain).toLowerCase())}
title={i18n.formatString(i18n.common.selectStakingValidator, getValidatorLabel(chain).toLowerCase())}>
<>
{detailItem && (
<ValidatorSelectorDetailModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ValidatorSelectorDetailModal = ({
modalBaseV2Ref={modalBaseV2Ref}
setVisible={setVisible}
modalVisible={detailModalVisible}
modalTitle={i18n.common.stakingValidatorDetail(getValidatorLabel(chain))}
modalTitle={i18n.formatString(i18n.common.stakingValidatorDetail, getValidatorLabel(chain))}
onBackButtonPress={onCancel}>
<View style={{ width: '100%' }}>
<MetaInfo hasBackgroundWrapper>
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletConnect/Account/WCAccountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const WCAccountInput = ({ accounts, selected }: Props) => {
leftItem={<AvatarGroup addresses={selectedAccounts.map(acc => acc.address)} />}
middleItem={
<Typography.Text style={{ color: theme.colorWhite, ...FontMedium }}>
{countSelected ? i18n.message.connectedAccounts(countSelected) : i18n.inputLabel.selectAcc}
{countSelected ? i18n.formatString(i18n.message.connectedAccounts, countSelected) : i18n.inputLabel.selectAcc}
</Typography.Text>
}
rightItem={<Icon phosphorIcon={DotsThree} weight={'fill'} />}
Expand Down
4 changes: 2 additions & 2 deletions src/components/WalletConnect/Account/WCAccountSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const WCAccountSelect = ({
{!availableAccounts.length ? (
<AlertBox
title={i18n.common.noAvailableAccount}
description={i18n.common.youDonotHaveAnyAcc('')}
description={i18n.formatString(i18n.common.youDonotHaveAnyAcc, '')}
type={'warning'}
/>
) : useModal ? (
Expand All @@ -93,7 +93,7 @@ export const WCAccountSelect = ({
disabled={!selectedAccounts.length}
icon={renderButtonIcon}
onPress={_onApply}>
{i18n.buttonTitles.applyAccounts(selectedAccounts.length)}
{i18n.formatString(i18n.buttonTitles.applyAccounts, selectedAccounts.length)}
</Button>
</BasicSelectModal>
) : (
Expand Down
6 changes: 3 additions & 3 deletions src/components/WalletConnect/Network/WCNetworkSelected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const WCNetworkSelected = ({ networks }: Props) => {
supported: false,
chainInfo: {
slug: '',
name: i18n.message.unknownNetworks(unSupportNetworks.length),
name: i18n.formatString(i18n.message.unknownNetworks, unSupportNetworks.length),
},
slug: '',
}
Expand All @@ -57,7 +57,7 @@ export const WCNetworkSelected = ({ networks }: Props) => {
renderSelected={() => (
<WCNetworkInput
networks={connectedNetworks}
content={i18n.message.connectedNetworkConnected(networkNumber)}
content={i18n.formatString(i18n.message.connectedNetworkConnected, networkNumber)}
onPress={() => {}}
/>
)}
Expand All @@ -69,7 +69,7 @@ export const WCNetworkSelected = ({ networks }: Props) => {
color: theme.colorWhite,
paddingBottom: theme.paddingXS,
}}>
{i18n.message.connectedNetworkConnected(networkNumber)}
{i18n.formatString(i18n.message.connectedNetworkConnected, networkNumber)}
</Typography.Text>
}
renderCustomItem={renderItem}
Expand Down
8 changes: 6 additions & 2 deletions src/components/WalletConnect/Network/WCNetworkSupported.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const WCNetworkSupported = ({ networks }: Props) => {
isShowInput={true}
disabled={!networkNumber}
renderSelected={() => (
<WCNetworkInput networks={networks} content={i18n.message.networkSupported(networkNumber)} onPress={() => {}} />
<WCNetworkInput
networks={networks}
content={i18n.formatString(i18n.message.networkSupported, networkNumber)}
onPress={() => {}}
/>
)}
beforeListItem={
<Typography.Text
Expand All @@ -46,7 +50,7 @@ export const WCNetworkSupported = ({ networks }: Props) => {
color: theme.colorWhite,
paddingBottom: theme.paddingXS,
}}>
{i18n.message.networkSupported(networkNumber)}
{i18n.formatString(i18n.message.networkSupported, networkNumber)}
</Typography.Text>
}
renderCustomItem={renderItem}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/StakingPoolItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const StakingPoolItem = ({

<View style={{ flex: 1 }}>
<Text numberOfLines={1} style={_style.poolNameTextStyle}>
{name || i18n.message.poolId(id)}
{name || i18n.formatString(i18n.message.poolId, id)}
</Text>
<View style={_style.contentWrapper}>
<Text style={_style.bondedAmountLabelTextStyle}>{i18n.message.bonded}</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/StakingValidatorItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const StakingValidatorItem = ({
</View>

<View style={_style.contentWrapper}>
<Text style={_style.subTextStyle}>{i18n.message.commission(commission)}</Text>
<Text style={_style.subTextStyle}>{i18n.formatString(i18n.message.commission, commission)}</Text>

{!!expectedReturnValue && expectedReturnValue !== '0' && (
<>
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/balance/useGetBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const useGetBalance = (chain = '', address = '', tokenSlug = '') => {
!cancel && setNativeTokenBalance(DEFAULT_BALANCE);
!cancel && setTokenBalance(DEFAULT_BALANCE);
!cancel && setIsLoading(false);
!cancel && setError(i18n.message.enableTokenOnChain(tokenNames.join(', '), chainInfo?.name || ''));
!cancel &&
setError(i18n.formatString(i18n.message.enableTokenOnChain, tokenNames.join(', '), chainInfo?.name || ''));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/chain/useChainChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function useChainChecker() {
chainStateMap[connectingChain.current]?.connectionStatus === _ChainConnectionStatus.CONNECTED
) {
const chainName = chainInfoMap[connectingChain.current].name;
setTimeout(() => show(i18n.common.chainConnected(chainName), { type: 'success' }), 300);
setTimeout(() => show(i18n.formatString(i18n.common.chainConnected, chainName), { type: 'success' }), 300);
setChainStatus(ChainStatus.CONNECTED);
}
}, [chainInfoMap, chainStateMap, connectingChainStatus, show]);
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/screen/Transaction/useSelectValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function useSelectValidators(
if (!defaultSelected.includes(changeVal)) {
if (toastRef && toastRef.current) {
toastRef.current.hideAll();
toastRef.current.show(i18n.stakingScreen.maximumSelectableValidators(maxCount), { type: 'normal' });
toastRef.current.show(i18n.formatString(i18n.stakingScreen.maximumSelectableValidators, maxCount), {
type: 'normal',
});
}

return currentChangeValidators;
Expand All @@ -40,7 +42,9 @@ export function useSelectValidators(
if (currentChangeValidators.length >= maxCount) {
if (toastRef && toastRef.current) {
toastRef.current.hideAll();
toastRef.current.show(i18n.stakingScreen.maximumSelectableValidators(maxCount), { type: 'normal' });
toastRef.current.show(i18n.formatString(i18n.stakingScreen.maximumSelectableValidators, maxCount), {
type: 'normal',
});
}

return currentChangeValidators;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/screen/Transaction/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const useTransaction = (
setTimeout(() => {
appModalContext.setConfirmModal({
visible: true,
message: i18n.common.enableChainMessage(chainInfoMap[chain].name),
message: i18n.formatString(i18n.common.enableChainMessage, chainInfoMap[chain].name),
title: i18n.common.enableChain,
onCancelModal: () => {
appModalContext.hideConfirmModal();
Expand Down
5 changes: 4 additions & 1 deletion src/screens/Account/RestoreJson/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ export const RestoreJson = () => {
{accountsInfo.length > 1 ? (
<SelectItem
leftItemIcon={<AvatarGroup addresses={addresses} />}
label={i18n.importAccount.importAccounts(String(accountsInfo.length).padStart(2, '0'))}
label={i18n.formatString(
i18n.importAccount.importAccounts,
String(accountsInfo.length).padStart(2, '0'),
)}
onPress={openModal}
rightIcon={<Icon phosphorIcon={DotsThree} size="sm" />}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ const AuthorizeConfirmation: React.FC<Props> = (props: Props) => {
) : (
<>
<Text style={styles.noAccountTextStyle}>{i18n.common.noAvailableAccount}</Text>
<Text style={styles.textCenter}>{i18n.common.youDonotHaveAnyAcc(accountTypeMessage || '')}</Text>
<Text style={styles.textCenter}>
{i18n.formatString(i18n.common.youDonotHaveAnyAcc, accountTypeMessage || '')}
</Text>
</>
)}
<View style={styles.contentContainer}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const MetadataConfirmation: React.FC<Props> = (props: Props) => {
<ConfirmationContent>
<ConfirmationGeneralInfo request={request} />
<Text style={styles.text}>{i18n.confirmation.yourMetadataIsOutOfDate}</Text>
<Text style={styles.description}>{i18n.confirmation.metadataDescription(chain, request.url)}</Text>
<Text style={styles.description}>
{i18n.formatString(i18n.confirmation.metadataDescription, chain, request.url)}
</Text>
<View style={{ paddingBottom: 8 }}>
<View style={styles.detailContainer}>
<Text style={styles.detailName}>{i18n.common.symbol}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BondTransactionConfirmation = ({ transaction }: Props) => {
<MetaInfo style={{ marginTop: 12 }} hasBackgroundWrapper>
<MetaInfo.AccountGroup
addresses={addressList}
content={i18n.common.selectedValidators(data.selectedValidators.length)}
content={i18n.formatString(i18n.common.selectedValidators, data.selectedValidators.length)}
label={data.type === StakingType.POOLED ? i18n.inputLabel.pool : i18n.inputLabel.validators}
/>

Expand Down
4 changes: 2 additions & 2 deletions src/screens/Settings/WalletConnect/ConnectionDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const ConnectionDetail = ({
...FontMedium,
color: theme.colorTextTertiary,
}}>
{i18n.message.connectedNetworks(chains.length)}
{i18n.formatString(i18n.message.connectedNetworks, chains.length)}
</Typography.Text>
<Icon phosphorIcon={Info} weight={'fill'} size={'sm'} iconColor={theme.colorTextTertiary} />
</TouchableOpacity>
Expand All @@ -138,7 +138,7 @@ export const ConnectionDetail = ({
paddingTop: theme.padding,
paddingBottom: theme.paddingXXS,
}}>
{i18n.message.connectedAccounts(accountItems.length)}
{i18n.formatString(i18n.message.connectedAccounts, accountItems.length)}
</Typography.Text>

<View style={{ gap: theme.paddingXS }}>
Expand Down
5 changes: 4 additions & 1 deletion src/screens/Transaction/NFT/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ const SendNFT: React.FC<SendNFTProps> = ({
}

if (isEthereumAddress(recipientAddress) !== isEthereumAddress(owner)) {
const message = i18n.errorMessage.recipientAddressMustBeType(isEthereumAddress(owner) ? 'evm' : 'substrate');
const message = i18n.formatString(
i18n.errorMessage.recipientAddressMustBeType,
isEthereumAddress(owner) ? 'evm' : 'substrate',
);

return [message];
}
Expand Down
7 changes: 5 additions & 2 deletions src/screens/Transaction/SendFund/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ export const SendFund = ({

if (isDestChainEvmCompatible !== isEthereumAddress(_recipientAddress)) {
onUpdateErrors('to')([
i18n.errorMessage.recipientAddressMustBeType(isDestChainEvmCompatible ? 'EVM' : 'substrate'),
i18n.formatString(
i18n.errorMessage.recipientAddressMustBeType,
isDestChainEvmCompatible ? 'EVM' : 'substrate',
),
]);
return false;
}
Expand Down Expand Up @@ -398,7 +401,7 @@ export const SendFund = ({

if (new BigN(_amount).gt(new BigN(_maxTransfer))) {
const maxString = formatBalance(_maxTransfer, decimals);
onUpdateErrors('value')([i18n.errorMessage.amountMustBeEqualOrLessThan(maxString)]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.amountMustBeEqualOrLessThan, maxString)]);

return false;
}
Expand Down
7 changes: 5 additions & 2 deletions src/screens/Transaction/SendFundV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ export const SendFund = ({

if (isDestChainEvmCompatible !== isEthereumAddress(_recipientAddress)) {
return Promise.resolve(
i18n.errorMessage.recipientAddressMustBeType(isDestChainEvmCompatible ? 'EVM' : 'substrate'),
i18n.formatString(
i18n.errorMessage.recipientAddressMustBeType,
isDestChainEvmCompatible ? 'EVM' : 'substrate',
),
);
}
}
Expand Down Expand Up @@ -549,7 +552,7 @@ export const SendFund = ({
if (new BigN(amount).gt(new BigN(maxTransfer))) {
const maxString = formatBalance(maxTransfer, decimals);

return Promise.resolve(i18n.errorMessage.amountMustBeEqualOrLessThan(maxString));
return Promise.resolve(i18n.formatString(i18n.errorMessage.amountMustBeEqualOrLessThan, maxString));
}

return Promise.resolve(undefined);
Expand Down
6 changes: 3 additions & 3 deletions src/screens/Transaction/Stake/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,21 @@ export const Stake = ({
const val = new BigN(value);
if (currentStakingType === StakingType.POOLED) {
if (val.lte(0)) {
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeGreaterThanZero()]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeGreaterThanZero, 'Value')]);
return;
}
} else {
if (!nominatorMetadata?.isBondedBefore || !isRelayChain) {
if (val.lte(0)) {
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeGreaterThanZero()]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeGreaterThanZero, 'Value')]);
return;
}
}
}

if (val.gt(nativeTokenBalance.value)) {
const maxString = new BigN(nativeTokenBalance.value).div(BN_TEN.pow(decimals)).toFixed(6);
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeEqualOrLessThan(maxString)]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeEqualOrLessThan, 'Value', maxString)]);
return;
}

Expand Down
16 changes: 11 additions & 5 deletions src/screens/Transaction/Unbond/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,31 @@ export const Unbond = ({
}, [onChangeValue, stakingChain]);

const validateAmountInput = useCallback(
(value: string, min: number | string | BigN, max: number | string | BigN, _decimals: number, name?: string) => {
(
value: string,
min: number | string | BigN,
max: number | string | BigN,
_decimals: number,
name: string = 'Value',
) => {
const _minValue = new BigN(min);
const _maxValue = new BigN(max);
const _middleValue = _maxValue.minus(_minValue);
const _maxString = formatBalance(_maxValue, _decimals);
const val = new BigN(value);

if (val.gt(_maxValue)) {
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeEqualOrLessThan(_maxString, name)]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeEqualOrLessThan, name, _maxString)]);
return;
}

if (val.lte(BN_ZERO)) {
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeGreaterThanZero(name)]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeGreaterThanZero, name)]);
return;
}

if (_middleValue.lt(BN_ZERO) && !val.eq(_maxValue)) {
onUpdateErrors('value')([i18n.errorMessage.unbondMustBeEqual(_maxString, name)]);
onUpdateErrors('value')([i18n.formatString(i18n.errorMessage.unbondMustBeEqual, name, _maxString)]);
return;
}

Expand Down Expand Up @@ -297,7 +303,7 @@ export const Unbond = ({
color: theme.colorTextTertiary,
...FontMedium,
}}>
{i18n.message.unBondMessage(unBondedTime)}
{i18n.formatString(i18n.message.unBondMessage, unBondedTime)}
</Typography.Text>
</ScrollView>

Expand Down
2 changes: 1 addition & 1 deletion src/screens/Transaction/helper/staking/stakingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getWaitingTime(waitingTime: number, status: UnstakingStatus) {
if (waitingTime > 24) {
const days = moment.duration(waitingTime, 'hours').days();

return i18n.inputLabel.withdrawInXDays(days);
return i18n.formatString(i18n.inputLabel.withdrawInXDays, days);
} else {
return i18n.inputLabel.withdrawInADay;
}
Expand Down
Loading