5

I am using below code to translate my web page. I am trying to set a default language(AF) when page load first time but it always translate my page in English(default) language so how can i set a default language with below script?

Here is my code:

   function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: 'af', layout: 
    google.translate.TranslateElement.InlineLayout.SIMPLE}, 
    'google_translate_element');
   }
2
  • Hey, refer this link to translate website to any specific language, on page load. Commented Oct 26, 2017 at 12:08
  • @ManpreetMatharu Okay Commented Aug 24, 2019 at 6:16

1 Answer 1

2

Google Translate uses a cookie called "googtrans" to track which language is selected. You can set that cookie yourself before the page loads and Google Translate will use it.

In your case :

 function googleTranslateElementInit() {
    
     // here we setting cookie by default for language we want
     $.cookie('googtrans', '/af/af');
     // cookie selection END here
    
     new google.translate.TranslateElement({pageLanguage: 'af', layout: 
     google.translate.TranslateElement.InlineLayout.SIMPLE}, 
     'google_translate_element');
  }

Hopefully, this can solve your issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.