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');
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With