From fb97a2f453eeee77f3f9ed978a09bfbbbd821959 Mon Sep 17 00:00:00 2001 From: Nicola Benaglia Date: Fri, 23 May 2025 09:26:20 +0200 Subject: [PATCH] Add translations --- src/i18n/locales/en/auth.json | 3 +- src/i18n/locales/en/core.json | 1 + src/i18n/locales/en/question.json | 9 ++- src/qortalRequests/get.ts | 104 ++++++++++++++++++++++++------ 4 files changed, 95 insertions(+), 22 deletions(-) diff --git a/src/i18n/locales/en/auth.json b/src/i18n/locales/en/auth.json index 5bd6c13..747b3ca 100644 --- a/src/i18n/locales/en/auth.json +++ b/src/i18n/locales/en/auth.json @@ -101,7 +101,8 @@ "use_custom": "use custom node", "use_local": "use local node", "using": "using node", - "using_public": "using public node" + "using_public": "using public node", + "using_public_gateway": "using public node: {{ gateway }}" }, "note": "note", "password": "password", diff --git a/src/i18n/locales/en/core.json b/src/i18n/locales/en/core.json index 18a78ff..b401cda 100644 --- a/src/i18n/locales/en/core.json +++ b/src/i18n/locales/en/core.json @@ -184,6 +184,7 @@ "file_too_large": "file {{ filename }} is too large. Max size allowed is {{ size }} MB.", "generic": "an error occurred", "initiate_download": "failed to initiate download", + "invalid_amount": "invalid amount", "invalid_base64": "invalid base64 data", "invalid_embed_link": "invalid embed link", "invalid_image_embed_link_name": "invalid image embed link. Missing param.", diff --git a/src/i18n/locales/en/question.json b/src/i18n/locales/en/question.json index 0f63174..542ee8d 100644 --- a/src/i18n/locales/en/question.json +++ b/src/i18n/locales/en/question.json @@ -21,15 +21,18 @@ "encryption_failed": "encryption failed", "encryption_requires_public_key": "encrypting data requires public keys", "fetch_balance": "unable to fetch balance", + "fetch_balance_token": "failed to fetch {{ token }} Balance. Try again!", "fetch_generic": "unable to fetch", "fetch_group": "failed to fetch the group", "fetch_list": "failed to fetch the list", "fetch_poll": "failed to fetch poll", + "fetch_recipient_public_key": "failed to fetch recipient's public key", "insufficient_balance_qort": "your QORT balance is insufficient", "insufficient_balance": "your asset balance is insufficient", "insufficient_funds": "insufficient funds", "invalid_receiver": "invalid receiver address or name", "missing_fields": "missing fields: {{ fields }}", + "name_already_for_sale": "this name is already for sale", "name_not_for_sale": "this name is not for sale", "no_api_found": "no usable API found", "no_data_encrypted_resource": "no data in the encrypted resource", @@ -47,6 +50,7 @@ "send": "failed to send", "submit_sell_order": "failed to submit sell order", "timeout_request": "request timed out", + "get_foreign_fee": "error in get foreign fee", "update_foreign_fee": "failed to update foreign fee", "upload_encryption": "upload failed due to failed encryption", "user_qortal_name": "user has no Qortal name" @@ -64,7 +68,8 @@ "user_declined_join": "user declined to join group", "user_declined_list": "user declined to get list of hosted resources", "user_declined_request": "user declined request", - "user_declined_share_list": "user declined to share list" + "user_declined_share_list": "user declined to share list", + "user_declined_send_message": "user declined to send message" } }, "name": "name: {{ name }}", @@ -73,6 +78,8 @@ "permission_access_list": "do you give this application permission to access the list", "permission_all_item_list": "do you give this application permission to add the following to the list {{ name }}:", "permission_authenticate": "do you give this application permission to authenticate?", + "permission_buy_order": "do you give this application permission to perform a buy order?", + "permission_fetch_balance": "do you give this application permission to fetch your {{ coin }} balance", "permission_list_hosted_data": "do you give this application permission to get a list of your hosted data?", "permission_delete_hosts_resources": "do you give this application permission to delete {{ size }} hosted resources?", "permission_pay_publish": "do you give this application permission to make the following payments and publishes?", diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts index 71315c1..832cc9e 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -2006,13 +2006,22 @@ export const sendChatMessage = async (data, isFromExtension, appInfo) => { const balance = await getBalanceInfo(); const hasEnoughBalance = +balance < 4 ? false : true; if (!hasEnoughBalance) { - throw new Error('You need at least 4 QORT to send a message'); + throw new Error( + i18n.t('group:message.error.qortals_required', { + quantity: 4, + postProcess: 'capitalizeFirstChar', + }) + ); } if (isRecipient && recipient) { const url = await createEndpoint(`/addresses/publickey/${recipient}`); const response = await fetch(url); if (!response.ok) - throw new Error("Failed to fetch recipient's public key"); + throw new Error( + i18n.t('question:message.error.fetch_recipient_public_key', { + postProcess: 'capitalizeFirstChar', + }) + ); let key; let hasPublicKey; @@ -2141,7 +2150,11 @@ export const sendChatMessage = async (data, isFromExtension, appInfo) => { throw new Error('Please enter a recipient or groupId'); } } else { - throw new Error('User declined to send message'); + throw new Error( + i18n.t('question:message.generic.user_declined_send_message', { + postProcess: 'capitalizeFirstChar', + }) + ); } }; @@ -2517,8 +2530,10 @@ export const getWalletBalance = async ( if (!bypassPermission && !skip) { resPermission = await getUserPermission( { - text1: 'Do you give this application permission to fetch your', - highlightedText: `${data.coin} balance`, + text1: i18n.t('question:permission_fetch_balance', { + coin: data.coin, // TODO highlight coin in the modal + postProcess: 'capitalizeFirstChar', + }), checkbox1: { value: true, label: i18n.t('question:always_retrieve_balance', { @@ -3052,7 +3067,12 @@ export const getForeignFee = async (data) => { } return res; // Return full response here } catch (error) { - throw new Error(error?.message || 'Error in get foreign fee'); + throw new Error( + error?.message || + i18n.t('question:message.error.get_foreign_fee', { + postProcess: 'capitalizeFirstChar', + }) + ); } }; @@ -3646,7 +3666,10 @@ export const sendCoin = async (data, isFromExtension) => { walletBalance = await response.text(); } if (isNaN(Number(walletBalance))) { - const errorMsg = 'Failed to Fetch QORT Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'QORT', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } @@ -3663,7 +3686,9 @@ export const sendCoin = async (data, isFromExtension) => { throw new Error(errorMsg); } if (amount <= 0) { - const errorMsg = 'Invalid Amount!'; + const errorMsg = i18n.t('core:message.error.invalid_amount', { + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } if (recipient.length === 0) { @@ -3707,13 +3732,22 @@ export const sendCoin = async (data, isFromExtension) => { const btcWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(btcWalletBalance))) { - throw new Error('Unable to fetch BTC balance'); + throw new Error( + i18n.t('question:message.error.fetch_balance_token', { + token: 'BTC', + postProcess: 'capitalizeFirstChar', + }) + ); } const btcWalletBalanceDecimals = Number(btcWalletBalance); const btcAmountDecimals = Number(amount); const fee = feePerByte * 500; // default 0.00050000 if (btcAmountDecimals + fee > btcWalletBalanceDecimals) { - throw new Error('INSUFFICIENT_FUNDS'); + throw new Error( + i18n.t('question:message.error.insufficient_funds', { + postProcess: 'capitalizeFirstChar', + }) + ); } const resPermission = await getUserPermission( @@ -3774,7 +3808,10 @@ export const sendCoin = async (data, isFromExtension) => { const ltcWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(ltcWalletBalance))) { - const errorMsg = 'Failed to Fetch LTC Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'LTC', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } const ltcWalletBalanceDecimals = Number(ltcWalletBalance); @@ -3843,7 +3880,10 @@ export const sendCoin = async (data, isFromExtension) => { const feePerByte = data.fee ? data.fee : dogeFeePerByte; const dogeWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(dogeWalletBalance))) { - const errorMsg = 'Failed to Fetch DOGE Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'DOGE', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } const dogeWalletBalanceDecimals = Number(dogeWalletBalance); @@ -3916,7 +3956,10 @@ export const sendCoin = async (data, isFromExtension) => { const feePerByte = data.fee ? data.fee : dgbFeePerByte; const dgbWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(dgbWalletBalance))) { - const errorMsg = 'Failed to Fetch DGB Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'DGB', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } const dgbWalletBalanceDecimals = Number(dgbWalletBalance); @@ -3986,7 +4029,10 @@ export const sendCoin = async (data, isFromExtension) => { const feePerByte = data.fee ? data.fee : rvnFeePerByte; const rvnWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(rvnWalletBalance))) { - const errorMsg = 'Failed to Fetch RVN Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'RVN', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } const rvnWalletBalanceDecimals = Number(rvnWalletBalance); @@ -4056,7 +4102,10 @@ export const sendCoin = async (data, isFromExtension) => { const arrrWalletBalance = await getWalletBalance({ coin: checkCoin }, true); if (isNaN(Number(arrrWalletBalance))) { - const errorMsg = 'Failed to Fetch ARRR Balance. Try again!'; + const errorMsg = i18n.t('question:message.error.fetch_balance_token', { + token: 'ARR', + postProcess: 'capitalizeFirstChar', + }); throw new Error(errorMsg); } const arrrWalletBalanceDecimals = Number(arrrWalletBalance); @@ -4192,8 +4241,9 @@ export const createBuyOrder = async (data, isFromExtension) => { const buyingFees = await getBuyingFees(foreignBlockchain); const resPermission = await getUserPermission( { - text1: - 'Do you give this application permission to perform a buy order?', + text1: i18n.t('question:permission_buy_order', { + postProcess: 'capitalizeFirstChar', + }), // TODO translate better text2: `${atAddresses?.length}${' '} ${`buy order${atAddresses?.length === 1 ? '' : 's'}`}`, text3: `${crosschainAtInfo?.reduce((latest, cur) => { @@ -4204,7 +4254,10 @@ export const createBuyOrder = async (data, isFromExtension) => { }, 0) )} ${` ${buyingFees.ticker}`}`, - highlightedText: `Is using public node: ${isGateway}`, + highlightedText: i18n.t('auth:node.using_public_gateway', { + gateway: isGateway, + postProcess: 'capitalizeFirstChar', + }), fee: '', html: `
@@ -5794,9 +5847,19 @@ export const sellNameRequest = async (data, isFromExtension) => { const response = await fetch(validApi + '/names/' + name); const nameData = await response.json(); - if (!nameData) throw new Error('This name does not exist'); + if (!nameData) + throw new Error( + i18n.t('auth:message.error.name_not_existing', { + postProcess: 'capitalizeFirstChar', + }) + ); - if (nameData?.isForSale) throw new Error('This name is already for sale'); + if (nameData?.isForSale) + throw new Error( + i18n.t('question:message.error.name_already_for_sale', { + postProcess: 'capitalizeFirstChar', + }) + ); const fee = await getFee('SELL_NAME'); const resPermission = await getUserPermission( { @@ -6278,6 +6341,7 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { }, isFromExtension ); + const { accepted, checkbox1 = false } = resPermission; if (!accepted) { throw new Error(