Add translations to appRating

This commit is contained in:
Nicola Benaglia 2025-05-15 19:26:43 +02:00
parent 3e6d2f5e4b
commit e94ff9ef09
6 changed files with 31 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import { StarFilledIcon } from '../../assets/Icons/StarFilled';
import { StarEmptyIcon } from '../../assets/Icons/StarEmpty'; import { StarEmptyIcon } from '../../assets/Icons/StarEmpty';
import { AppInfoUserName } from './Apps-styles'; import { AppInfoUserName } from './Apps-styles';
import { Spacer } from '../../common/Spacer'; import { Spacer } from '../../common/Spacer';
import { useTranslation } from 'react-i18next';
export const AppRating = ({ app, myName, ratingCountPosition = 'right' }) => { export const AppRating = ({ app, myName, ratingCountPosition = 'right' }) => {
const [value, setValue] = useState(0); const [value, setValue] = useState(0);
@ -19,6 +20,7 @@ export const AppRating = ({ app, myName, ratingCountPosition = 'right' }) => {
const [openSnack, setOpenSnack] = useState(false); const [openSnack, setOpenSnack] = useState(false);
const [infoSnack, setInfoSnack] = useState(null); const [infoSnack, setInfoSnack] = useState(null);
const hasCalledRef = useRef(false); const hasCalledRef = useRef(false);
const { t } = useTranslation(['core', 'group']);
const getRating = useCallback(async (name, service) => { const getRating = useCallback(async (name, service) => {
try { try {
@ -101,26 +103,39 @@ export const AppRating = ({ app, myName, ratingCountPosition = 'right' }) => {
const rateFunc = async (event, chosenValue, currentValue) => { const rateFunc = async (event, chosenValue, currentValue) => {
try { try {
const newValue = chosenValue || currentValue; const newValue = chosenValue || currentValue;
if (!myName) throw new Error('You need a name to rate.'); if (!myName)
throw new Error(
t('core:message.generic.name_rate', {
postProcess: 'capitalize',
})
);
if (!app?.name) return; if (!app?.name) return;
const fee = await getFee('CREATE_POLL'); const fee = await getFee('CREATE_POLL');
await show({ await show({
// TODO translate message: t('core:message.error.generic', {
message: `Would you like to rate this app a rating of ${newValue}?. It will create a POLL tx.`, rate: newValue,
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
if (hasPublishedRating === false) { if (hasPublishedRating === false) {
const pollName = `app-library-${app.service}-rating-${app.name}`; const pollName = `app-library-${app.service}-rating-${app.name}`;
const pollOptions = [`1, 2, 3, 4, 5, initialValue-${newValue}`]; const pollOptions = [`1, 2, 3, 4, 5, initialValue-${newValue}`];
const pollDescription = t('core:message.error.generic', {
name: app.name,
service: app.service,
postProcess: 'capitalize',
});
await new Promise((res, rej) => { await new Promise((res, rej) => {
window window
.sendMessage( .sendMessage(
'createPoll', 'createPoll',
{ {
pollName: pollName, pollName: pollName,
pollDescription: `Rating for ${app.service} ${app.name}`, pollDescription: pollDescription,
pollOptions: pollOptions, pollOptions: pollOptions,
pollOwnerAddress: myName, pollOwnerAddress: myName,
}, },
@ -137,7 +152,7 @@ export const AppRating = ({ app, myName, ratingCountPosition = 'right' }) => {
message: message:
'Successfully rated. Please wait a couple minutes for the network to propogate the changes.', 'Successfully rated. Please wait a couple minutes for the network to propogate the changes.',
}); });
setOpenSnack(true); setOpenSnack(true); // TODO translate
} }
}) })
.catch((error) => { .catch((error) => {

View File

@ -1,4 +1,4 @@
import React, { useContext, useState } from 'react'; import { useContext, useState } from 'react';
import { executeEvent } from '../../utils/events'; import { executeEvent } from '../../utils/events';
import { getBaseApiReact, MyContext } from '../../App'; import { getBaseApiReact, MyContext } from '../../App';
import { createEndpoint } from '../../background'; import { createEndpoint } from '../../background';
@ -7,10 +7,9 @@ import {
sortablePinnedAppsAtom, sortablePinnedAppsAtom,
} from '../../atoms/global'; } from '../../atoms/global';
import { saveToLocalStorage } from './AppsNavBarDesktop'; import { saveToLocalStorage } from './AppsNavBarDesktop';
import { base64ToBlobUrl } from '../../utils/fileReading';
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption'; import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption'; import { uint8ArrayToObject } from '../../backgroundFunctions/encryption';
import { useAtom, useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
export const useHandlePrivateApps = () => { export const useHandlePrivateApps = () => {
const [status, setStatus] = useState(''); const [status, setStatus] = useState('');

View File

@ -1,7 +1,7 @@
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'; import { useCallback, useContext, useEffect, useState } from 'react';
import { executeEvent } from '../../utils/events'; import { executeEvent } from '../../utils/events';
import { navigationControllerAtom } from '../../atoms/global'; import { navigationControllerAtom } from '../../atoms/global';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { Filesystem, Directory } from '@capacitor/filesystem';
import { saveFile } from '../../qortalRequests/get'; import { saveFile } from '../../qortalRequests/get';
import { mimeToExtensionMap } from '../../utils/memeTypes'; import { mimeToExtensionMap } from '../../utils/memeTypes';
import { MyContext } from '../../App'; import { MyContext } from '../../App';

View File

@ -111,7 +111,7 @@ export const GeneralNotifications = ({ address }) => {
userSelect: 'none', userSelect: 'none',
}} }}
> >
No new notifications {t('core:message.generic.no_notifications')}
</Typography> </Typography>
)} )}
{hasNewPayment && ( {hasNewPayment && (

View File

@ -233,7 +233,7 @@ export const Save = ({ isDesktop, disableWidth, myName }) => {
{isDesktop ? ( {isDesktop ? (
<IconWrapper <IconWrapper
disableWidth={disableWidth} disableWidth={disableWidth}
label={t('core:save_options.save', { label={t('core:action.save', {
postProcess: 'capitalize', postProcess: 'capitalize',
})} })}
selected={false} selected={false}
@ -409,7 +409,7 @@ export const Save = ({ isDesktop, disableWidth, myName }) => {
onClick={saveToQdn} onClick={saveToQdn}
variant="contained" variant="contained"
> >
{t('core:save_options.save_qdn', { {t('core:action.save_qdn', {
postProcess: 'capitalize', postProcess: 'capitalize',
})} })}
</LoadingButton> </LoadingButton>

View File

@ -98,12 +98,15 @@
"name_available": "{{ name }} is available", "name_available": "{{ name }} is available",
"name_benefits": "benefits of a name", "name_benefits": "benefits of a name",
"name_checking": "checking if name already exists", "name_checking": "checking if name already exists",
"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_description": "no description", "no_description": "no description",
"no_notifications": "no new notifications",
"one_app_per_name": "note: Currently, only one App and Website is allowed per Name.", "one_app_per_name": "note: Currently, only one App and Website is allowed per Name.",
"publish_data": "publish data to Qortal: anything from apps to videos. Fully decentralized!", "publish_data": "publish data to Qortal: anything from apps to videos. Fully decentralized!",
"publishing": "publishing... Please wait.", "publishing": "publishing... Please wait.",
"rating": "rating for {{ service }} {{ name }}",
"secure_ownership": "secure ownership of data published by your name. You can even sell your name, along with your data to a third party.", "secure_ownership": "secure ownership of data published by your name. You can even sell your name, along with your data to a third party.",
"select_zip": "select .zip file containing static content:" "select_zip": "select .zip file containing static content:"
}, },
@ -146,13 +149,13 @@
"publish_app": "would you like to publish this app?", "publish_app": "would you like to publish this app?",
"publish_qdn": "would you like to publish your settings to QDN (encrypted)?", "publish_qdn": "would you like to publish your settings to QDN (encrypted)?",
"qdn": "use QDN saving", "qdn": "use QDN saving",
"rate_app": "would you like to rate this app a rating of {{ rate }}?. It will create a POLL tx.",
"register_name": "you need a registered Qortal name to save your pinned apps to QDN.", "register_name": "you need a registered Qortal name to save your pinned apps to QDN.",
"reset_pinned": "don't like your current local changes? Would you like to reset to the default pinned apps?", "reset_pinned": "don't like your current local changes? Would you like to reset to the default pinned apps?",
"reset_qdn": "don't like your current local changes? Would you like to reset to your saved QDN pinned apps?", "reset_qdn": "don't like your current local changes? Would you like to reset to your saved QDN pinned apps?",
"revert_default": "revert to default", "revert_default": "revert to default",
"revert_qdn": "revert to QDN", "revert_qdn": "revert to QDN",
"save_qdn": "save to QDN", "save_qdn": "save to QDN",
"save": "save",
"settings": "you are using the export/import way of saving settings.", "settings": "you are using the export/import way of saving settings.",
"unsaved_changes": " you have unsaved changes to your pinned apps. Save them to QDN." "unsaved_changes": " you have unsaved changes to your pinned apps. Save them to QDN."
}, },