Translate Webpage

This feature uses the Website Translator by Google to allow users to translate the content of your webpage to all supported languages.


The parameters allowed are present on Google's webpage.

You can add this method to a button with an onclick event, for example:

<button onclick="agastya.translate('fr')">French</button>
<button onclick="agastya.translate('hi')">Hindi</button>

You can also add a selector with particular languages and assign the onchange event to translate.

<select onchange="agastya.translate(this.value)">
	<option selected>Change language</option>
	<option value="ja">Japanese</option>
	<option value="nl">Dutch</option>
	<option value="ru">Russian</option>

To only allow certain languages in the widget selector, you can add the data-translate-languages attribute to the <body> tag and specify a list of languages. Please note that this will not work if there is a space between language codes due a bug in Google Translate's webpage plugin.

<body data-translate-languages="ja, nl, ru">...<body> <!-- Will not work -->
<body data-translate-languages="ja,nl,ru">...<body> <!-- Good to go! -->

Since translate is a third-party feature bundled with Agastya, agastya.reset("translate") is not a function and users will have to click the "Show original" or "close" button on the translation menu.