Guide d'utilisation Annuler

Configurer un cadre de traduction pour un fournisseur de services

Découvrez comment configurer le cadre de traduction pour un fournisseur de services de traduction de votre choix afin de traduire dynamiquement votre contenu avec RoboHelp.

En plus des fournisseurs de traduction prédéfinis prêts à l'emploi, vous pouvez également intégrer votre connecteur de traduction pour répondre à vos besoins.  

Utilisation d’un script personnalisé pour la traduction

Pour configurer un fournisseur personnalisé, créez un fichier JavaScript sur le système.Le fichier contient une fonction avec la valeur de retour d’un objet. Cet objet retourné a un champ « appelant » et une fonction de type de retour JavaScript Promise comme valeur.

(src_lng, tar_lng, text2translate, API_KEY, endpoint) => {
//src_lang: source language
//tar_lang: target language
//text2translate: text to send for translation
//API_KEY: API key from your service provider
//endpoint: endpoint/API URL of your service provider
//build your query
var query:Function = //REST API goes here, which returns a Promise
return {
caller: query
}
}
(src_lng, tar_lng, text2translate, API_KEY, endpoint) => { //src_lang: source language //tar_lang: target language //text2translate: text to send for translation //API_KEY: API key from your service provider //endpoint: endpoint/API URL of your service provider //build your query var query:Function = //REST API goes here, which returns a Promise return { caller: query } }
(src_lng, tar_lng, text2translate, API_KEY, endpoint) => { 
 //src_lang: source language 
 //tar_lang: target language 
 //text2translate: text to send for translation 
 //API_KEY: API key from your service provider 
 //endpoint: endpoint/API URL of your service provider 
 //build your query  
 var query:Function = //REST API goes here, which returns a Promise 
 return { 
  caller: query  
 } 
}

appelant (fonction)

La fonction définie dans le champ appelant de l’objet retourné envoie la demande d’API REST au serveur à l’aide de la méthode « demande » de javascript, qui renvoie une promesse javascript. Résolvez/rejetez la promesse en conséquence et retournez finalement le texte traduit ou, en cas d’erreur, lancez une erreur.

Exemple de fichier de script Bing

(src_lng, tar_lng, text2translate, API_KEY, endpoint) => {
const uuidv4 = require('uuid/v4');
const request = require('request');
var api_request_fn = () => {
// return a promise because sending and receiving translated text is asynchronous procedure
return new Promise((resolve, reject) => {
var request_data = {
method: 'POST',
baseUrl: endpoint,
url: 'translate',
qs: {
'api-version': '3.0',
'to': [tar_lng]
},
headers: {
'Ocp-Apim-Subscription-Key': API_KEY, //your API key goes here
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString() //give an ID to your request
},
body: [{
'text': text2translate //send the text to translate as a part of the body
}],
json: true,
}
// the structure of request_data is different for every service provider
// look up the documentation provided by your translation service provider
// to build the request data.
request(request_data, function(err, res, body) {
// read about request method here https://www.npmjs.com/package/request
if(err) {// in case of an error reject the promise, it will exit the translation process
reject({body, err, res})
} else {// in case of a valid response from the server, resolve the promise
resolve({body, err, res})
}
})
}).then(data => {
if(data.body.error) {
// in case error from the server is send as part of the body
// and skipping the previous if block in request, handle it here
throw new Error(data.body.error.message);
// throw the error with the message you want to show,
// preferably the error message sent by the server
} else {
return data.body[0].translations[0].text
// return the translated text here, in this case it is in the data at
// the specified location. The location in the data object varies with the provider
}
})
}
}
(src_lng, tar_lng, text2translate, API_KEY, endpoint) => { const uuidv4 = require('uuid/v4'); const request = require('request'); var api_request_fn = () => { // return a promise because sending and receiving translated text is asynchronous procedure return new Promise((resolve, reject) => { var request_data = { method: 'POST', baseUrl: endpoint, url: 'translate', qs: { 'api-version': '3.0', 'to': [tar_lng] }, headers: { 'Ocp-Apim-Subscription-Key': API_KEY, //your API key goes here 'Content-type': 'application/json', 'X-ClientTraceId': uuidv4().toString() //give an ID to your request }, body: [{ 'text': text2translate //send the text to translate as a part of the body }], json: true, } // the structure of request_data is different for every service provider // look up the documentation provided by your translation service provider // to build the request data. request(request_data, function(err, res, body) { // read about request method here https://www.npmjs.com/package/request if(err) {// in case of an error reject the promise, it will exit the translation process reject({body, err, res}) } else {// in case of a valid response from the server, resolve the promise resolve({body, err, res}) } }) }).then(data => { if(data.body.error) { // in case error from the server is send as part of the body // and skipping the previous if block in request, handle it here throw new Error(data.body.error.message); // throw the error with the message you want to show, // preferably the error message sent by the server } else { return data.body[0].translations[0].text // return the translated text here, in this case it is in the data at // the specified location. The location in the data object varies with the provider } }) } }
(src_lng, tar_lng, text2translate, API_KEY, endpoint) => { 
     const uuidv4 = require('uuid/v4'); 
   const request = require('request'); 
 var api_request_fn = () => { 
   // return a promise because sending and receiving translated text is asynchronous procedure 
            return new Promise((resolve, reject) => {  
   var request_data = { 
              method: 'POST', 
              baseUrl: endpoint, 
              url: 'translate', 
              qs: { 
                'api-version': '3.0', 
                'to': [tar_lng] 
              }, 
              headers: { 
                 'Ocp-Apim-Subscription-Key': API_KEY, //your API key goes here 
                 'Content-type': 'application/json', 
                 'X-ClientTraceId': uuidv4().toString() //give an ID to your request 
              }, 
              body: [{ 
                    'text': text2translate //send the text to translate as a part of the body 
              }], 
              json: true, 
          }  
   // the structure of request_data is different for every service provider 
   // look up the documentation provided by your translation service provider  
   // to build the request data. 
 
                request(request_data, function(err, res, body) {  
     // read about request method here https://www.npmjs.com/package/request 
                    if(err) {// in case of an error reject the promise, it will exit the translation process 
                        reject({body, err, res}) 
                    } else {// in case of a valid response from the server, resolve the promise 
                        resolve({body, err, res}) 
                    } 
                }) 
            }).then(data => { 
                if(data.body.error) { 
     // in case error from the server is send as part of the body  
     // and skipping the previous if block in request, handle it here  
                    throw new Error(data.body.error.message); 
     // throw the error with the message you want to show,  
     // preferably the error message sent by the server 
                } else { 
                    return data.body[0].translations[0].text  
     // return the translated text here, in this case it is in the data at  
     // the specified location. The location in the data object varies with the provider 
                } 
            }) 
        } 
}

Nous avons parlé du builder d'API de traduction Bing dans l’exemple ci-dessus, notez que Google et yandex ont des gestionnaires différents de ceux de Bing. Créez cette fonction selon les spécifications fournies par votre fournisseur de services.

Nous vous recommandons fortement de consulter des exemples dans votre répertoire d’installation RoboHelp :   
"resources/data/template/translation/bing/profile_builder.js"
"resources/data/template/translation/google/profile_builder.js"
"resources/data/template/translation/yandex/profile_builder.js"
"resources/data/template/translation/deepl/profile_builder.js"

Remarque :
  1. Lorsque les clients utilisent ces fonctionnalités de traduction, les données sont envoyées au fournisseur à des fins de traitement. 
  2. L’utilisation et le traitement de ces données sont régis par le contrat du client avec le fournisseur et la politique de confidentialité du fournisseur, et Adobe n’est pas responsable du fournisseur.

Créer un profil d’intégration personnalisé

  1. Accédez aux profils de traduction. Pour plus d’informations, voir Créer un profil pour la traduction automatique.

  2. Cliquez sur + pour créer un profil.

  3. Dans la boîte de dialogue Profil de traduction, fournissez les détails de la clé API, du point de terminaison et du chemin d'accès de script personnalisé

  4. Cliquez sur Valider pour vérifier que les informations d’identification saisies sont correctes et complètes.

  5. Cliquez sur Enregistrer.

Recevez de l’aide plus rapidement et plus facilement

Nouvel utilisateur ?