From c43ea1244c1cbb689eeab2bbf20c842034b286eb Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Sat, 4 Nov 2023 14:39:25 +0000 Subject: [PATCH] added email translation for contact --- .vscode/settings.json | 3 +++ public/locales/ae.json | 13 +++++++++++ public/locales/de.json | 13 +++++++++++ public/locales/en-GB.json | 13 +++++++++++ public/locales/en-US.json | 13 +++++++++++ public/locales/en.json | 13 +++++++++++ public/locales/es.json | 13 +++++++++++ public/locales/fr.json | 13 +++++++++++ public/locales/hi.json | 13 +++++++++++ public/locales/il.json | 13 +++++++++++ public/locales/in.json | 13 +++++++++++ public/locales/it.json | 13 +++++++++++ public/locales/jp.json | 13 +++++++++++ public/locales/pt.json | 13 +++++++++++ public/locales/ua.json | 13 +++++++++++ src/app/[locale]/components/contact.js | 19 +++++++++++++--- src/app/[locale]/favicon.ico | Bin 0 -> 15406 bytes src/app/[locale]/templates/email.js | 5 ++++- src/app/api/[locale]/sendemail/route.ts | 28 ++++++++++++++++++++++++ src/app/api/sendemail/route.ts | 25 --------------------- src/app/favicon.ico | Bin 0 -> 15406 bytes 21 files changed, 233 insertions(+), 29 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/app/[locale]/favicon.ico create mode 100644 src/app/api/[locale]/sendemail/route.ts delete mode 100644 src/app/api/sendemail/route.ts create mode 100644 src/app/favicon.ico diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9dabd54 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.maxTokenizationLineLength": 20000000 +} \ No newline at end of file diff --git a/public/locales/ae.json b/public/locales/ae.json index c65f995..833a28b 100644 --- a/public/locales/ae.json +++ b/public/locales/ae.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "د.إ" + }, + "Templates": { + "Email": { + "lang": "ae", + "thankyoumsg": "شكرًا لاتصالك بنا! إليك الرسالة:", + "emaildate": "تاريخ:", + "emailto": "ل:", + "emailfrom": "من:", + "emailname": "اسم:", + "emailsubject": "المادة:", + "emailbody": "رسالة:", + "copyright": "م الإنشاء بواسطة لويس كارفاليو " + } } } \ No newline at end of file diff --git a/public/locales/de.json b/public/locales/de.json index 72f0919..833f5f1 100644 --- a/public/locales/de.json +++ b/public/locales/de.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "€" + }, + "Templates": { + "Email": { + "lang": "de", + "thankyoumsg": "Danke, dass Sie uns kontaktiert haben! Hier ist die Nachricht:", + "emaildate": "Datum:", + "emailto": "Zu:", + "emailfrom": "Von:", + "emailname": "Name:", + "emailsubject": "Thema:", + "emailbody": "Botschaft:", + "copyright": "Erstellt von" + } } } \ No newline at end of file diff --git a/public/locales/en-GB.json b/public/locales/en-GB.json index 86ede46..efcf542 100644 --- a/public/locales/en-GB.json +++ b/public/locales/en-GB.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "£" + }, + "Templates": { + "Email": { + "lang": "en-GB", + "thankyoumsg": "Thank you for contact us! Here's the message:", + "emaildate": "Date:", + "emailto": "To:", + "emailfrom": "From:", + "emailname": "Name:", + "emailsubject": "Subject:", + "emailbody": "Body:", + "copyright": "Created by" + } } } \ No newline at end of file diff --git a/public/locales/en-US.json b/public/locales/en-US.json index 6969733..caaed24 100644 --- a/public/locales/en-US.json +++ b/public/locales/en-US.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "$" + }, + "Templates": { + "Email": { + "lang": "en-US", + "thankyoumsg": "Thank you for contact us! Here's the message:", + "emaildate": "Date:", + "emailto": "To:", + "emailfrom": "From:", + "emailname": "Name:", + "emailsubject": "Subject:", + "emailbody": "Body:", + "copyright": "Created by" + } } } \ No newline at end of file diff --git a/public/locales/en.json b/public/locales/en.json index 86ede46..9db9288 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "£" + }, + "Templates": { + "Email": { + "lang": "en", + "thankyoumsg": "Thank you for contact us! Here's the message:", + "emaildate": "Date:", + "emailto": "To:", + "emailfrom": "From:", + "emailname": "Name:", + "emailsubject": "Subject:", + "emailbody": "Body:", + "copyright": "Created by" + } } } \ No newline at end of file diff --git a/public/locales/es.json b/public/locales/es.json index 75b98aa..7b564de 100644 --- a/public/locales/es.json +++ b/public/locales/es.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "€" + }, + "Templates": { + "Email": { + "lang": "es", + "thankyoumsg": "¡Gracias por contactarnos! Aquí está el mensaje:", + "emaildate": "Fecha:", + "emailto": "Para:", + "emailfrom": "De:", + "emailname": "Nombre:", + "emailsubject": "Sujeto:", + "emailbody": "Mensaje:", + "copyright": "Creado por" + } } } \ No newline at end of file diff --git a/public/locales/fr.json b/public/locales/fr.json index 621ddb7..a9766e6 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "€" + }, + "Templates": { + "Email": { + "lang": "fr", + "thankyoumsg": "Merci de nous contacter! Voici le message:", + "emaildate": "Date:", + "emailto": "Pour:", + "emailfrom": "Depuis:", + "emailname": "Nom:", + "emailsubject": "Sujet:", + "emailbody": "Message:", + "copyright": "Créé par" + } } } \ No newline at end of file diff --git a/public/locales/hi.json b/public/locales/hi.json index 9558d1c..9f0c4d0 100644 --- a/public/locales/hi.json +++ b/public/locales/hi.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "$" + }, + "Templates": { + "Email": { + "lang": "hi", + "thankyoumsg": "Mahalo no kou ho'oka'a'ike mai iā mākou! Eia ka memo:", + "emaildate": "La:", + "emailto": "I:", + "emailfrom": "Mai:", + "emailname": "Inoa:", + "emailsubject": "Ke kumuhana:", + "emailbody": "Memo:", + "copyright": "Hana 'ia e" + } } } \ No newline at end of file diff --git a/public/locales/il.json b/public/locales/il.json index 9c77847..f7e17e7 100644 --- a/public/locales/il.json +++ b/public/locales/il.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "₪" + }, + "Templates": { + "Email": { + "lang": "il", + "thankyoumsg": "תודה שפנית אלינו! הנה ההודעה:", + "emaildate": "תַאֲרִיך:", + "emailto": "ל:", + "emailfrom": "מ:", + "emailname": "שֵׁם:", + "emailsubject": "נושא:", + "emailbody": "הוֹדָעָה:", + "copyright": "מיוצר ע'י" + } } } \ No newline at end of file diff --git a/public/locales/in.json b/public/locales/in.json index 50b6afa..b555848 100644 --- a/public/locales/in.json +++ b/public/locales/in.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "₹" + }, + "Templates": { + "Email": { + "lang": "in", + "thankyoumsg": "हमसे संपर्क करने के लिए धन्यवाद! संदेश यह है:", + "emaildate": "तारीख:", + "emailto": "को:", + "emailfrom": "से:", + "emailname": "नाम:", + "emailsubject": "विषय:", + "emailbody": "संदेश:", + "copyright": "द्वारा निर्मित" + } } } \ No newline at end of file diff --git a/public/locales/it.json b/public/locales/it.json index b5a1142..ee7eb8f 100644 --- a/public/locales/it.json +++ b/public/locales/it.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "€" + }, + "Templates": { + "Email": { + "lang": "it", + "thankyoumsg": "Grazie per averci contattato! Ecco il messaggio:", + "emaildate": "Data:", + "emailto": "A:", + "emailfrom": "Da:", + "emailname": "Nome:", + "emailsubject": "Soggetto:", + "emailbody": "Messaggio:", + "copyright": "Creato da" + } } } \ No newline at end of file diff --git a/public/locales/jp.json b/public/locales/jp.json index cd7768f..691ee01 100644 --- a/public/locales/jp.json +++ b/public/locales/jp.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "¥" + }, + "Templates": { + "Email": { + "lang": "jp", + "thankyoumsg": "「ご連絡いただきありがとうございます。メッセージは次のとおりです。」", + "emaildate": "日付:", + "emailto": "に:", + "emailfrom": "から:", + "emailname": "名前:", + "emailsubject": "主題:", + "emailbody": "メッセージ:", + "copyright": "によって作成された" + } } } \ No newline at end of file diff --git a/public/locales/pt.json b/public/locales/pt.json index 1e88bb8..5aa54c9 100644 --- a/public/locales/pt.json +++ b/public/locales/pt.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "€" + }, + "Templates": { + "Email": { + "lang": "pt", + "thankyoumsg": "Obrigado por entrar em contato conosco! Aqui está a mensagem:", + "emaildate": "Data:", + "emailto": "Para:", + "emailfrom": "De:", + "emailname": "Nome:", + "emailsubject": "Assunto:", + "emailbody": "Mensagem:", + "copyright": "Criado por" + } } } \ No newline at end of file diff --git a/public/locales/ua.json b/public/locales/ua.json index f40e120..2bb3487 100644 --- a/public/locales/ua.json +++ b/public/locales/ua.json @@ -134,5 +134,18 @@ }, "Currency": { "symbol": "₴" + }, + "Templates": { + "Email": { + "lang": "ua", + "thankyoumsg": "Дякуємо за звернення до нас! Ось повідомлення:", + "emaildate": "Дата:", + "emailto": "Кому:", + "emailfrom": "Від:", + "emailname": "Ім'я:", + "emailsubject": "Тема:", + "emailbody": "Тіло:", + "copyright": "Створено" + } } } \ No newline at end of file diff --git a/src/app/[locale]/components/contact.js b/src/app/[locale]/components/contact.js index 22d5f46..94c5bdd 100644 --- a/src/app/[locale]/components/contact.js +++ b/src/app/[locale]/components/contact.js @@ -2,10 +2,12 @@ import React, { useState } from 'react'; import styles from '../styles/page/page.module.scss'; -import { useTranslations } from 'next-intl'; +import { useLocale, useTranslations } from 'next-intl'; export default function ContactComponent() { const t = useTranslations('Home'); + const temailtrans = useTranslations('Templates.Email'); + const locale = useLocale(); const [name, setName] = useState(""); const [email, setEmail] = useState(""); @@ -35,10 +37,21 @@ export default function ContactComponent() { name: name, email: email, subject: subject, - message: message + message: message, + translationmsgs: { + lang: temailtrans('lang'), + thankyoumsg: temailtrans('thankyoumsg'), + emaildate: temailtrans('emaildate'), + emailto: temailtrans('emailto'), + emailfrom: temailtrans('emailfrom'), + emailname: temailtrans('emailname'), + emailsubject: temailtrans('emailsubject'), + emailbody: temailtrans('emailbody'), + copyright: temailtrans('copyright') + } }); - fetch('/api/sendemail', { + fetch('/api/'+ locale +'/sendemail', { method: "post", body: formData, headers: new Headers({ diff --git a/src/app/[locale]/favicon.ico b/src/app/[locale]/favicon.ico new file m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{|hi$t-h!o{5VXA~TuK9F2*@-<8Li zjNjCU9Gxe0^}zDbII2C;m~U=4h6KFrNzxu6irDvTZLx-KhX zy9`{v1YFDE_)I1-(ty(=iT{`j&vI86Vse6CzrPyic8%CCby}UluehUe#LU$sA>FB; zqcQXhFu#@-z#LnmYvQ`4mvjAV-O)?Z7cHeHhSHC)=W}X~?tK}KPHb1t1=`lp4Qv;X zZ~9F3#<>N)&J8E?M|lLwS~Gv9IW#Y6iw-i(#1w}lvo7vDE2~D!LenSBEzib9xx{yo z!;JfJyvx3!%)4veA>V1;SWTt5JN`UoURp>uG?I>JAaA3gv_~5mXx625V{KXw8He67 z0iVf4e9G2~=X(7^`N6~=z#6W(%wH8Uo9ceLJAUP<{{9Ct0?ni|-eexLrS!lEnTu0g z7fIB1B2u_gl9@$I;k7ig-c2js)MwQ`7pZ;M?Lc*;bPfN0B2*m@km+VVbhpGa|2Gcp zWhnlX2v%3-I$ht@K~%lIuHjFkZRyTAaftckw`71>Q>eBzigIXv$(K1*ohP~`^!gRf z70vzBj?ODf=o)^lebjlL$eFPLQTRxHBEEd{LAp0f<{Z*IRcq#{b>4U3{jX%2IgcuH zbN@NTcr9A#ul>Kl9$uhyYx{i{Wm1}qI&8n85AX`r?=!15rAEDh9H1OEZ{xn>mr literal 0 HcmV?d00001 diff --git a/src/app/[locale]/templates/email.js b/src/app/[locale]/templates/email.js index 3a8cd9f..aa32efb 100644 --- a/src/app/[locale]/templates/email.js +++ b/src/app/[locale]/templates/email.js @@ -1,5 +1,8 @@ // minify html code by using this website: https://codebeautify.org/minify-html +const year = new Date().getUTCFullYear(); +const curdate = new Date().toUTCString(); +const dirv = "auto"; -const EmailTemplate = (embody) => `Email

