PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.7
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.7
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / dom / translate-script.php

translate-script.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.7, at inc/dom/translate-script.php

53 lines 822 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8
9 /**
10 * Modify scripts in dom for translated pages
11 *
12 * @param object $dom
13 * @param array $args
14 * @return object
15 */
16 function wplng_dom_translate_script( $dom, $args ) {
17
18 wplng_args_setup( $args );
19
20 foreach ( $dom->find( 'script' ) as $element ) {
21
22 if ( ! empty( $element->attr['type'] )
23 && (
24 $element->attr['type'] === 'application/ld+json'
25 || $element->attr['type'] === 'application/json'
26 )
27 ) {
28
29 /**
30 * Translate JSON in JSON scripts
31 */
32
33 $element->innertext = wplng_translate_json(
34 $element->innertext,
35 $args
36 );
37
38 } else {
39
40 /**
41 * Translate JS in JS scripts
42 */
43
44 $element->innertext = wplng_translate_js(
45 $element->innertext,
46 $args
47 );
48 }
49 }
50
51 return $dom;
52 }
53