<commit_before><?php
if(!defined('ABSPATH'))exit;

add_filter('cppress_layout_data', function($layout){
	$lang = qtranxf_getLanguage();
	$layout['widgets'] = cpq_translate($layout['widgets'], $lang);
	return $layout;
});

function cpq_translate($data, $lang){
	$widgets = array();
	foreach($data as $k => $d){
		if(is_array($d) && !array_key_exists($lang, $d)){
			$widgets[$k] = cpq_translate($d, $lang);
		}

		if(is_array($d) && isset($d[$lang])){
			$widgets[$k] = $d[$lang];
		}else if(is_array($d) && !isset($d[$lang]) && in_array(key($d), qtranxf_getSortedLanguages(), true)){
		    $widgets[$k] = '';
        }
		if(!is_array($d)){
			$widgets[$k] = $d;
		}
	}
	
	return $widgets;
}<commit_msg>1.0.5 -- Added signel fields translation function for frontend<commit_after><?php
if(!defined('ABSPATH'))exit;

add_filter('cppress_layout_data', function($layout){
    $lang = qtranxf_getLanguage();
    $layout['widgets'] = cpq_translate($layout['widgets'], $lang);
    return $layout;
});

add_filter('cppress_translate_field', function($field){
    $lang = qtranxf_getLanguage();
    if(is_array($field) && isset($field[$lang])){
        return $field[$lang];
    }

    return $field;
});

function cpq_translate($data, $lang){
    $widgets = array();
    foreach($data as $k => $d){
        if(is_array($d) && !array_key_exists($lang, $d)){
            $widgets[$k] = cpq_translate($d, $lang);
        }

        if(is_array($d) && isset($d[$lang])){
            $widgets[$k] = $d[$lang];
        }else if(is_array($d) && !isset($d[$lang]) && in_array(key($d), qtranxf_getSortedLanguages(), true)){
            $widgets[$k] = '';
        }
        if(!is_array($d)){
            $widgets[$k] = $d;
        }
    }

    return $widgets;
}
{'fraction_non_alphanumeric': 0.22018348623853212, 'fraction_numerical': 0.0017201834862385322, 'mean_word_length': 3.901685393258427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5952432', 'n_tokens_mistral': 667, 'n_tokens_neox': 633, 'n_words': 101}