# jetpack/16.3-a.7/modules/widgets/google-translate/google-translate.js

Jetpack – WP Security, Backup, Speed, &amp; Growth, version 16.3-a.7. 34 lines.

- Page: https://pluginprobe.com/plugins/jetpack/16.3-a.7/code/modules/widgets/google-translate/google-translate.js
- Raw: https://pluginprobe.com/plugins/jetpack/16.3-a.7/raw/modules/widgets/google-translate/google-translate.js
- Modified: 2024-12-16T14:21:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jetpack/16.3-a.7/code/modules/widgets/google-translate/google-translate.js#L10-L20`.

```javascript
/* global google, _wp_google_translate_widget */
function googleTranslateElementInit() {
	var lang = 'en';
	var langParam;
	var langRegex = /[?&#]lang=([a-zA-Z\-_]+)/;
	if (
		typeof _wp_google_translate_widget === 'object' &&
		typeof _wp_google_translate_widget.lang === 'string'
	) {
		lang = _wp_google_translate_widget.lang;
	}
	langParam = window.location.href.match( langRegex );
	if ( langParam ) {
		window.location.href =
			window.location.href.replace( langRegex, '' ).replace( /#googtrans\([a-zA-Z\-_|]+\)/, '' ) +
			'#googtrans(' +
			lang +
			'|' +
			langParam[ 1 ] +
			')';
	}
	new google.translate.TranslateElement(
		{
			pageLanguage: lang,
			layout: _wp_google_translate_widget.layout,
			autoDisplay: false,
		},
		'google_translate_element'
	);
}
if ( module ) {
	module.exports = googleTranslateElementInit;
}

```
