How to Translate Text from English to French; French to English with Deep Learning AI using Java

If you’re looking to include a cost efficient two-way French translation service in your application, we have you covered. Our English to French & French to English translation APIs use Deep Learning AI to generate clean, accurate translations, and they’re incredibly easy to implement: all you need to do is follow complementary instructions provided below to structure your API call using ready-to-run Java code examples.

Let’s begin by installing the API client. We can do so by adding a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

And then adding one to the pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Now we can call either (or both) of the French translation APIs using the code blocks provided below. Note that before calling either of these, you should head to our website and register a free account to get your Cloudmersive API key (which you will be required to include within the field indicated by the code comments).

Use the following code to call the English to French API iteration:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.LanguageTranslationApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
try {
LanguageTranslationResponse result = apiInstance.languageTranslationTranslateEngToFra(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateEngToFra");
e.printStackTrace();
}

And use the following to call the French to English API iteration:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.LanguageTranslationApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
try {
LanguageTranslationResponse result = apiInstance.languageTranslationTranslateFraToEng(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateFraToEng");
e.printStackTrace();
}

With that, you’re all done — no more code required. Prendre plaisir!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

436 Followers

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.