'wpLingua JSON debug - Excluded parent', 'parents' => $args['parents'], 'value' => $json_decoded, ); error_log( var_export( $debug, true ) ); } return $json_decoded; } /** * Parse each JSON elements */ foreach ( $json_decoded as $key => $value ) { $current_parents = array_merge( $args['parents'], array( $key ) ); /** * Don't parse element if it's exclude */ if ( wplng_json_element_is_excluded( $json_decoded, $current_parents ) ) { if ( true === WPLNG_DEBUG_JSON ) { $debug = array( 'title' => 'wpLingua JSON debug - Excluded element', 'parents' => $current_parents, 'value' => $value, ); error_log( var_export( $debug, true ) ); } continue; } if ( is_array( $value ) ) { /** * If element is an array, parse it */ $args['parents'] = $current_parents; $array_translated[ $key ] = wplng_translate_json_array( $value, $args ); $args['parents'] = array_splice( $args['parents'], 0, -1 ); } elseif ( is_string( $value ) ) { $debug_type = ''; /** * If element is a string */ if ( wplng_str_is_locale_id( $value ) ) { /** * If is a local ID (fr_FR, fr, FR, ...), replace by current */ $debug_type = 'String - Local ID'; $array_translated[ $key ] = $args['language_target']; } elseif ( wplng_str_is_json( $value ) ) { /** * If element is a JSON, parse and translate it */ $debug_type = 'String - JSON'; $args['parents'] = $current_parents; $array_translated[ $key ] = wplng_translate_json( $value, $args ); } elseif ( wplng_str_is_html( $value ) ) { /** * If element is a HTML, parse and translate it */ $debug_type = 'String - HTML'; $array_translated[ $key ] = wplng_translate_html( $value, $args ); } elseif ( wplng_str_is_url( $value ) ) { /** * If element is an URL, replace by translated URL */ $debug_type = 'String - URL'; $array_translated[ $key ] = wplng_url_translate( $value ); } elseif ( wplng_str_is_script_i18n( $value ) ) { /** * If element is a i18n script, replace by translated script */ // Voluntarily don't pass $current_parents $debug_type = 'String - Script i18n'; $array_translated[ $key ] = wplng_translate_js_json_in_i18n_script( $value ); } else { /** * Element is a unknow string, * - check if it's translatable * - Check if is an included element */ if ( ! wplng_text_is_translatable( $value ) ) { $debug_type = 'String - Untranslatable'; } elseif ( ! wplng_json_element_is_included( $value, $current_parents ) ) { $debug_type = 'String - Not included'; } else { $debug_type = 'String - Translatable'; $array_translated[ $key ] = wplng_get_translated_text_from_translations( $value, $args['translations'] ); } } /** * Print debug data in debug.log file */ if ( true === WPLNG_DEBUG_JSON && isset( $json_decoded[ $key ] ) && isset( $array_translated[ $key ] ) // && $debug_type === 'String - Not included' ) { $debug = array( 'title' => 'wpLingua JSON debug', 'parents' => $current_parents, 'type' => $debug_type, 'value' => $json_decoded[ $key ], ); if ( $json_decoded[ $key ] !== $array_translated[ $key ] ) { $debug['translated'] = $array_translated[ $key ]; } error_log( var_export( $debug, true ) ); } } } return $array_translated; }