compare.php 1.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<?php
include_once __DIR__ . '/app/inc/init.php';
?>
<html>
<head>
    <meta charset="utf-8"/>
</head>
<body><pre><?php

    $goodLang = $_GET['good'];
    $testLang = $_GET['test'];

    $good = json_decode(file_get_contents(__DIR__ . '/locale/' . $goodLang . '.json'), true);
    $test = json_decode(file_get_contents(__DIR__ . '/locale/' . $testLang . '.json'), true);

    $diffSection = false;

    foreach ($good as $sectionName => $section) {
        if (!isset($test[$sectionName])) {
            echo '- section: ' . $sectionName . "\n";
            $diffSection = true;
        }
    }
    foreach ($test as $sectionName => $section) {
        if (!isset($good[$sectionName])) {
            echo '+ section: ' . $sectionName . "\n";
            $diffSection = true;
        }
    }

    if (!$diffSection and array_keys($good)!=array_keys($test)) {
        var_dump(array_keys($good));
        var_dump(array_keys($test));
    } else {
        echo 'All sections are in two langs.' . "\n";
    }


    $diff = array();

    foreach ($good as $sectionName => $section) {
        $diffSection = false;
        foreach($section as $key=>$value) {
            if (!isset($test[$sectionName][$key])) {
                $diff[$sectionName]['-'][] = $key;
                $diffSection = true;
            }
        }

        if (!$diffSection and array_keys($good[$sectionName]) != array_keys($test[$sectionName])) {
            $diff[$sectionName]['order_good'] = array_keys($good[$sectionName]);
            $diff[$sectionName]['order_test'] = array_keys($test[$sectionName]);
        }
    }

    foreach ($test as $sectionName => $section) {
        foreach($section as $key=>$value) {
            if (!isset($good[$sectionName][$key])) {
                $diff[$sectionName]['+'][] = $key;
            }
        }
    }
    if (count($diff) > 0) {
        var_dump($diff);
    }
    ?>
</pre>
</body>
</html>