From f1d62fe11bb3a300a6cb760f4a82094e5568525a Mon Sep 17 00:00:00 2001 From: Nicola Benaglia Date: Sat, 10 May 2025 10:42:33 +0200 Subject: [PATCH] Translate newThread --- public/locales/en/core.json | 14 ++- public/locales/en/group.json | 7 +- src/components/Group/Forum/NewThread.tsx | 115 +++++++++++++---------- src/components/Home/NewUsersCTA.tsx | 2 +- 4 files changed, 86 insertions(+), 52 deletions(-) diff --git a/public/locales/en/core.json b/public/locales/en/core.json index fc7748d..5e3295d 100644 --- a/public/locales/en/core.json +++ b/public/locales/en/core.json @@ -11,6 +11,7 @@ "close": "close", "continue": "continue", "continue_logout": "continue to logout", + "create_thread": "create thread", "decline": "decline", "decrypt": "decrypt", "edit": "edit", @@ -19,7 +20,13 @@ "invite": "invite", "join": "join", "logout": "logout", - "notify": "notify" + "new": { + "post": "new post", + "thread": "new thread" + }, + "notify": "notify", + "post": "post", + "post_message": "post message" }, "core": { "block_height": "block height", @@ -50,6 +57,7 @@ "error": { "generic": "an error occurred", "incorrect_password": "incorrect password", + "missing_field": "missing: {{ field }}", "save_qdn": "unable to save to QDN" }, "status": { @@ -66,7 +74,6 @@ } }, "minting_status": "minting status", - "new_user": "are you a new user?", "page": { "last": "last", "first": "first", @@ -76,6 +83,9 @@ "payment_notification": "payment notification", "price": "price", "q_mail": "q-mail", + "question": { + "new_user": "are you a new user?" + }, "save_options": { "no_pinned_changes": "you currently do not have any changes to your pinned apps", "overwrite_changes": "the app was unable to download your existing QDN-saved pinned apps. Would you like to overwrite those changes?", diff --git a/public/locales/en/group.json b/public/locales/en/group.json index 64b9a73..713fa9c 100644 --- a/public/locales/en/group.json +++ b/public/locales/en/group.json @@ -48,6 +48,7 @@ "not_part_group": "you are not part of the encrypted group of members. Wait until an admin re-encrypts the keys.", "only_encrypted": "only unencrypted messages will be displayed.", "private_key_copied": "private key copied", + "provide_message": "please provide a first message to the thread", "secure_place": "keep your private key in a secure place. Do not share!", "setting_group": "setting up group... please wait." }, @@ -56,8 +57,10 @@ "descrypt_wallet": "error decrypting wallet {{ :errorMessage }}", "description_required": "please provide a description", "group_info": "cannot access group information", + "group_secret_key": "cannot get group secret key", "name_required": "please provide a name", - "notify_admins": "try notifying an admin from the list of admins below:" + "notify_admins": "try notifying an admin from the list of admins below:", + "thread_id": "unable to locate thread Id" }, "success": { "group_creation": "successfully created group. It may take a couple of minutes for the changes to propagate", @@ -70,6 +73,8 @@ "group_join_request": "requested to join Group {{group_name}}: awaiting confirmation", "group_join_outcome": "requested to join Group {{group_name}}: success!", "loading_threads": "loading threads... please wait.", + "post_creation": "successfully created post. It may take some time for the publish to propagate", + "thread_creation": "successfully created thread. It may take some time for the publish to propagate", "unbanned_user": "successfully unbanned user. It may take a couple of minutes for the changes to propagate" } } diff --git a/src/components/Group/Forum/NewThread.tsx b/src/components/Group/Forum/NewThread.tsx index 3279058..0de6269 100644 --- a/src/components/Group/Forum/NewThread.tsx +++ b/src/components/Group/Forum/NewThread.tsx @@ -203,8 +203,11 @@ export const NewThread = ({ // if (!description) missingFields.push('subject') if (missingFields.length > 0) { const missingFieldsString = missingFields.join(', '); - const errMsg = `Missing: ${missingFieldsString}`; - errorMsg = errMsg; // TODO translate + const errMsg = t('group:message.error.missing_field', { + field: missingFieldsString, + postProcess: 'capitalize', + }); + errorMsg = errMsg; } if (errorMsg) { @@ -213,8 +216,12 @@ export const NewThread = ({ const htmlContent = editorRef.current.getHTML(); - if (!htmlContent?.trim() || htmlContent?.trim() === '

') - throw new Error('Please provide a first message to the thread'); + if (!htmlContent?.trim() || htmlContent?.trim() === '

') { + const errMsg = t('group:message.generic.provide_message', { + postProcess: 'capitalize', + }); + throw new Error(errMsg); + } const fee = await getFee('ARBITRARY'); let feeToShow = fee.fee; @@ -237,6 +244,7 @@ export const NewThread = ({ delete reply.reply; } } + const mailObject: any = { createdAt: Date.now(), version: 1, @@ -249,7 +257,10 @@ export const NewThread = ({ const secretKey = isPrivate === false ? null : await getSecretKey(false, true); if (!secretKey && isPrivate) { - throw new Error('Cannot get group secret key'); + const errMsg = t('group:message.error.group_secret_key', { + postProcess: 'capitalize', + }); + throw new Error(errMsg); } if (!isMessage) { @@ -272,17 +283,18 @@ export const NewThread = ({ isPrivate === false ? threadToBase64 : await encryptSingleFunc(threadToBase64, secretKey); - let identifierThread = `grp-${groupInfo.groupId}-thread-${idThread}`; + const identifierThread = `grp-${groupInfo.groupId}-thread-${idThread}`; await publishGroupEncryptedResource({ identifier: identifierThread, encryptedData: encryptSingleThread, }); - let identifierPost = `thmsg-${identifierThread}-${idMsg}`; + const identifierPost = `thmsg-${identifierThread}-${idMsg}`; await publishGroupEncryptedResource({ identifier: identifierPost, encryptedData: encryptSingleFirstPost, }); + const dataToSaveToStorage = { name: myName, identifier: identifierThread, @@ -291,6 +303,7 @@ export const NewThread = ({ created: Date.now(), groupId: groupInfo.groupId, }; + const dataToSaveToStoragePost = { name: myName, identifier: identifierPost, @@ -299,6 +312,7 @@ export const NewThread = ({ created: Date.now(), threadId: identifierThread, }; + await saveTempPublish({ data: dataToSaveToStorage, key: 'thread' }); await saveTempPublish({ data: dataToSaveToStoragePost, @@ -306,36 +320,32 @@ export const NewThread = ({ }); setInfoSnack({ type: 'success', - message: - 'Successfully created thread. It may take some time for the publish to propagate', + message: t('group:message.success.thread_creation', { + postProcess: 'capitalize', + }), }); setOpenSnack(true); - // dispatch( - // setNotification({ - // msg: "Message sent", - // alertType: "success", - // }) - // ); if (publishCallback) { publishCallback(); } closeModal(); } else { - if (!currentThread) throw new Error('unable to locate thread Id'); + if (!currentThread) { + const errMsg = t('group:message.error.thread_id', { + postProcess: 'capitalize', + }); + throw new Error(errMsg); + } const idThread = currentThread.threadId; const messageToBase64 = await objectToBase64(mailObject); const encryptSinglePost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(messageToBase64, secretKey); - const idMsg = uid.rnd(); - let identifier = `thmsg-${idThread}-${idMsg}`; - const res = await publishGroupEncryptedResource({ - identifier: identifier, - encryptedData: encryptSinglePost, - }); + const idMsg = uid.rnd(); + const identifier = `thmsg-${idThread}-${idMsg}`; const dataToSaveToStoragePost = { threadId: idThread, name: myName, @@ -348,32 +358,17 @@ export const NewThread = ({ data: dataToSaveToStoragePost, key: 'thread-post', }); - // await qortalRequest(multiplePublishMsg); - // dispatch( - // setNotification({ - // msg: "Message sent", - // alertType: "success", - // }) - // ); setInfoSnack({ type: 'success', - message: - 'Successfully created post. It may take some time for the publish to propagate', + message: t('group:message.success.post_creation', { + postProcess: 'capitalize', + }), }); setOpenSnack(true); if (publishCallback) { publishCallback(); } - // messageCallback({ - // identifier, - // id: identifier, - // name, - // service: MAIL_SERVICE_TYPE, - // created: Date.now(), - // ...mailObject, - // }); } - closeModal(); } catch (error: any) { if (error?.message) { @@ -392,6 +387,7 @@ export const NewThread = ({ const sendMail = () => { publishQDNResource(); }; + return ( setIsOpen(true)} > - {currentThread ? 'New Post' : 'New Thread'} + + {currentThread + ? t('core:action.new.post', { + postProcess: 'capitalize', + }) + : t('core:action.new.thread', { + postProcess: 'capitalize', + })} + - {isMessage ? 'Post Message' : 'New Thread'} + {isMessage + ? t('core:action.post_message', { + postProcess: 'capitalize', + }) + : t('core:action.new.thread', { + postProcess: 'capitalize', + })} + + + {isSending && ( - {isMessage ? 'Post' : 'Create Thread'} + {isMessage + ? t('core:action.post', { + postProcess: 'capitalize', + }) + : t('core:action.create_thread', { + postProcess: 'capitalize', + })} {isMessage ? ( diff --git a/src/components/Home/NewUsersCTA.tsx b/src/components/Home/NewUsersCTA.tsx index 44666d6..68e8b06 100644 --- a/src/components/Home/NewUsersCTA.tsx +++ b/src/components/Home/NewUsersCTA.tsx @@ -36,7 +36,7 @@ export const NewUsersCTA = ({ balance }) => { textAlign: 'center', }} > - {t('core:new_user', { postProcess: 'capitalize' })} + {t('core:question.new_user', { postProcess: 'capitalize' })}