| 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 |
|