From a6d77d86153ee6bf69bca2dc6d95161b96a9da64 Mon Sep 17 00:00:00 2001 From: Nicola Benaglia Date: Thu, 22 May 2025 19:47:07 +0200 Subject: [PATCH] Add translations --- src/background.ts | 34 +----- src/components/NotAuthenticated.tsx | 20 +++- src/i18n/locales/en/auth.json | 1 + src/i18n/locales/en/core.json | 1 + src/i18n/locales/en/question.json | 13 ++- src/qortalRequests/get.ts | 157 +++++++++++++++++++++++----- 6 files changed, 161 insertions(+), 65 deletions(-) diff --git a/src/background.ts b/src/background.ts index c30488c..ea8f2ec 100644 --- a/src/background.ts +++ b/src/background.ts @@ -102,7 +102,6 @@ import { } from './background-cases'; import { getData, removeKeysAndLogout, storeData } from './utils/chromeStorage'; import TradeBotRespondRequest from './transactions/TradeBotRespondRequest'; -// import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch'; export let groupSecretkeys = {}; @@ -127,6 +126,7 @@ export const groupApi = 'https://ext-node.qortal.link'; export const groupApiSocket = 'wss://ext-node.qortal.link'; export const groupApiLocal = 'http://127.0.0.1:12391'; export const groupApiSocketLocal = 'ws://127.0.0.1:12391'; + const timeDifferenceForNotificationChatsBackground = 86400000; const requestQueueAnnouncements = new RequestQueueWithPromise(1); @@ -3423,8 +3423,7 @@ const checkGroupList = async () => { directs: sortedDirects, }); } catch (error) { - console.error(error); - } finally { + console.log(error); } }; @@ -3539,7 +3538,7 @@ export const checkNewMessages = async () => { targetOrigin ); } catch (error) { - } finally { + console.log(error); } }; @@ -3788,35 +3787,10 @@ export const checkThreads = async (bringBack) => { targetOrigin ); } catch (error) { - } finally { + console.log(error); } }; -// Configure Background Fetch -// BackgroundFetch.configure({ -// minimumFetchInterval: 15, // Minimum 15-minute interval -// enableHeadless: true, // Enable headless mode for Android -// }, async (taskId) => { -// // This is where your background task logic goes -// const wallet = await getSaveWallet(); -// const address = wallet.address0; -// if (!address) return; -// checkActiveChatsForNotifications(); -// checkNewMessages(); -// checkThreads(); - -// await new Promise((res)=> { -// setTimeout(() => { -// res() -// }, 55000); -// }) -// // Always finish the task when complete -// BackgroundFetch.finish(taskId); -// }, (taskId) => { -// // Optional timeout callback -// BackgroundFetch.finish(taskId); -// }); - let notificationCheckInterval; let paymentsCheckInterval; diff --git a/src/components/NotAuthenticated.tsx b/src/components/NotAuthenticated.tsx index 192379e..6100aed 100644 --- a/src/components/NotAuthenticated.tsx +++ b/src/components/NotAuthenticated.tsx @@ -359,7 +359,9 @@ export const NotAuthenticated = ({ }) .catch((error) => { console.error( - 'Failed to set API key:', + it('auth:message.error.unable_set_apikey', { + postProcess: 'capitalizeFirstChar', + }), error.message || t('core:message.error.generic', { postProcess: 'capitalizeFirstChar', @@ -396,7 +398,9 @@ export const NotAuthenticated = ({ }) .catch((error) => { console.error( - 'Failed to set API key:', + it('auth:message.error.unable_set_apikey', { + postProcess: 'capitalizeFirstChar', + }), error.message || t('core:message.error.generic', { postProcess: 'capitalizeFirstChar', @@ -678,7 +682,9 @@ export const NotAuthenticated = ({ }) .catch((error) => { console.error( - 'Failed to set API key:', + it('auth:message.error.unable_set_apikey', { + postProcess: 'capitalizeFirstChar', + }), error.message || t('core:message.error.generic', { postProcess: 'capitalizeFirstChar', @@ -830,7 +836,9 @@ export const NotAuthenticated = ({ }) .catch((error) => { console.error( - 'Failed to set API key:', + it('auth:message.error.unable_set_apikey', { + postProcess: 'capitalizeFirstChar', + }), error.message || t('core:message.error.generic', { postProcess: 'capitalizeFirstChar', @@ -894,7 +902,9 @@ export const NotAuthenticated = ({ }) .catch((error) => { console.error( - 'Failed to set API key:', + it('auth:message.error.unable_set_apikey', { + postProcess: 'capitalizeFirstChar', + }), error.message || t('core:message.error.generic', { postProcess: 'capitalizeFirstChar', diff --git a/src/i18n/locales/en/auth.json b/src/i18n/locales/en/auth.json index d4e171d..0f67622 100644 --- a/src/i18n/locales/en/auth.json +++ b/src/i18n/locales/en/auth.json @@ -60,6 +60,7 @@ "name_not_existing": "name does not exist", "name_not_registered": "name not registered", "unable_block_user": "unable to block user", + "unable_set_apikey": "failed to set API key:", "unable_fetch_user_account": "unable to fetch user account", "unable_decrypt": "unable to decrypt", "unable_reencrypt_secret_key": "unable to re-encrypt secret key" diff --git a/src/i18n/locales/en/core.json b/src/i18n/locales/en/core.json index 698e167..78013b5 100644 --- a/src/i18n/locales/en/core.json +++ b/src/i18n/locales/en/core.json @@ -173,6 +173,7 @@ "app_need_name": "your app needs a name", "file_too_large": "file {{ filename }} is too large. Max size allowed is {{ size }} MB.", "generic": "an error occurred", + "invalid_base64": "invalid base64 data", "invalid_embed_link": "invalid embed link", "invalid_poll_embed_link_name": "invalid poll embed link. Missing name.", "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 8a2f636..90bc8e5 100644 --- a/src/i18n/locales/en/question.json +++ b/src/i18n/locales/en/question.json @@ -2,21 +2,27 @@ "always_authenticate": "always authenticate automatically", "always_retrieve_balance": "always allow balance to be retrieved automatically", "always_retrieve_list": "always allow lists to be retrieved automatically", - "authenticate": "do you give this application permission to authenticate?", + "amount_qty": "amount: {{ quantity }}", + "asset_name": "asset: {{ asset }}", + "assets_used_pay": "asset used in payments: {{ asset }}", "description": "description: {{ description }}", "deploy_at": "would you like to deploy this AT?", "message": { "error": { + "create_sell_order": "failed to Create Sell Order. Try again!", "cancel_sell_order": "failed to Cancel Sell Order. Try again!", "fetch_balance": "unable to fetch balance", "fetch_group": "failed to fetch the group", "fetch_list": "failed to fetch the list", + "insufficient_balance": "your asset balance is insufficient", + "insufficient_balance_qort": "your QORT balance is insufficient", "missing_fields": "missing fields: {{ fields }}", "no_data_encrypted_resource": "no data in the encrypted resource", "no_group_found": "group not found", "no_group_key": "no group key found", "perform_request": "failed to perform request", "retrieve_file": "failed to retrieve file", + "submit_sell_order": "failed to submit sell order", "timeout_request": "request timed out", "unable_create_tradebot": "unable to create tradebot", "unable_decrypt": "unable to decrypt", @@ -37,6 +43,11 @@ "name": "name: {{ name }}", "option": "option: {{ option }}", "options": "options: {{ optionList }}", + "permission_authenticate": "do you give this application permission to authenticate?", + "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?", + "permission_transfer_asset": "do you give this application permission to transfer the following asset?", "poll": "poll: {{ name }}", "request_create_poll": "you are requesting to create the poll below:", "request_vote_poll": "you are being requested to vote on the poll below:" diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts index b48d0ca..6a7e7f5 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -503,7 +503,7 @@ export const getUserAccount = async ({ if (!skip) { resPermission = await getUserPermission( { - text1: i18n.t('question:authenticate', { + text1: i18n.t('question:permission_authenticate', { postProcess: 'capitalizeFirstChar', }), checkbox1: { @@ -916,8 +916,9 @@ export const getHostedData = async (data, isFromExtension) => { } const resPermission = await getUserPermission( { - text1: 'Do you give this application permission to', - text2: `Get a list of your hosted data?`, + text1: i18n.t('question:message.error.submit_sell_order', { + postProcess: 'capitalizeFirstChar', + }), }, isFromExtension ); @@ -964,8 +965,10 @@ export const deleteHostedData = async (data, isFromExtension) => { }); const resPermission = await getUserPermission( { - text1: 'Do you give this application permission to', - text2: `Delete ${data?.hostedData?.length} hosted resources?`, + text1: i18n.t('question:permission_delete_hosts_resources', { + size: data?.hostedData?.length, + postProcess: 'capitalizeFirstChar', + }), }, isFromExtension ); @@ -1205,7 +1208,12 @@ export const deleteListItems = async (data, isFromExtension) => { throw new Error(errorMsg); } if (!data?.item && !data?.items) { - throw new Error('Missing fields: items'); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: 'items', + postProcess: 'capitalizeFirstChar', + }) + ); } const item = data?.item; const items = data?.items; @@ -3488,7 +3496,12 @@ export const sendCoin = async (data, isFromExtension) => { throw new Error(errorMsg); } if (!data?.destinationAddress && !data?.recipient) { - throw new Error('Missing fields: recipient'); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: 'recipient', + postProcess: 'capitalizeFirstChar', + }) + ); } let checkCoin = data.coin; const wallet = await getSaveWallet(); @@ -4202,7 +4215,9 @@ const tradeBotCreateRequest = async (body, keyPair) => { body ); return { - error: 'Failed to Create Sell Order. Try again!', + error: i18n.t('question:message.error.create_sell_order', { + postProcess: 'capitalizeFirstChar', + }), failedTradeBot: findFailedTradeBot, }; } @@ -4210,7 +4225,11 @@ const tradeBotCreateRequest = async (body, keyPair) => { if (res?.signature) { return res; } else { - throw new Error('Failed to Create Sell Order. Try again!'); + throw new Error( + i18n.t('question:message.error.create_sell_order', { + postProcess: 'capitalizeFirstChar', + }) + ); } }; @@ -4279,7 +4298,12 @@ export const createSellOrder = async (data, isFromExtension) => { ); } } catch (error) { - throw new Error(error?.message || 'Failed to submit sell order.'); + throw new Error( + error?.message || + i18n.t('question:message.error.submit_sell_order', { + postProcess: 'capitalizeFirstChar', + }) + ); } }; @@ -4346,7 +4370,12 @@ export const cancelSellOrder = async (data, isFromExtension) => { ); } } catch (error) { - throw new Error(error?.message || 'Failed to submit sell order.'); + throw new Error( + error?.message || + i18n.t('question:message.error.submit_sell_order', { + postProcess: 'capitalizeFirstChar', + }) + ); } }; @@ -5485,7 +5514,12 @@ export const decryptAESGCMRequest = async (data, isFromExtension) => { const requiredFields = ['encryptedData', 'iv', 'senderPublicKey']; requiredFields.forEach((field) => { if (!data[field]) { - throw new Error(`Missing required field: ${field}`); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: field, + postProcess: 'capitalizeFirstChar', + }) + ); } }); @@ -5776,7 +5810,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { const requiredFields = ['payments', 'assetId']; requiredFields.forEach((field) => { if (data[field] === undefined || data[field] === null) { - throw new Error(`Missing required field: ${field}`); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: field, + postProcess: 'capitalizeFirstChar', + }) + ); } }); const resKeyPair = await getKeyPair(); @@ -5801,7 +5840,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { for (const field of requiredFieldsPayment) { if (!payment[field]) { - throw new Error(`Missing required field: ${field}`); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: field, + postProcess: 'capitalizeFirstChar', + }) + ); } } @@ -5829,7 +5873,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { for (const field of requiredFieldsArbitraryTx) { if (!arbitraryTx[field]) { - throw new Error(`Missing required field: ${field}`); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: field, + postProcess: 'capitalizeFirstChar', + }) + ); } } @@ -5840,7 +5889,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { } const isValid = isValidBase64WithDecode(arbitraryTx.base64); - if (!isValid) throw new Error('Invalid base64 data'); + if (!isValid) + throw new Error( + i18n.t('core:message.error.invalid_base64', { + postProcess: 'capitalizeFirstChar', + }) + ); if (!arbitraryTx?.service?.includes('_PRIVATE')) throw new Error('Please use a PRIVATE service'); const additionalPublicKeys = arbitraryTx?.additionalPublicKeys || []; @@ -5868,7 +5922,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { for (const field of requiredFieldsArbitraryTx) { if (!arbitraryTx[field]) { - throw new Error(`Missing required field: ${field}`); + throw new Error( + i18n.t('question:message.error.missing_fields', { + fields: field, + postProcess: 'capitalizeFirstChar', + }) + ); } } @@ -5879,7 +5938,12 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { } const isValid = isValidBase64WithDecode(arbitraryTx.base64); - if (!isValid) throw new Error('Invalid base64 data'); + if (!isValid) + throw new Error( + i18n.t('core:message.error.invalid_base64', { + postProcess: 'capitalizeFirstChar', + }) + ); if (!arbitraryTx?.service?.includes('_PRIVATE')) throw new Error('Please use a PRIVATE service'); const additionalPublicKeys = arbitraryTx?.additionalPublicKeys || []; @@ -5899,17 +5963,30 @@ export const multiPaymentWithPrivateData = async (data, isFromExtension) => { if (!name) throw new Error('A name is needed to publish'); const balance = await getBalanceInfo(); - if (+balance < fee) throw new Error('Your QORT balance is insufficient'); + if (+balance < fee) + throw new Error( + i18n.t('question:message.error.insufficient_balance_qort', { + postProcess: 'capitalizeFirstChar', + }) + ); const assetBalance = await getAssetBalanceInfo(assetId); const assetInfo = await getAssetInfo(assetId); if (assetBalance < totalAmount) - throw new Error('Your asset balance is insufficient'); + throw new Error( + i18n.t('question:message.error.insufficient_balance', { + postProcess: 'capitalizeFirstChar', + }) + ); const resPermission = await getUserPermission( { - text1: - 'Do you give this application permission to make the following payments and publishes?', - text2: `Asset used in payments: ${assetInfo.name}`, + text1: i18n.t('question:permission_pay_publish', { + postProcess: 'capitalizeFirstChar', + }), + text2: i18n.t('question:assets_used_pay', { + asset: assetInfo.name, + postProcess: 'capitalizeFirstChar', + }), html: `