How to integrate Salesforce with Google translate.

60b8d91411f0b7080d3d162f
Google APIs, Google translation API, Salesforce, Salesforce lightning, Integration
Google APIs, Google translation API, Salesforce, Salesforce lightning, Integration
About the author
Nadia Recarey
Salesforce specialist
Share this article

In this article, we will show you how to integrate Salesforce with Google Translate. You will learn how to translate text in Salesforce using a Lightning Web Component and the Google Translation API.

Here’s a sample of what we will be developing.

You might think of looking for a package on the AppExchange, but it is highly probable they use Google Translation API as well, and it is actually really easy to use.

You can check out the details here

https://cloud.google.com/translate and prices here https://cloud.google.com/translate/
pricing. Bear in mind that translation usage is calculated in millions of characters, where 1 million = 106 characters.

It might be helpful if you already have some knowledge about:

  1. Apex and Lightning Web Component development
  2. API requests/responses

What do we need?

A project on Google Cloud to use the Translate API (we will use the API Key that Google provides us). For more information about how to create a project on Google Cloud, click here.

What will be developing?

We will create a simple Lightning Web Component that will only contain an input field where we are going to enter our text that we want to translate, and a button that will call our apex method to translate it.

We’ll create:
  • An Apex class

GoogleTranslateHelper: A Google Translate Helper class that will contain the callout to the Google Translate API.

  • A Lightning Web Component

Translate: A simple LWC that will show us the translated text.

You can see the code in the following GitHub repo

https://github.com/ NadiaRecarey/ googleTranslationOnSalesforce .

Ok, let’s dive into it!

1. Store your API Key

When you get your API Key from Google, you might want to have it stored somewhere in Salesforce rather than hardcoded, so we are going to create a new field called “Google_Translate_API_Key__c” on a custom setting to save it there.

2. Register Google Translation API endpoint in the Remote Site Settings page

To add a remote site setting:

  1. From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.
  2. Click New Remote Site.
  3. Enter Google_Translate as Remote Site Name.
  4. Enter https://www.googleapis.com as the URL for the remote site.
  5. Optionally, enter a description of the site.
  6. Click Save.

3. Create an Apex Class: GoogleTranslateHelper

This class will contain two methods: getTranslatedText and googleTranslateCallout.

Method googleTranslateCallout

As we see on the comment before the method declaration, the response we should expect from the Google Translation API is a JSON that contains an array within the data object. This array, Translations, will contain all the translated texts we sent in the request, and the detected language of the original text.

This method will be called directly from the LWC and will receive a list of texts we wish to translate. Remember that for us to be able to call Apex methods from LWC js files, we have to denote the method with the @auraEnabled decorator.

In line 37 we call the other method googleTranslateCallout, which will actually make the callout to the google API.

After we got a response from the callout, we parse it using the JSON Apex class and then return it.

As we see on the comment before the method declaration, the response we should expect from the Google Translation API is a JSON that contains an array within the data object. This array, Translations, will contain all the translated texts we sent in the request, and the detected language of the original text.

This method will be called directly from the LWC and will receive a list of texts we wish to translate. Remember that for us to be able to call Apex methods from LWC js files, we have to denote the method with the @auraEnabled decorator.

In line 37 we call the other method googleTranslateCallout, which will actually make the callout to the google API.

After we got a response from the callout, we parse it using the JSON Apex class and then return it.

