Add Google translate button on your webpage of blogger (not Google translate default widget)

DEBIPRASAD
0

Add Google translate button on your webpage of blogger 


 Google Translate is a free online language translation service that allows you to translate text from one language to another.

 You can add the Google Translate widget to your website or blog, which will allow your visitors to translate your content into their preferred language. 

But here I will provide the actual button format through which you can actually  translate the homepage or any post page to a specific language through buttons.

This is not the default translate widget of google it is a pure button format. You don't need any Google translate API. You only need the HTML code and nothing.

Here is the HTML Code.

——————————————————————————————————————---------------

<!DOCTYPE html>

<html lang="en-US">

<head>

 <meta charset="UTF-8">

 <title>Google Translate Example</title>

 <style>

  #google_translate_element {

   display: none;

  }

  .translate-button {

   background-color: #007bff;

   color: #fff;

   padding: 10px 20px;

   border-radius: 5px;

   border: none;

   margin-right: 10px;

   cursor: pointer;

  }

  .translate-button:hover {

   background-color: #0062cc;

  }

 </style>

</head>

<body>


 <div>

  <button class="translate-button" onclick="translateToEnglish()">Translate to English</button>

  <button class="translate-button" onclick="translateToHindi()">Translate to हिंदी</button>

 </div>

<div id="google_translate_element"></div>

 <script type="text/javascript">

  function googleTranslateElementInit() {

   new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');

  }

 </script>

 <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

 <script>

  function translateToEnglish() {

   var select = document.querySelector(".goog-te-combo");

   select.value = "en";

   select.dispatchEvent(new Event('change'));

  }

  function translateToHindi() {

   var select = document.querySelector(".goog-te-combo");

   select.value = "hi";

   select.dispatchEvent(new Event('change'));

  }

 </script>


</body>

</html>

-—-——————————————————————————————————————----------

If you want add the button in post page then, copy the code 

1.  Open the post page where you want to add .


Html code for Google translate buttons
2.  Change compose view to html view.


Html code for Google translate buttons



Clear the space between<p> and </p>

Html code for Google translate buttons
3.  Then paste the code on the top of page.

Inbetween<p> and</p> and update it.

Html code for Google translate buttons


4.  Here is the result 


Html code for Google translate buttons



Remember some important points

  • "You have to add the code before adding the content to it."
  • "In this code, I have only provided buttons for two specific languages, through which you can switch between them."
  • "I have provided buttons for only two languages - Hindi and English. You can change them by replacing the Hindi and English text in the code with the text of the language you want."


 If you want to translate the Homepage or the whole page you have to add it as a widget to your blog's sidebar or footer by going to the "Layout" section in your Blogger dashboard and adding a new HTML/JavaScript gadget. Simply copy and paste the Google Translate widget code into the gadget and save.


1.  Choose layout option on the blogger dashboard 
Html code for Google translate buttons


2.  Click add a gadget where you want to place it
Html code for Google translate buttons


Html code for Google translate buttons



3.  Click on HTML/Javascript 


Html code for Google translate buttons


4.  Name a title to the gadget like “Translate”.

 Paste the html code on the content section and save it.

Html code for Google translate buttons



5.  Here is the result.

Html code for Google translate buttons


For other websites, you can add the Google Translate widget by adding the JavaScript code to the HTML code of your website. You can also use CodePen to create custom Google Translate widgets using JavaScript and CSS.

Overall, adding the Google Translate widget to your website or blog is a great way to make your content accessible to a wider audience who may speak different languages.

Post a Comment

0Comments
Post a Comment (0)

Featured Post

Australian Universities' Bans Indian Students from Specific Indian States

 Australian Universities' Restrictions on Students from Selected Indian States: Unveiling Concerns and Clarifications Introduction: A re...