| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Modify the lang attribute in dom for translated pages |
| 11 |
* |
| 12 |
* @param object $dom |
| 13 |
* @param array $args |
| 14 |
* @return object |
| 15 |
*/ |
| 16 |
function wplng_dom_replace_attr_lang( $dom, $args ) { |
| 17 |
|
| 18 |
wplng_args_setup( $args ); |
| 19 |
|
| 20 |
/** |
| 21 |
* Replace languages IDs in attributes |
| 22 |
*/ |
| 23 |
|
| 24 |
$attr_lang_id_to_replace = wplng_data_attr_lang_id_to_replace(); |
| 25 |
|
| 26 |
foreach ( $attr_lang_id_to_replace as $attr ) { |
| 27 |
foreach ( $dom->find( $attr['selector'] ) as $element ) { |
| 28 |
|
| 29 |
if ( empty( $element->attr[ $attr['attr'] ] ) ) { |
| 30 |
continue; |
| 31 |
} |
| 32 |
|
| 33 |
$lang_id = $element->attr[ $attr['attr'] ]; |
| 34 |
|
| 35 |
if ( ! wplng_str_is_locale_id( $lang_id ) ) { |
| 36 |
continue; |
| 37 |
} |
| 38 |
|
| 39 |
$element->attr[ $attr['attr'] ] = esc_attr( $args['language_target'] ); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
return $dom; |
| 44 |
} |
| 45 |
|