Adapt lifecycles parole with translation
This commit is contained in:
@@ -76,14 +76,14 @@ const jwennUserAdminEpiId = async userAdminId => {
|
|||||||
return userAdmin
|
return userAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
const translateTeks = async teksFR => {
|
const translateLyrics = async parolesFR => {
|
||||||
const english = await strapi.services.translator.translate('FR', 'EN', teksFR)
|
const english = await strapi.services.translator.translate('FR', 'EN', parolesFR)
|
||||||
const espagnol = await strapi.services.translator.translate('FR', 'ES', teksFR)
|
const espagnol = await strapi.services.translator.translate('FR', 'ES', parolesFR)
|
||||||
const deutsch = await strapi.services.translator.translate('FR', 'DE', teksFR)
|
const deutsch = await strapi.services.translator.translate('FR', 'DE', parolesFR)
|
||||||
const italiano = await strapi.services.translator.translate('FR', 'IT', teksFR)
|
const italiano = await strapi.services.translator.translate('FR', 'IT', parolesFR)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
francais: teksFR,
|
francais: parolesFR,
|
||||||
english: english + '\n\n (Translated by DeepL)',
|
english: english + '\n\n (Translated by DeepL)',
|
||||||
espagnol: espagnol + '\n\n (Traducido por DeepL)',
|
espagnol: espagnol + '\n\n (Traducido por DeepL)',
|
||||||
deutsch: deutsch + '\n\n (Übersetzt von DeepL)',
|
deutsch: deutsch + '\n\n (Übersetzt von DeepL)',
|
||||||
@@ -91,16 +91,16 @@ const translateTeks = async teksFR => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateParoles = (tit, transkripsyon) => {
|
const validateParoles = (titre, transcription) => {
|
||||||
if (!tit || tit.trim().length === 0) {
|
if (!titre || titre.trim().length === 0) {
|
||||||
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
|
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transkripsyon || transkripsyon.trim().length === 0) {
|
if (!transcription || transcription.trim().length === 0) {
|
||||||
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
|
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transkripsyon.trim().length < 10) {
|
if (transcription.trim().length < 10) {
|
||||||
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
|
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ const validateParoles = (tit, transkripsyon) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
beforeCreate: async event => {
|
beforeCreate: async event => {
|
||||||
let {data} = event.params
|
let {data} = event.params
|
||||||
validateParoles(data.tit, data.transkripsyon)
|
validateParoles(data.titre, data.transcription)
|
||||||
|
|
||||||
const user = await jwennUserEpiId(data?.user?.id)
|
const user = await jwennUserEpiId(data?.user?.id)
|
||||||
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
const userAdmin = await jwennUserAdminEpiId(data?.createdBy)
|
||||||
@@ -117,9 +117,9 @@ module.exports = {
|
|||||||
data.userAdmin = userAdmin
|
data.userAdmin = userAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.tit && !data.forceSlug) {
|
if (data.titre && !data.forceSlug) {
|
||||||
const artiste = await jwennAwtisEpiId(data.artistes)
|
const artiste = await jwennAwtisEpiId(data.artistes)
|
||||||
data.slug = getSlug(artiste, data.tit)
|
data.slug = getSlug(artiste, data.titre)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSlugExistance = await isSlugExists(data.slug)
|
const getSlugExistance = await isSlugExists(data.slug)
|
||||||
@@ -128,22 +128,22 @@ module.exports = {
|
|||||||
throw new ValidationError('Un morceau du même artiste existe déjà.')
|
throw new ValidationError('Un morceau du même artiste existe déjà.')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user && user.canAutoTranslate && data.tradiksyonOtomatik && data.tradiksyon.francais && (!data.tradiksyon.english || !data.tradiksyon.espagnol || !data.tradiksyon.deutsch || !data.tradiksyon.italiano)) {
|
if (user && user.canAutoTranslate && data.traductionAuto && data.titre.francais && (!data.transcription.english || !data.transcription.espagnol || !data.transcription.deutsch || !data.transcription.italiano)) {
|
||||||
const translate = await translateTeks(data.tradiksyon.francais)
|
const translated = await translateLyrics(data.traduction.francais)
|
||||||
data.tradiksyon = translate
|
data.traductions = translated
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
beforeUpdate: async event => {
|
beforeUpdate: async event => {
|
||||||
let {data} = event.params
|
let {data} = event.params
|
||||||
validateParoles(data.tit, data.transkripsyon)
|
validateParoles(data.titre, data.transcription)
|
||||||
|
|
||||||
const {where} = event.params
|
const {where} = event.params
|
||||||
|
|
||||||
if(!data.publishedAt) {
|
if(!data.publishedAt) {
|
||||||
if (data.tit && !data.forceSlug) {
|
if (data.tit && !data.forceSlug) {
|
||||||
const artiste = await jwennAwtisEpiId(data.artistes)
|
const artiste = await jwennAwtisEpiId(data.artistes)
|
||||||
data.slug = getSlug(artiste, data.tit)
|
data.slug = getSlug(artiste, data.titre)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +163,8 @@ module.exports = {
|
|||||||
strapi.plugins['email'].services.email.send({
|
strapi.plugins['email'].services.email.send({
|
||||||
from: process.env.SMTP_FROM,
|
from: process.env.SMTP_FROM,
|
||||||
to: previousData.user.email,
|
to: previousData.user.email,
|
||||||
subject: `Publication de "${previousData.tit}"`,
|
subject: `Publication de "${previousData.titre}"`,
|
||||||
html: `<p>Le titre que vous avez soumis, <strong>"${previousData.tit}"</strong> a été publié sur le site.</p>
|
html: `<p>Le titre que vous avez soumis, <strong>"${previousData.titre}"</strong> a été publié sur le site.</p>
|
||||||
<p>Vous pouvez le trouver à l'adresse <a href="${process.env.WEBSITE_URL}/paroles/${previousData.slug}">${process.env.WEBSITE_URL}/paroles/${previousData.slug}</a>.</p><p>Merci pour votre contribution ❤️</p>`
|
<p>Vous pouvez le trouver à l'adresse <a href="${process.env.WEBSITE_URL}/paroles/${previousData.slug}">${process.env.WEBSITE_URL}/paroles/${previousData.slug}</a>.</p><p>Merci pour votre contribution ❤️</p>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -173,8 +173,8 @@ module.exports = {
|
|||||||
strapi.plugins['email'].services.email.send({
|
strapi.plugins['email'].services.email.send({
|
||||||
from: process.env.SMTP_FROM,
|
from: process.env.SMTP_FROM,
|
||||||
to: previousData.userAdmin.email,
|
to: previousData.userAdmin.email,
|
||||||
subject: `Publication de "${previousData.tit}"`,
|
subject: `Publication de "${previousData.titre}"`,
|
||||||
html: `<p>Le titre que vous avez soumis, <strong>"${previousData.tit}"</strong> a été publié sur le site.</p>
|
html: `<p>Le titre que vous avez soumis, <strong>"${previousData.titre}"</strong> a été publié sur le site.</p>
|
||||||
<p>Vous pouvez le trouver à l'adresse <a href="${process.env.WEBSITE_URL}/paroles/${previousData.slug}">${process.env.WEBSITE_URL}/paroles/${previousData.slug}</a>.</p><p>Merci pour votre contribution ❤️</p>`
|
<p>Vous pouvez le trouver à l'adresse <a href="${process.env.WEBSITE_URL}/paroles/${previousData.slug}">${process.env.WEBSITE_URL}/paroles/${previousData.slug}</a>.</p><p>Merci pour votre contribution ❤️</p>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -192,8 +192,8 @@ module.exports = {
|
|||||||
strapi.plugins['email'].services.email.send({
|
strapi.plugins['email'].services.email.send({
|
||||||
from: process.env.SMTP_FROM,
|
from: process.env.SMTP_FROM,
|
||||||
to: process.env.SMTP_SEND_TO,
|
to: process.env.SMTP_SEND_TO,
|
||||||
subject: `Nouveau texte de ${user.username} : "${data.tit}" (site)`,
|
subject: `Nouveau texte de ${user.username} : "${data.titre}" (site)`,
|
||||||
html: `Le titre <strong>"${data.tit}"</strong> a été soumis depuis le site.`
|
html: `Le titre <strong>"${data.titre}"</strong> a été soumis depuis le site.`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,8 +201,8 @@ module.exports = {
|
|||||||
strapi.plugins['email'].services.email.send({
|
strapi.plugins['email'].services.email.send({
|
||||||
from: process.env.SMTP_FROM,
|
from: process.env.SMTP_FROM,
|
||||||
to: process.env.SMTP_SEND_TO,
|
to: process.env.SMTP_SEND_TO,
|
||||||
subject: `Nouveau texte de ${userAdmin.firstname} : "${data.tit}" (site)`,
|
subject: `Nouveau texte de ${userAdmin.firstname} : "${data.titre}" (site)`,
|
||||||
html: `Le titre <strong>"${data.tit}"</strong> a été soumis depuis le site.`
|
html: `Le titre <strong>"${data.titre}"</strong> a été soumis depuis le site.`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user