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();
}
// TODO send chat message
// send chat message
} catch (error) {
console.error(error);
} 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 { CustomizedSnackbars } from '../Snackbar/Snackbar';
import { extractComponents } from '../Chat/MessageDisplay';
import { executeEvent } from '../../utils/events';
import { base64ToBlobUrl } from '../../utils/fileReading';
import {
blobControllerAtom,
@ -17,8 +14,8 @@ import { parseQortalLink } from './embed-utils';
import { PollCard } from './PollEmbed';
import { ImageCard } from './ImageEmbed';
import { AttachmentCard } from './AttachmentEmbed';
import { decodeIfEncoded } from '../../utils/decode';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { useTranslation } from 'react-i18next';
const getPoll = async (name) => {
const pollName = name;
@ -32,6 +29,7 @@ const getPoll = async (name) => {
});
const responseData = await response.json();
if (responseData?.message?.includes('POLL_NO_EXISTS')) {
throw new Error('POLL_NO_EXISTS');
} else if (responseData?.pollName) {
@ -65,7 +63,7 @@ export const Embed = ({ embedLink }) => {
const [parsedData, setParsedData] = useState(null);
const setBlobs = useSetAtom(blobControllerAtom);
const [selectedGroupId] = useAtom(selectedGroupIdAtom);
const { t } = useTranslation(['auth', 'core', 'group']);
const resourceData = useMemo(() => {
const parsedDataOnTheFly = parseQortalLink(embedLink);
if (
@ -108,11 +106,20 @@ export const Embed = ({ embedLink }) => {
setErrorMsg('');
setType('POLL');
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);
setPoll(pollRes);
} catch (error) {
setErrorMsg(error?.message || 'Invalid embed link');
setErrorMsg(
error?.message ||
t('core:message.error.invalid_embed_link', {
postProcess: 'capitalizeFirst',
})
);
} finally {
setIsLoading(false);
}
@ -147,14 +154,15 @@ export const Embed = ({ embedLink }) => {
'Content-Type': 'application/json',
},
});
const data = await responseData.text();
if (data) {
let decryptedData;
try {
if (key && encryptionType === 'private') {
decryptedData = await window.sendMessage(
'DECRYPT_DATA_WITH_SHARING_KEY',
{
encryptedData: data,
key: decodeURIComponent(key),
@ -164,7 +172,6 @@ export const Embed = ({ embedLink }) => {
if (encryptionType === 'group') {
decryptedData = await window.sendMessage(
'DECRYPT_QORTAL_GROUP_DATA',
{
data64: data,
groupId: selectedGroupId,
@ -172,11 +179,19 @@ export const Embed = ({ embedLink }) => {
);
}
} catch (error) {
throw new Error('Unable to decrypt');
throw new Error(
t('auth:message.error.unable_decrypt', {
postProcess: 'capitalizeFirst',
})
);
}
if (!decryptedData || decryptedData?.error)
throw new Error('Could not decrypt data');
throw new Error(
t('auth:message.error.decrypt_data', {
postProcess: 'capitalizeFirst',
})
);
imageFinalUrl = base64ToBlobUrl(
decryptedData,
parsedData?.mimeType
@ -193,11 +208,14 @@ export const Embed = ({ embedLink }) => {
};
});
} else {
throw new Error('No data for image');
throw new Error(
t('core:message.generic.no_data_image', {
postProcess: 'capitalizeFirst',
})
);
}
} else {
imageFinalUrl = `${getBaseApiReact()}/arbitrary/${service}/${name}/${identifier}?async=true`;
// If parsedData is used here, it must be defined somewhere
}
}
@ -219,6 +237,7 @@ export const Embed = ({ embedLink }) => {
if (imageFinalUrl) {
return imageFinalUrl;
} else {
//TODO translate
setErrorMsg(
'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",
"file_too_large": "file {{ filename }} is too large. Max size allowed is {{ size }} MB.",
"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_zip": "invalid zip",
"message_loading": "error loading message.",
@ -181,6 +183,7 @@
"name_rate": "you need a name to rate.",
"name_registration": "your balance is {{ balance }} QORT. A name registration requires a {{ fee }} QORT fee",
"name_unavailable": "{{ name }} is unavailable",
"no_data_image": "no data for image",
"no_description": "no description",
"no_minting_details": "cannot view minting details on the gateway",
"no_notifications": "no new notifications",