PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.12.3
Translate and Go multilingual – Automatic AI translation – wpLingua v2.12.3
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 / translator / html.php

html.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.12.3, at inc/translator/html.php

98 lines 2.1 KB
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 * wpLingua translate : Get translated HTML
11 *
12 * @param string $html
13 * @param array $args
14 * @return string
15 */
16 function wplng_translate_html( $html, $args = array() ) {
17
18 if ( empty( $html ) ) {
19 return $html;
20 }
21
22 /**
23 * Create the dom element
24 */
25
26 $dom = wplng_sdh_str_get_html( $html );
27
28 if ( empty( $dom ) ) {
29 return $html;
30 }
31
32 /**
33 * Replace excluded HTML part by tag
34 */
35
36 $excluded_elements = array();
37
38 $dom = wplng_dom_exclusions_put_tags( $dom, $excluded_elements );
39
40 /**
41 * Update args and get all texts in HTML if needed
42 */
43
44 wplng_args_setup( $args );
45
46 if ( empty( $args['translations'] ) ) {
47 $texts = wplng_parse_html( $dom );
48 wplng_args_update_from_texts( $args, $texts );
49 }
50
51 /**
52 * Update the dom
53 */
54
55 // Setup translated page (dir, attribute lang, class, links)
56 $dom = wplng_dom_replace_attr_dir( $dom, $args );
57 $dom = wplng_dom_replace_attr_lang( $dom, $args );
58 $dom = wplng_dom_replace_body_class( $dom, $args );
59 $dom = wplng_dom_replace_links( $dom, $args );
60
61 // Translate texts
62 $dom = wplng_dom_translate_nodes_texts( $dom, $args );
63 $dom = wplng_dom_translate_attr_texts( $dom, $args );
64
65 // Translate HTML, JS and JSON
66 $dom = wplng_dom_translate_html_attr( $dom, $args );
67 $dom = wplng_dom_translate_json_attr( $dom, $args );
68 $dom = wplng_dom_translate_script( $dom, $args );
69
70 // Load editor or list mode if needed
71 $dom = wplng_dom_mode_editor( $dom, $args );
72 $dom = wplng_dom_mode_list( $dom, $args );
73
74 // Load bar if needed (progress or overload)
75 $dom = wplng_dom_load_progress( $dom, $args );
76 $dom = wplng_dom_load_overload( $dom, $args );
77
78 /**
79 * Replace exclude tags by HTML
80 */
81
82 $dom = wplng_dom_exclusions_replace_tags( $dom, $excluded_elements );
83
84 /**
85 * Dom is ready: check, apply filter and return
86 */
87
88 $dom->save();
89 $dom = (string) wplng_sdh_str_get_html( $dom );
90 $dom = str_replace( '_wplingua_no_translate_', '', $dom );
91
92 if ( empty( $dom ) ) {
93 return $html;
94 }
95
96 return $dom;
97 }
98