feat: add pt-BR/ja/ko translation languages
Déploiement API BETA / build (push) Successful in 2m12s
Déploiement API PROD / build (push) Successful in 2m9s
Déploiement API BETA / deploy (push) Successful in 47s
Déploiement API PROD / deploy (push) Successful in 1m0s

This commit is contained in:
2026-07-03 13:40:22 +04:00
parent 2003948a9a
commit 34a54eaae9
3 changed files with 31 additions and 21 deletions
+19 -21
View File
@@ -6,11 +6,14 @@ const { createCoreService } = require('@strapi/strapi').factories;
const { ApplicationError } = require("@strapi/utils").errors const { ApplicationError } = require("@strapi/utils").errors
const LANG_MAP = { const LANG_MAP = {
fr: { field: 'francais', targetLang: 'fr', userPrompt: 'Tradui an fransé' }, fr: { field: 'francais', targetLang: 'fr', userPrompt: 'Tradui an fransé' },
en: { field: 'anglais', targetLang: 'en', userPrompt: 'Translate to English' }, en: { field: 'anglais', targetLang: 'en', userPrompt: 'Translate to English', deeplTarget: 'EN', suffix: '\n\n (Translated by DeepL)' },
es: { field: 'espagnol', targetLang: 'es', userPrompt: 'Traduce al español' }, es: { field: 'espagnol', targetLang: 'es', userPrompt: 'Traduce al español', deeplTarget: 'ES', suffix: '\n\n (Traducido por DeepL)' },
de: { field: 'allemand', targetLang: 'de', userPrompt: 'Übersetze auf Deutsch' }, de: { field: 'allemand', targetLang: 'de', userPrompt: 'Übersetze auf Deutsch', deeplTarget: 'DE', suffix: '\n\n (Übersetzt von DeepL)' },
it: { field: 'italien', targetLang: 'it', userPrompt: 'Traduci in italiano' }, it: { field: 'italien', targetLang: 'it', userPrompt: 'Traduci in italiano', deeplTarget: 'IT', suffix: '\n\n (Tradotto da DeepL)' },
pt: { field: 'portugais', targetLang: 'pt', userPrompt: 'Traduza para o português', deeplTarget: 'PT-BR', suffix: '\n\n (Traduzido pela DeepL)' },
ja: { field: 'japonais', targetLang: 'ja', userPrompt: '日本語に翻訳して', deeplTarget: 'JA', suffix: '\n\n (DeepLによる翻訳)' },
ko: { field: 'coreen', targetLang: 'ko', userPrompt: '한국어로 번역해줘', deeplTarget: 'KO', suffix: '\n\n (DeepL 번역)' },
} }
const ALL_LANGS = Object.keys(LANG_MAP) const ALL_LANGS = Object.keys(LANG_MAP)
@@ -82,18 +85,16 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
return data.translations[0].text return data.translations[0].text
}, },
async translateLyrics(parolesFR) { async translateLyrics(parolesFR) {
const anglais = await this.translate('FR', 'EN', parolesFR) const result = { francais: 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 { for (const lang of ALL_LANGS) {
francais: parolesFR, if (lang === 'fr') continue
anglais: anglais + '\n\n (Translated by DeepL)', const { field, deeplTarget, suffix } = LANG_MAP[lang]
espagnol: espagnol + '\n\n (Traducido por DeepL)', const translated = await this.translate('FR', deeplTarget, parolesFR)
allemand: allemand + '\n\n (Übersetzt von DeepL)', result[field] = translated + suffix
italien: italien + '\n\n (Tradotto da DeepL)'
} }
return result
}, },
validateParoles(titre, transcription) { validateParoles(titre, transcription) {
if (!titre || titre.trim().length === 0) { if (!titre || titre.trim().length === 0) {
@@ -197,12 +198,9 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
}, },
async bulkTranslateMissing() { async bulkTranslateMissing() {
const TARGET_LANGS = [ const TARGET_LANGS = ALL_LANGS
{ lang: 'en', field: 'anglais', deeplTarget: 'EN', suffix: '\n\n(Translated by DeepL)' }, .filter(lang => lang !== 'fr')
{ lang: 'es', field: 'espagnol', deeplTarget: 'ES', suffix: '\n\n(Traducido por DeepL)' }, .map(lang => ({ lang, ...LANG_MAP[lang] }))
{ lang: 'de', field: 'allemand', deeplTarget: 'DE', suffix: '\n\n(Übersetzt von DeepL)' },
{ lang: 'it', field: 'italien', deeplTarget: 'IT', suffix: '\n\n(Tradotto da DeepL)' },
]
const pageSize = 100 const pageSize = 100
let start = 0 let start = 0
+9
View File
@@ -21,6 +21,15 @@
}, },
"italien": { "italien": {
"type": "richtext" "type": "richtext"
},
"portugais": {
"type": "richtext"
},
"japonais": {
"type": "richtext"
},
"coreen": {
"type": "richtext"
} }
} }
} }
+3
View File
@@ -93,9 +93,12 @@ export interface TradTraductions extends Struct.ComponentSchema {
attributes: { attributes: {
allemand: Schema.Attribute.RichText; allemand: Schema.Attribute.RichText;
anglais: Schema.Attribute.RichText; anglais: Schema.Attribute.RichText;
coreen: Schema.Attribute.RichText;
espagnol: Schema.Attribute.RichText; espagnol: Schema.Attribute.RichText;
francais: Schema.Attribute.RichText; francais: Schema.Attribute.RichText;
italien: Schema.Attribute.RichText; italien: Schema.Attribute.RichText;
japonais: Schema.Attribute.RichText;
portugais: Schema.Attribute.RichText;
}; };
} }