Add translations

This commit is contained in:
Nicola Benaglia 2025-05-17 15:30:23 +02:00
parent 7e3c97c4a7
commit a7b7768d22
3 changed files with 37 additions and 15 deletions

View File

@ -185,7 +185,7 @@ export const AnnouncementDiscussion = ({
clearEditorContent(); clearEditorContent();
} }
// TODO send chat message // send chat message
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {

View File

@ -1,11 +1,8 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'; import { useEffect, useMemo, useRef, useState } from 'react';
import { getBaseApiReact } from '../../App'; import { getBaseApiReact } from '../../App';
import { CustomizedSnackbars } from '../Snackbar/Snackbar'; import { CustomizedSnackbars } from '../Snackbar/Snackbar';
import { extractComponents } from '../Chat/MessageDisplay'; import { extractComponents } from '../Chat/MessageDisplay';
import { executeEvent } from '../../utils/events'; import { executeEvent } from '../../utils/events';
import { base64ToBlobUrl } from '../../utils/fileReading'; import { base64ToBlobUrl } from '../../utils/fileReading';
import { import {
blobControllerAtom, blobControllerAtom,
@ -17,8 +14,8 @@ import { parseQortalLink } from './embed-utils';
import { PollCard } from './PollEmbed'; import { PollCard } from './PollEmbed';
import { ImageCard } from './ImageEmbed'; import { ImageCard } from './ImageEmbed';
import { AttachmentCard } from './AttachmentEmbed'; import { AttachmentCard } from './AttachmentEmbed';
import { decodeIfEncoded } from '../../utils/decode';
import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { useTranslation } from 'react-i18next';
const getPoll = async (name) => { const getPoll = async (name) => {
const pollName = name; const pollName = name;
@ -32,6 +29,7 @@ const getPoll = async (name) => {
}); });
const responseData = await response.json(); const responseData = await response.json();
if (responseData?.message?.includes('POLL_NO_EXISTS')) { if (responseData?.message?.includes('POLL_NO_EXISTS')) {
throw new Error('POLL_NO_EXISTS'); throw new Error('POLL_NO_EXISTS');
} else if (responseData?.pollName) { } else if (responseData?.pollName) {
@ -65,7 +63,7 @@ export const Embed = ({ embedLink }) => {
const [parsedData, setParsedData] = useState(null); const [parsedData, setParsedData] = useState(null);
const setBlobs = useSetAtom(blobControllerAtom); const setBlobs = useSetAtom(blobControllerAtom);
const [selectedGroupId] = useAtom(selectedGroupIdAtom); const [selectedGroupId] = useAtom(selectedGroupIdAtom);
const { t } = useTranslation(['auth', 'core', 'group']);
const resourceData = useMemo(() => { const resourceData = useMemo(() => {
const parsedDataOnTheFly = parseQortalLink(embedLink); const parsedDataOnTheFly = parseQortalLink(embedLink);
if ( if (
@ -108,11 +106,20 @@ export const Embed = ({ embedLink }) => {
setErrorMsg(''); setErrorMsg('');
setType('POLL'); setType('POLL');
if (!parsedData?.name) if (!parsedData?.name)
throw new Error('Invalid poll embed link. Missing name.'); throw new Error(
t('core:message.error.invalid_embed_link_name', {
postProcess: 'capitalizeFirst',
})
);
const pollRes = await getPoll(parsedData.name); const pollRes = await getPoll(parsedData.name);
setPoll(pollRes); setPoll(pollRes);
} catch (error) { } catch (error) {
setErrorMsg(error?.message || 'Invalid embed link'); setErrorMsg(
error?.message ||
t('core:message.error.invalid_embed_link', {
postProcess: 'capitalizeFirst',
})
);
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
@ -147,14 +154,15 @@ export const Embed = ({ embedLink }) => {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
}); });
const data = await responseData.text(); const data = await responseData.text();
if (data) { if (data) {
let decryptedData; let decryptedData;
try { try {
if (key && encryptionType === 'private') { if (key && encryptionType === 'private') {
decryptedData = await window.sendMessage( decryptedData = await window.sendMessage(
'DECRYPT_DATA_WITH_SHARING_KEY', 'DECRYPT_DATA_WITH_SHARING_KEY',
{ {
encryptedData: data, encryptedData: data,
key: decodeURIComponent(key), key: decodeURIComponent(key),
@ -164,7 +172,6 @@ export const Embed = ({ embedLink }) => {
if (encryptionType === 'group') { if (encryptionType === 'group') {
decryptedData = await window.sendMessage( decryptedData = await window.sendMessage(
'DECRYPT_QORTAL_GROUP_DATA', 'DECRYPT_QORTAL_GROUP_DATA',
{ {
data64: data, data64: data,
groupId: selectedGroupId, groupId: selectedGroupId,
@ -172,11 +179,19 @@ export const Embed = ({ embedLink }) => {
); );
} }
} catch (error) { } catch (error) {
throw new Error('Unable to decrypt'); throw new Error(
t('auth:message.error.unable_decrypt', {
postProcess: 'capitalizeFirst',
})
);
} }
if (!decryptedData || decryptedData?.error) if (!decryptedData || decryptedData?.error)
throw new Error('Could not decrypt data'); throw new Error(
t('auth:message.error.decrypt_data', {
postProcess: 'capitalizeFirst',
})
);
imageFinalUrl = base64ToBlobUrl( imageFinalUrl = base64ToBlobUrl(
decryptedData, decryptedData,
parsedData?.mimeType parsedData?.mimeType
@ -193,11 +208,14 @@ export const Embed = ({ embedLink }) => {
}; };
}); });
} else { } else {
throw new Error('No data for image'); throw new Error(
t('core:message.generic.no_data_image', {
postProcess: 'capitalizeFirst',
})
);
} }
} else { } else {
imageFinalUrl = `${getBaseApiReact()}/arbitrary/${service}/${name}/${identifier}?async=true`; imageFinalUrl = `${getBaseApiReact()}/arbitrary/${service}/${name}/${identifier}?async=true`;
// If parsedData is used here, it must be defined somewhere // If parsedData is used here, it must be defined somewhere
} }
} }
@ -219,6 +237,7 @@ export const Embed = ({ embedLink }) => {
if (imageFinalUrl) { if (imageFinalUrl) {
return imageFinalUrl; return imageFinalUrl;
} else { } else {
//TODO translate
setErrorMsg( setErrorMsg(
'Unable to download IMAGE. Please try again later by clicking the refresh button' 'Unable to download IMAGE. Please try again later by clicking the refresh button'
); );

View File

@ -136,6 +136,8 @@
"app_need_name": "your app needs a name", "app_need_name": "your app needs a name",
"file_too_large": "file {{ filename }} is too large. Max size allowed is {{ size }} MB.", "file_too_large": "file {{ filename }} is too large. Max size allowed is {{ size }} MB.",
"generic": "an error occurred", "generic": "an error occurred",
"invalid_embed_link": "invalid embed link",
"invalid_embed_link_name": "invalid poll embed link. Missing name.",
"invalid_signature": "invalid signature", "invalid_signature": "invalid signature",
"invalid_zip": "invalid zip", "invalid_zip": "invalid zip",
"message_loading": "error loading message.", "message_loading": "error loading message.",
@ -181,6 +183,7 @@
"name_rate": "you need a name to rate.", "name_rate": "you need a name to rate.",
"name_registration": "your balance is {{ balance }} QORT. A name registration requires a {{ fee }} QORT fee", "name_registration": "your balance is {{ balance }} QORT. A name registration requires a {{ fee }} QORT fee",
"name_unavailable": "{{ name }} is unavailable", "name_unavailable": "{{ name }} is unavailable",
"no_data_image": "no data for image",
"no_description": "no description", "no_description": "no description",
"no_minting_details": "cannot view minting details on the gateway", "no_minting_details": "cannot view minting details on the gateway",
"no_notifications": "no new notifications", "no_notifications": "no new notifications",