# wplingua/2.16.7/inc/dom/translate-script.php

Translate and Go multilingual – Automatic AI translation – wpLingua, version 2.16.7. 53 lines.

- Page: https://pluginprobe.com/plugins/wplingua/2.16.7/code/inc/dom/translate-script.php
- Raw: https://pluginprobe.com/plugins/wplingua/2.16.7/raw/inc/dom/translate-script.php
- Modified: 2026-09-17T00:21:52+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/wplingua/2.16.7/code/inc/dom/translate-script.php#L10-L20`.

```php
<?php

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}


/**
 * Modify scripts in dom for translated pages
 *
 * @param object $dom
 * @param array  $args
 * @return object
 */
function wplng_dom_translate_script( $dom, $args ) {

	wplng_args_setup( $args );

	foreach ( $dom->find( 'script' ) as $element ) {

		if ( ! empty( $element->attr['type'] )
			&& (
				$element->attr['type'] === 'application/ld+json'
				|| $element->attr['type'] === 'application/json'
			)
		) {

			/**
			 * Translate JSON in JSON scripts
			 */

			$element->innertext = wplng_translate_json(
				$element->innertext,
				$args
			);

		} else {

			/**
			 * Translate JS in JS scripts
			 */

			$element->innertext = wplng_translate_js(
				$element->innertext,
				$args
			);
		}
	}

	return $dom;
}

```
