<commit_before><?php

/**
 * Display theme details
 *
 * PHP Version 5
 *
 * @category  Plugins
 * @package   Languages
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

$loader = \csphere\core\service\Locator::get();

$short = \csphere\core\http\Input::get('get', 'short');
$dir   = \csphere\core\http\Input::get('get', 'dir');
$theme = \csphere\core\http\Input::get('get', 'theme');
$type  = empty($theme) ? 'plugin' : 'theme';
$typed = $type . 's';

$lang = \csphere\core\translation\Fetch::keys('languages');

// Add breadcrumb navigation
$bread = new \csphere\core\template\Breadcrumb('languages');

$bread->add('control');
$bread->add($typed, 'languages/' . $type . '/short/' . $short);

$details = 'languages/details/short/' . $short . '/dir/' . $dir;

if ($type == 'theme') {

    $details .= '/theme/1';
}

$bread->add('details', $details);
$bread->trace();

// Check for target and translation details
$meta = new \csphere\core\translation\Metadata();

$exists = $meta->exists($short);

if ($type == 'plugin') {

    $target = new \csphere\core\plugins\Metadata();

} else {

    $target = new \csphere\core\themes\Metadata();
}

$dir_exists = $target->exists($dir);

// Only proceed if target was found and translation exists
if ($exists === true AND $dir_exists === true) {

    $error = '';
    $xml   = $loader->load('xml', 'language');
    $data  = $xml->source($type, $dir, $short);

    // Compare definitions with the one in default plugin
    $default  = $xml->source('plugin', 'default');
    $def_lang = array();
    $cur_lang = array();

    foreach ($default['definitions'] AS $def) {

        $def_lang[$def['name']] = $def['value'];
    }

    foreach ($data['definitions'] AS $def) {

        $cur_lang[$def['name']] = $def['value'];
    }

    $test = array_diff_key($cur_lang, $def_lang);
    $bad  = array_diff_key($cur_lang, $test);

    foreach ($bad AS $key => $name) {

        $error .= $lang['warn_override'] . ': ' . $key . "\n";
    }

    // Compare this language information with another main language
    $use_lang = $short == 'en' ? 'de' : 'en';
    $alt_lang = $xml->source($type, $dir, $use_lang);
    $top_lang = array();

    foreach ($alt_lang['definitions'] AS $def) {

        $top_lang[$def['name']] = $def['value'];
    }

    $test = array_diff_key($cur_lang, $top_lang);

    foreach ($test AS $key => $name) {

        $error .= $lang['warn_difference'] . ': ' . $key . "\n";
    }

    // Define vars for template
    $data['error'] = $error;
    $data['short'] = $short;
    $data['dir']   = $dir;
    $data['type']  = $type;

    // Output results
    $view = $loader->load('view');

    $view->template('languages', 'details', $data);
}<commit_msg>bugfix<commit_after><?php

/**
 * Display theme details
 *
 * PHP Version 5
 *
 * @category  Plugins
 * @package   Languages
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

$loader = \csphere\core\service\Locator::get();

$short = \csphere\core\http\Input::get('get', 'short');
$dir   = \csphere\core\http\Input::get('get', 'dir');
$theme = \csphere\core\http\Input::get('get', 'theme');
$type  = empty($theme) ? 'plugin' : 'theme';
$typed = $type . 's';

$lang = \csphere\core\translation\Fetch::keys('languages');

// Add breadcrumb navigation
$bread = new \csphere\core\template\Breadcrumb('languages');

$bread->add('control');
$bread->add($typed, 'languages/' . $typed . '/short/' . $short);

$details = 'languages/details/short/' . $short . '/dir/' . $dir;

if ($type == 'theme') {

    $details .= '/theme/1';
}

$bread->add('details', $details);
$bread->trace();

// Check for target and translation details
$meta = new \csphere\core\translation\Metadata();

$exists = $meta->exists($short);

if ($type == 'plugin') {

    $target = new \csphere\core\plugins\Metadata();

} else {

    $target = new \csphere\core\themes\Metadata();
}

$dir_exists = $target->exists($dir);

// Only proceed if target was found and translation exists
if ($exists === true AND $dir_exists === true) {

    $error = '';
    $xml   = $loader->load('xml', 'language');
    $data  = $xml->source($type, $dir, $short);

    // Compare definitions with the one in default plugin
    $default  = $xml->source('plugin', 'default');
    $def_lang = array();
    $cur_lang = array();

    foreach ($default['definitions'] AS $def) {

        $def_lang[$def['name']] = $def['value'];
    }

    foreach ($data['definitions'] AS $def) {

        $cur_lang[$def['name']] = $def['value'];
    }

    $test = array_diff_key($cur_lang, $def_lang);
    $bad  = array_diff_key($cur_lang, $test);

    foreach ($bad AS $key => $name) {

        $error .= $lang['warn_override'] . ': ' . $key . "\n";
    }

    // Compare this language information with another main language
    $use_lang = $short == 'en' ? 'de' : 'en';
    $alt_lang = $xml->source($type, $dir, $use_lang);
    $top_lang = array();

    foreach ($alt_lang['definitions'] AS $def) {

        $top_lang[$def['name']] = $def['value'];
    }

    $test = array_diff_key($cur_lang, $top_lang);

    foreach ($test AS $key => $name) {

        $error .= $lang['warn_difference'] . ': ' . $key . "\n";
    }

    // Define vars for template
    $data['error'] = $error;
    $data['short'] = $short;
    $data['dir']   = $dir;
    $data['type']  = $type;

    // Output results
    $view = $loader->load('view');

    $view->template('languages', 'details', $data);
}
{'fraction_non_alphanumeric': 0.21254846669016567, 'fraction_numerical': 0.0021149101163200562, 'mean_word_length': 3.238237490664675, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '7240176', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1925, 'n_words': 428}