Create services with validateParoles and translateLyrics
This commit is contained in:
@@ -3,6 +3,7 @@ const qs = require('qs')
|
||||
const axios = require('axios')
|
||||
|
||||
const { createCoreService } = require('@strapi/strapi').factories;
|
||||
const { ValidationError } = require("@strapi/utils").errors
|
||||
|
||||
class Translator {
|
||||
constructor() {
|
||||
@@ -37,5 +38,32 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
|
||||
const translator = new Translator()
|
||||
const data = await translator.get(origin, target, text)
|
||||
return data.translations[0].text
|
||||
},
|
||||
async translateLyrics(parolesFR) {
|
||||
const anglais = await this.translate('FR', 'EN', parolesFR)
|
||||
const espagnol = await this.translate('FR', 'ES', parolesFR)
|
||||
const allemand = await this.translate('FR', 'DE', parolesFR)
|
||||
const italien = await this.translate('FR', 'IT', parolesFR)
|
||||
|
||||
return {
|
||||
francais: parolesFR,
|
||||
anglais: anglais + '\n\n (Translated by DeepL)',
|
||||
espagnol: espagnol + '\n\n (Traducido por DeepL)',
|
||||
allemand: allemand + '\n\n (Übersetzt von DeepL)',
|
||||
italien: italien + '\n\n (Tradotto da DeepL)'
|
||||
}
|
||||
},
|
||||
validateParoles(titre, transcription) {
|
||||
if (!titre || titre.trim().length === 0) {
|
||||
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
|
||||
}
|
||||
|
||||
if (!transcription || transcription.trim().length === 0) {
|
||||
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
|
||||
}
|
||||
|
||||
if (transcription.trim().length < 10) {
|
||||
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user