DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Recurrent Workflows With Cloud Native Dapr Jobs
  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • Understanding Java Signals

Trending

  • Streamlining Event Data in Event-Driven Ansible
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • SQL Server Index Optimization Strategies: Best Practices with Ola Hallengren’s Scripts
  • A Modern Stack for Building Scalable Systems
  1. DZone
  2. Coding
  3. Java
  4. How to Translate a Language in Java

How to Translate a Language in Java

Leverage Deep Learning AI to translate text in ENG to FRA, FRA to ENG, ENG to DEU, DEU to ENG, ENG to RUS, or RUS to ENG.

By 
Brian O'Neill user avatar
Brian O'Neill
DZone Core CORE ·
Feb. 09, 21 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
26.4K Views

Join the DZone community and get the full member experience.

Join For Free

Since the internet stepped into the spotlight in the late twentieth century, it has been doing its part to facilitate globalization on a massive scale. With companies increasing international transactions and individuals from across the world connecting online, we are all growing closer each day. 

While these personal and business connections are teaching us a lot about our various cultures, we still encounter language barriers. These barriers can cause considerable inconvenience and frustration for users and businesses alike, which is why the developments that have been made in language translation technology are so valuable.

This brings us to the translation solution that we will be discussing today; if you need to automate language translation between English and either French, German, or Russian, we have a few APIs to help with that. Leveraging Deep Learning AI, we offer the following natural language processing functions:

  • English to French.
  • French to English.
  • English to German.
  • German to English.
  • English to Russian.
  • Russian to English.

In this article, I will guide you through how to use these APIs in Java. Each API will begin with the same few steps but will alter when it comes to creating an instance of the API. 

Now to start things off, we will first need to install the SDK with Maven by adding a reference to the repository in pom.xml:

Java
 




x


 
1
<repositories>
2
    <repository>
3
        <id>jitpack.io</id>
4
        <url>https://jitpack.io</url>
5
    </repository>
6
</repositories>



Then, we will add a reference to the dependency:

Java
 




xxxxxxxxxx
1


 
1
<dependencies>
2
<dependency>
3
    <groupId>com.github.Cloudmersive</groupId>
4
    <artifactId>Cloudmersive.APIClient.Java</artifactId>
5
    <version>v3.54</version>
6
</dependency>
7
</dependencies>



Our next step is to add the imports to the controller, and configure the API key:

Java
 




xxxxxxxxxx
1
15


 
 
1
// Import classes:
2
//import com.cloudmersive.client.invoker.ApiClient;
3
//import com.cloudmersive.client.invoker.ApiException;
4
//import com.cloudmersive.client.invoker.Configuration;
5
//impot com.cloudmersive.client.invoker.auth.*;
6
//import com.cloudmersive.client.LanguageTranslationApi;
7

          
8
ApiClient defaultClient = Configuration.getDefaultApiClient();
9

          
10
// Configure API key authorization: Apikey
11
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
12
Apikey.setApiKey("YOUR API KEY");
13
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
14
//Apikey.setApiKeyPrefix("Token");



Now, we come to the variable section of the code; this is where you will input your translation request, instance the API, and call the function for your specific request. I will provide each code for our six translation options below.

English (ENG) to French (FRA):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateEngToFra(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateEngToFra");
8
    e.printStackTrace();
9
}



French (FRA) to English (ENG):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateFraToEng(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateFraToEng");
8
    e.printStackTrace();
9
}



English (ENG) to German (DEU):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateEngToDeu(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateEngToDeu");
8
    e.printStackTrace();
9
}



German (DEU) to English (ENG):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateDeuToEng(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateDeuToEng");
8
    e.printStackTrace();
9
}



English (ENG) to Russian (RUS):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateEngToRus(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateEngToRus");
8
    e.printStackTrace();
9
}



Russian (RUS) to English (ENG):

Java
 




xxxxxxxxxx
1
10
9


 
1
LanguageTranslationApi apiInstance = new LanguageTranslationApi();
2
LanguageTranslationRequest input = new LanguageTranslationRequest(); // LanguageTranslationRequest | Input translation request
3
try {
4
    LanguageTranslationResponse result = apiInstance.languageTranslationTranslateRusToEng(input);
5
    System.out.println(result);
6
} catch (ApiException e) {
7
    System.err.println("Exception when calling LanguageTranslationApi#languageTranslationTranslateRusToEng");
8
    e.printStackTrace();
9
}



Et c’est tout! Or in English, and that’s all! In order for the request to be successful, you must be sure to correctly input both your translation request and your API key.

Java (programming language) ENGLISH (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Recurrent Workflows With Cloud Native Dapr Jobs
  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • Understanding Java Signals

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!