Thank you for contact us! Here's the message:

Date: ${new Date().toUTCString()}

To: ${process.env.EMAIL_USER}

From: ${embody.email}

Name: ${embody.name}

Subject: ${embody.subject}

Body: ${embody.message}

`; +const EmailTemplate = (embody, t) => `Email

${t.thankyoumsg ?? "Thank you for contact us! Here's the message:"}

${t.emaildate ?? "Date:"} ${curdate}

${t.emailto ?? "To:"} ${process.env.EMAIL_USER}

${t.emailfrom ?? "From:"} ${embody.email}

${t.emailname ?? "Name:"} ${embody.name}

${t.emailsubject ?? "Subject:"} ${embody.subject}

${t.emailbody ?? "Message:"} ${embody.message}

`; export { EmailTemplate } \ No newline at end of file diff --git a/src/app/api/[locale]/sendemail/route.ts b/src/app/api/[locale]/sendemail/route.ts new file mode 100644 index 0000000..3ba3c58 --- /dev/null +++ b/src/app/api/[locale]/sendemail/route.ts @@ -0,0 +1,28 @@ +import { NextResponse } from "next/server"; +import { sendMailUtil } from '../../../[locale]/utils/sendmailUtils'; +import { EmailTemplate } from '../../../[locale]/templates'; + +export async function POST(req: any) { + const body = await req.json(); + const curpath = `${process.env.TYPEENV === 'production' ? 'https://lcp-pi.vercel.app' : './public'}`; + const attachmentsobj = [{ + filename: 'logo_compact.png', + path: `${curpath}/images/logos/logo_compact.png`, + cid: 'uniquelogo' + }]; + + const dataobj = { + to: process.env.EMAIL_USER, + from: `"${body.name}" <${body.email}>`, + subject: body.subject, + text: `${body.message}\r\n Sent by ${body.email} (${body.name})`, + html: EmailTemplate(body, body.translationmsgs), + attachments: attachmentsobj + }; + + console.log(dataobj); + + await sendMailUtil(dataobj); + + return NextResponse.json({ dataobj }); +} \ No newline at end of file diff --git a/src/app/api/sendemail/route.ts b/src/app/api/sendemail/route.ts deleted file mode 100644 index 260a94b..0000000 --- a/src/app/api/sendemail/route.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { NextResponse } from "next/server"; -import { sendMailUtil } from '../../[locale]/utils/sendmailUtils'; -import { EmailTemplate } from '../../[locale]/templates'; - -export async function POST(req: any) { - const body = await req.json(); - const dataobj = { - to: process.env.EMAIL_USER, - from: `"${body.name}" <${body.email}>`, - subject: body.subject, - text: `${body.message}\r\n Sent by ${body.email} (${body.name})`, - html: EmailTemplate(body), - attachments: [{ - filename: 'logo_compact.png', - path: process.env.TYPEENV === 'production' ? "https://lcp-pi.vercel.app/images/logos/logo_compact.png" : "./public/images/logos/logo_compact.png", - cid: 'uniquelogo' - }] - }; - - console.log(dataobj); - - await sendMailUtil(dataobj); - - return NextResponse.json({ dataobj }); -} \ No newline at end of file diff --git a/src/app/favicon.ico b/src/app/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..d6e3988e38fad2e49515b18d1e27d30b6a59e427 GIT binary patch literal 15406 zcmeHNc~Dhl6u)FSjWvxnIZoM(jDM8PRMIqUnrW8POintvRwijv?xii}J|ek=ic99w zD4Mt-Svle;xga8n3kssRfFg?^sDK~>3g_4F+$Re9-t&QvC*(cM$Gz{~@4M%B&i%e~ z&v(u-3@@XB(YUd}qqi~WVZ(UcFbr>R+wWFQ3?qowe0*-)f6g%WG&PJ??86}(VY|+Q zUBdsAqU8vd%O)(9jY!4$YD;+;SCESW#7Pp*id`R{IvF@OA2>4#*!v7{J{TxI1C$lI z@C*UY`fY4@?(SEL$tr#!An>Kin{OwVQezF94{00t}+5BIG&hjIEk(D09 z5W_Eq@NYW~Vx8>3Ldt*Cm2Zg05W10(T(A1DvH~Dw0&w6(Ag&#dxfm!fsoKYFzxdsb zY6R?l0*LVjVqXE`I|2t^0wN7tJKl$W$#UT0M&R;Z;OZ&*G|qg9>VPBv*jMT2_yR|} z0Ea2B%Dwkl;(Cnyy>8*Cz@x{r{?%dPq%Zj=4|jZD^F4)xpY$lpi&xc2AZ1ih%rw2mt>RJPlERNg2-DfS?ta+hkJ z+vk56C*dV+V6eR*Ut_E+qAwYNW%TRSx7$}9hqXMaU0Ops8B3%!Bm4aIS?|aYyez(W zUOvIMw1X>TGXiJ>{bdDQu=qckdNtR-!tj2!Y>3bvcKhd8yCHan)UY>5w!4zbo zyNrdd3nj&&`vLtn=^o>r>B3(?4xe*d%P%>JFJ&rpKlF_RVybX&R*5o@ES%h zmR$4Q>t15I1Y;`>RP9j9zhdPiCJXKUeIQ*=qh$eROUQlT4qTx3H+{FP}j ztqNC%MV1EYwFVr;1s;^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