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 LANG_MAP = {
fr: { field: 'francais', targetLang: 'fr', userPrompt: 'Tradui an fransé' },
en: { field: 'anglais', targetLang: 'en', userPrompt: 'Translate to English' },
es: { field: 'espagnol', targetLang: 'es', userPrompt: 'Traduce al español' },
de: { field: 'allemand', targetLang: 'de', userPrompt: 'Übersetze auf Deutsch' },
it: { field: 'italien', targetLang: 'it', userPrompt: 'Traduci in italiano' },
fr: { field: 'francais', targetLang: 'fr', userPrompt: 'Tradui an fransé' },
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', deeplTarget: 'ES', suffix: '\n\n (Traducido por DeepL)' },
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', 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)
@@ -82,18 +85,16 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
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)
const result = { francais: 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)'
for (const lang of ALL_LANGS) {
if (lang === 'fr') continue
const { field, deeplTarget, suffix } = LANG_MAP[lang]
const translated = await this.translate('FR', deeplTarget, parolesFR)
result[field] = translated + suffix
}
return result
},
validateParoles(titre, transcription) {
if (!titre || titre.trim().length === 0) {
@@ -197,12 +198,9 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
},
async bulkTranslateMissing() {
const TARGET_LANGS = [
{ lang: 'en', field: 'anglais', deeplTarget: 'EN', suffix: '\n\n(Translated by DeepL)' },
{ lang: 'es', field: 'espagnol', deeplTarget: 'ES', suffix: '\n\n(Traducido por DeepL)' },
{ 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 TARGET_LANGS = ALL_LANGS
.filter(lang => lang !== 'fr')
.map(lang => ({ lang, ...LANG_MAP[lang] }))
const pageSize = 100
let start = 0
+9
View File
@@ -21,6 +21,15 @@
},
"italien": {
"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: {
allemand: Schema.Attribute.RichText;
anglais: Schema.Attribute.RichText;
coreen: Schema.Attribute.RichText;
espagnol: Schema.Attribute.RichText;
francais: Schema.Attribute.RichText;
italien: Schema.Attribute.RichText;
japonais: Schema.Attribute.RichText;
portugais: Schema.Attribute.RichText;
};
}