aboutsummaryrefslogtreecommitdiffstats
path: root/langs/diff.php
blob: f7e87839f09a7791af19a9ef4861dbdb4daaeb9f (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
 * Report the diff of 's' file
 * against matching file in language 'l', if it exists.
*/

define('APP_ROOT', realpath(__DIR__ . '/..'));

$source_file = isset($_GET['s']) ? strip_tags(trim($_GET['s'])) : null;
$target_lang = isset($_GET['l']) ? strip_tags(trim($_GET['l'])) : null;

if (is_null($source_file) ||
    is_null($target_lang)) {

    die('kthxbai');
}

if (!file_exists($source_file)) {
    die('no source');
}

include 'lib.php';

$target_file = _lang_file_switch($source_file, $target_lang);

if (!file_exists($target_file)) {
    die('no target');
}

if($source_file =='en/about/constitution.en.lang') {
    $constitution = true;
} else {
    $constitution = false;
}

if($source_file =='en/about/license.en.lang') {
    $license = true;
} else {
    $license = false;
}

if ($source_file == '../_nav/langs/en.lang') {
    $file   = substr(_lang_file_switch($source_file, $target_lang), 14);
    $note   = '<span style="color: red; font-weight: bold"> NOTE: THIS IS TRANSLATION OF NAVIGATION SO LOCATION FOR COMMIT IS DIFFERENT!</span>';
    $commit = '<a href="//svnweb.mageia.org/web/www/trunk/_nav/langs/' . $file . '?view=markup">web/www/trunk/_nav/langs/' . $file . '</a> and for now to the <a href="//svnweb.mageia.org/web/nav/langs/' . $file . '?view=markup">web/nav/langs/' . $file . '</a> too';
} else {
    $file   = _lang_file_switch($source_file, $target_lang);
    $note   = '';
    $commit = '<a href="//svnweb.mageia.org/web/www/trunk/langs/' . $file . '?view=markup">web/www/trunk/langs/' . $file . '</a>';
}

$source_file = realpath($source_file);
$target_file = realpath($target_file);

if (false === strstr($source_file, '/langs/') ||
    false == strstr($target_file, '/langs/')) {
    die('no sorry');
}

$diff = _lang_diff($source_file, $target_file);

$issues = array(
    'missing' => 'missing strings',
    'notrans' => 'untranslated strings',
    'extra' => 'unused (old) strings',
    'dup_str' => 'duplicate strings',
);

$s = '<a href="report.php">&laquo; back to langs report</a>';
$s .= sprintf('<h1>Differences between %s source and %s target</h1>',
    substr($source_file, strpos($source_file, '/langs/')+7), $target_lang);

if($constitution) {
    $s .= '<h2 style="color: red;">Please translate constitution fully into ' . $langs[$target_lang] . ' first</h2>';
    $s .= '<p>You can find it in <a href="//svnweb.mageia.org/org/constitution/">svn</a>. ';

    $constitution_results = aproximate_number_of_untranslated_constitution_lines(APP_ROOT, 'en');
    $unique_lines_in_eng_constitution = $constitution_results['unique_lines_in_constitution'];
    $lang_constitution_results = aproximate_number_of_untranslated_constitution_lines(APP_ROOT, $target_lang, $unique_lines_in_eng_constitution);
    $constitution_readable = $lang_constitution_results['constitution_readable'];
    $diff['untranslated_lines_in_constitution'] = $lang_constitution_results['untranslated_lines_in_constitution']; // add untranslated license sentences
    $dest_constitution = sprintf('%s/%s_%s.md', 'href="//svnweb.mageia.org/web/www/trunk/en/about/constitution', 'mageia.org_statutes', ($constitution_readable ? $target_lang : 'en'));
    $issues['untranslated_lines_in_constitution'] = 'of all untranslated lines in <a ' . $dest_constitution . '">constitution</a> (in svn)';
}

if($license) {
    require_once('../en/about/license/license.php');
    $license_numbers = array_pop(read_license_from_vcs($target_lang));
    $num_of_untranslated_strings = $license_numbers["untran"]; // number of all license sentences
    $diff['untranslated_sentences_in_license'] = $license_numbers['untranslated_sentences']; // add untranslated license sentences
    $s .= '<h2 style="color: red;">Please translate license fully into ' . $langs[$target_lang] . ' first</h2>';
    $s .= sprintf('<p>You can find it in <a href="http://gitweb.mageia.org/software/drakx/tree/perl-install/share/po/%s.po">git</a>. ', $target_lang); // git doesn't work yet on https
    $issues['untranslated_sentences_in_license'] = 'untranslated msgid strings in ' . $num_of_untranslated_strings . ' sentences in separate <a href="http://gitweb.mageia.org/software/drakx/tree/perl-install/share/po/' . $target_lang . '.po">license file</a> (in git)';
}

if($constitution || $license) {
    $s .= 'Please read <a href="https://wiki.mageia.org/en/Internationalisation_Team_%28i18n%29#Special_cases_of_web_pages">page on wiki for more information</a> about that.</p>';
}

$s .= '<p>After translation:</p>
        <ul>
            <li>if you have a SVN account, you may commit updated file directly in <code>' . $commit . '</code>. ' . $note . '</li>
            <li>or attach it to a mail to Mageia localization team (<code>mageia-i18n</code>, <a href="irc://irc.freenode.net/#mageia-i18n">#mageia-i18n</a> on Freenode).</li>
        </ul>';

foreach ($issues as $type => $name) {
    if (count($diff[$type]) > 0) {
        $s .= sprintf('<h2>%d %s:</h2>', count($diff[$type]), $name);
        $s .= '<pre>';
        if ($type == 'untranslated_lines_in_constitution') {
            $prefix = '';
        } else if ($type == 'untranslated_sentences_in_license') {
            $prefix = 'msgid: ';
        } else {
            $prefix = ';';
        }
        foreach ($diff[$type] as $l)
            $s .= sprintf("%s%s\n\n", $prefix, rtrim(htmlspecialchars($l)));
        $s .= '</pre>';
    }
}

header('Content-Type: text/html;charset=utf-8');

?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="robot" content="noindex,nofollow,nosnippet">
    <?php echo sprintf('<title>Differences between %s source and %s target</title>',
    substr($source_file, strpos($source_file, '/langs/')+7), $target_lang); ?>
    <style>
    pre { background: #eee; padding: 0.6em; }
    </style>
</head>
<body>
    <?php echo $s; ?>
<hr>
</body>
</html>