About the author
Nadia Recarey
Share this article
How to integrate Salesforce with Google translate.
How to integrate Salesforce with Google translate.
Re-writing your career path: how to start a job in IT.
Re-writing your career path: how to start a job in IT.
Salesforce Summer ’21 Release is here, we picked up the top 5 new features!
Salesforce Summer ’21 Release is here, we picked up the top 5 new features!
A day to learn, connect and have fun.
A day to learn, connect and have fun.
Welcome to our new website
Welcome to our new website
Introducing a hybrid work model
Introducing a hybrid work model
Building a Digital Experience
Building a Digital Experience
We join the Pledge 1% Movement to donate 1% of staff time to the Community
We join the Pledge 1% Movement to donate 1% of staff time to the Community
Dreamforce is coming!
Dreamforce is coming!
Our Dreamforce 2021 takeaways
Our Dreamforce 2021 takeaways
We are Salesforce Talent Alliance members!
We are Salesforce Talent Alliance members!
What’s it like to work at Modelit?
What’s it like to work at Modelit?
Salesforce’s requirement to Enable Multi-Factor Authentication (MFA)
Salesforce’s requirement to Enable Multi-Factor Authentication (MFA)
Why should you hire a Nearshore team?
Why should you hire a Nearshore team?
The new TrailblazerDX is on its way.
The new TrailblazerDX is on its way.
We've become Salesforce PDO partners!
We've become Salesforce PDO partners!
The Latest and Greatest from TrailblazerDX '22: A Recap of Salesforce's Event
The Latest and Greatest from TrailblazerDX '22: A Recap of Salesforce's Event
How Agile Methodology can help you thrive with Salesforce
How Agile Methodology can help you thrive with Salesforce
The importance of stand-ups: why they're essential for agile teams and clients
The importance of stand-ups: why they're essential for agile teams and clients
How staff augmentation can benefit your organization
How staff augmentation can benefit your organization
How to make the most out of Salesforce
How to make the most out of Salesforce
Dreamforce 2022 is almost here!
Dreamforce 2022 is almost here!
Salesforce Tips: Dealing with 15 vs 18-character Record IDs
Salesforce Tips: Dealing with 15 vs 18-character Record IDs
Your Guide to Dreamforce 2022: How to Survive and Thrive
Your Guide to Dreamforce 2022: How to Survive and Thrive
Why we’re Salesforce certified and you should be too!
Why we’re Salesforce certified and you should be too!
Salesforce Winter ‘23 release: Modelit’s Top 10 Takeaways
Salesforce Winter ‘23 release: Modelit’s Top 10 Takeaways
Why should you complete a Salesforce Health Check?
Why should you complete a Salesforce Health Check?
Dreamforce 2022: On-demand content highlights
Dreamforce 2022: On-demand content highlights
Dreamforce 2022: Modelit’s top takeaways
Dreamforce 2022: Modelit’s top takeaways
Getting to know Salesforce Genie
Getting to know Salesforce Genie
Introducing the Salesforce Associate Certificate
Introducing the Salesforce Associate Certificate
Syncing Contact, Email and Events from your Gmail or Outlook to Salesforce using Einstein Activity Capture
Syncing Contact, Email and Events from your Gmail or Outlook to Salesforce using Einstein Activity Capture
Soft skills in the Salesforce ecosystem
Soft skills in the Salesforce ecosystem
How to maximize your marketing efforts with Salesforce Marketing Cloud
How to maximize your marketing efforts with Salesforce Marketing Cloud
Our year in review: Modelit 2022
Our year in review: Modelit 2022
Modelit launches Bolt, fast-hiring platform for Salesforce talent
Modelit launches Bolt, fast-hiring platform for Salesforce talent
Salesforce Spring ‘23 release: Modelit’s Highlights
Salesforce Spring ‘23 release: Modelit’s Highlights
Economic Uncertainty: How Nearshore Outsourcing Can Help
Economic Uncertainty: How Nearshore Outsourcing Can Help
Notes from the CEO: Is your Salesforce costing more than you think?
Notes from the CEO: Is your Salesforce costing more than you think?
Mastering Staff Augmentation: How Modelit Confronts Communication Challenges
Mastering Staff Augmentation: How Modelit Confronts Communication Challenges
Previous
There are no previous blog posts.
Next
There are no next blog posts.
Mohammed
March 4, 2022

I want to Translate PDF into salesforce .

Archana
January 19, 2022

Do you have any idea if google translate V3 API can be integrated in Salesforce?

Leave a reply

Your email address will not be published. Required fields are marked *
Thank you! Your reply has been received!
Oops! Something went wrong while posting the comment.

Get in touch

Message sent successfully.

Thanks so much for contacting us! We received your message and will get back to you within the next 48 hrs.

Your message was not sent.

While we take a look at our server, you can Write us an email.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.