aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilip Komar <filip@mageia.org>2014-01-12 21:32:30 +0000
committerFilip Komar <filip@mageia.org>2014-01-12 21:32:30 +0000
commit3a2f4b84559d12dcf2e73fdf97d14337876e069c (patch)
treea80aaaf51292c2ceee45892077f783185765198d
parent417e1cd2e0fbb4b231391f4b1b53a78ddbd889da (diff)
downloadwww-3a2f4b84559d12dcf2e73fdf97d14337876e069c.tar
www-3a2f4b84559d12dcf2e73fdf97d14337876e069c.tar.gz
www-3a2f4b84559d12dcf2e73fdf97d14337876e069c.tar.bz2
www-3a2f4b84559d12dcf2e73fdf97d14337876e069c.tar.xz
www-3a2f4b84559d12dcf2e73fdf97d14337876e069c.zip
l10n report can be limited to only one resource + better management of untranslated lines in constitution
-rw-r--r--langs/diff.php42
-rw-r--r--langs/lib.php38
-rw-r--r--langs/report.php82
3 files changed, 128 insertions, 34 deletions
diff --git a/langs/diff.php b/langs/diff.php
index 117d38a9e..cdaf6b8f2 100644
--- a/langs/diff.php
+++ b/langs/diff.php
@@ -4,6 +4,8 @@
* 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;
@@ -61,9 +63,21 @@ $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);
+$diff['untranslated_lines_in_constitution'] = array();
if($constitution) {
- $s .= '<h2 style="color: red;">Please translate constitution first</h2>';
+ $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'];
+ $num_of_untranslated_lines = $lang_constitution_results['aproximate_number_of_untranslated_lines'];
+ if ($constitution_readable) {
+ $diff['untranslated_lines_in_constitution'] = $lang_constitution_results['untranslated_lines_in_constitution']; // add untranslated license sentences
+ } else {
+ $diff['untranslated_lines_in_constitution'] = $lang_constitution_results['untranslated_lines_in_constitution']; // add untranslated license sentences
+ }
}
$num_of_untranslated_strings = 0;
@@ -73,7 +87,7 @@ if($license) {
$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 into ' . $langs[$target_lang] . ' first</h2>';
+ $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
}
@@ -87,14 +101,30 @@ $s .= '<p>After translation:</p>
<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 (array('missing' => 'missing strings', 'notrans' => 'untranslated strings', 'extra' => 'unused (old) strings', 'dup_str' => 'duplicate strings', '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)') as $type => $name) {
+$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 = array(
+ 'missing' => 'missing strings',
+ 'notrans' => 'untranslated strings',
+ 'extra' => 'unused (old) strings',
+ 'dup_str' => 'duplicate strings',
+ 'untranslated_lines_in_constitution' => 'of all untranslated lines in <a ' . $dest_constitution . '">constitution</a> (in svn)',
+ '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)',
+);
+foreach ($issues as $type => $name) {
if (count($diff[$type]) > 0) {
$s .= sprintf('<h2>%d %s:</h2>', count($diff[$type]), $name);
$s .= '<pre>';
- $prefix = (($type == 'untranslated_sentences_in_license') ? 'msgid: ' : ';');
+ 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, htmlspecialchars($l));
+ $s .= sprintf("%s%s\n\n", $prefix, rtrim(htmlspecialchars($l)));
$s .= '</pre>';
}
}
@@ -113,7 +143,7 @@ header('Content-Type: text/html;charset=utf-8');
</style>
</head>
<body>
- <?php echo $s; $test_1 = TRUE; $test = strip_tags($test_1); echo '1. test: ' . $test; ?>
+ <?php echo $s; ?>
<hr>
</body>
</html>
diff --git a/langs/lib.php b/langs/lib.php
index 091883292..f93e53777 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -122,4 +122,40 @@ function get_other_langs()
}
array_unshift($re, 'en');
return $re;
-} \ No newline at end of file
+}
+
+function aproximate_number_of_untranslated_constitution_lines($app_root, $lang, $unique_lines_in_eng_constitution = array())
+{
+ $constitution_is_readable = FALSE;
+ $dest_constitution = sprintf('%s/%s/%s/%s_%s.md', $app_root, $lang, 'about/constitution', 'mageia.org_statutes', $lang);
+ $number_of_unique_lines_in_eng_constitution = count($unique_lines_in_eng_constitution);
+ if(is_readable($dest_constitution)) {
+ $unique_lines_in_constitution = array_unique(file($dest_constitution));
+ $number_of_unique_lines_in_constitution = count($unique_lines_in_constitution);
+ $constitution_is_readable = TRUE;
+ if ($lang == 'en') {
+ $aproximate_number_of_untranslated_lines = $number_of_unique_lines_in_constitution;
+ $untranslated_lines_in_constitution = array();
+ } else {
+ $untranslated_lines_in_constitution = array_intersect($unique_lines_in_eng_constitution, $unique_lines_in_constitution);
+ $number_of_nonunique_lines_lang_constitution = count($untranslated_lines_in_constitution);
+ $ratio = $number_of_nonunique_lines_lang_constitution / $number_of_unique_lines_in_eng_constitution;
+ $limit_ratio = 0.15; // limit ratio of "allowed" untranslated lines
+ if ($ratio > $limit_ratio) {
+ // add aproximate number of untranslated constitution lines
+ $aproximate_number_of_untranslated_lines = $number_of_nonunique_lines_lang_constitution - round($limit_ratio * $number_of_unique_lines_in_eng_constitution);
+ }
+ }
+ } else {
+ $unique_lines_in_constitution = $unique_lines_in_eng_constitution;
+ $aproximate_number_of_untranslated_lines = $number_of_unique_lines_in_eng_constitution;
+ $untranslated_lines_in_constitution = $unique_lines_in_eng_constitution;
+ }
+
+ return array(
+ 'unique_lines_in_constitution' => $unique_lines_in_constitution,
+ 'constitution_readable' => $constitution_is_readable,
+ 'untranslated_lines_in_constitution' => $untranslated_lines_in_constitution,
+ 'aproximate_number_of_untranslated_lines' => $aproximate_number_of_untranslated_lines,
+ );
+}
diff --git a/langs/report.php b/langs/report.php
index 6f8fcbb8a..63cfde1e7 100644
--- a/langs/report.php
+++ b/langs/report.php
@@ -38,14 +38,24 @@
/**
*/
$one_language = isset($_GET['l']) ? strip_tags(trim($_GET['l'])) : null;
+ $one_resource = isset($_GET['r']) ? strip_tags(trim($_GET['r'])) : null;
include 'lib.php';
define('APP_ROOT', realpath(__DIR__ . '/..'));
- $enFiles = get_lang_references();
- // added navigation file
- array_unshift($enFiles, '../_nav/langs/en.lang');
+ $restore_languages = FALSE;
+ $restore_resources = FALSE;
+
+ if (isset($one_resource) && $one_resource != 'all') {
+ $enFiles = array($one_resource);
+ $restore_resources = TRUE;
+ } else {
+ $enFiles = get_lang_references();
+ array_unshift($enFiles, '../_nav/langs/en.lang'); // added navigation file
+ }
+
if (isset($one_language) && $one_language != 'all') {
$otherLangs = array('en', $one_language);
+ $restore_languages = TRUE;
} else {
$otherLangs = get_other_langs();
}
@@ -59,13 +69,15 @@
$diff_link = '<a href="diff.php?s=%s&amp;l=%s" title="see detailed diff">';
$languages = array();
+ $unique_lines_in_eng_constitution = 0;
+ $number_of_unique_lines_in_eng_constitution = 0;
foreach ($otherLangs as $l) {
$stats['en']['files'] += 1;
$stats[$l]['files'] = 0;
$stats[$l]['strings'] = 0;
- if ($l == 'en') {
+ if ($l == 'en' || $restore_languages) {
$link_one_language = '%s';
} else {
$link_one_language = '<a href="?l=' . $l . '" title="see this language only">%s</a>';
@@ -118,14 +130,13 @@
$num_of_duplicated_strings = count($test['dup_str']);
if ($link == 'about/constitution') {
- $dest_constitution = sprintf('%s/%s/%s/%s_%s.md', APP_ROOT, $l, 'about/constitution', 'mageia.org_statutes', $l);
+ $constitution_results = aproximate_number_of_untranslated_constitution_lines(APP_ROOT, $l, $unique_lines_in_eng_constitution);
if ($l == 'en') {
- $strings_en_constitution = count(array_unique(file($dest_constitution)));
- }
- $test['a'] += $strings_en_constitution; // add aproximate number of strings from constitution to translate
- if(!is_readable($dest_constitution) || $l == 'en') {
- $num_of_untranslated_strings += $strings_en_constitution; // add all constitution strings
+ $unique_lines_in_eng_constitution = $constitution_results['unique_lines_in_constitution'];
+ $number_of_unique_lines_in_eng_constitution = count($unique_lines_in_eng_constitution);
}
+ $test['a'] += $number_of_unique_lines_in_eng_constitution; // add aproximate number of lines from constitution to translate
+ $num_of_untranslated_strings += $constitution_results['aproximate_number_of_untranslated_lines'];
}
if ($link == 'about/license') {
require_once('../en/about/license/license.php');
@@ -148,17 +159,17 @@
);
} else if ($link == '2') {
$mga = array(
- 'A' => '2/download_index.php',
- 'B' => '2/for-pc/index.php',
- 'C' => '2/for-server/index.php',
- 'D' => '2/index.php',
+ 'A' => '2/index.php',
+ 'B' => '2/download_index.php',
+ 'C' => '2/for-pc/index.php',
+ 'D' => '2/for-server/index.php',
);
} else if ($link == '3') {
$mga = array(
- 'A' => '3/download_index.php',
- 'B' => 'for-pc/index.php',
- 'C' => 'for-server/index.php',
- 'D' => '3/index.php',
+ 'A' => '3/index.php',
+ 'B' => '3/download_index.php',
+ 'C' => 'for-pc/index.php',
+ 'D' => 'for-server/index.php',
);
} else {
$mga = array(
@@ -228,7 +239,7 @@
$num_of_col++;
if ($num_of_col % $num_clmns_to_repeat == 0 && $num_of_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) {
if ($l == 'en') {
- $cols .= $lang_coloumn = '<td style="font-weight: bold;"><a href="?l=all" title="see all languages">Language</a></td>';
+ $cols .= $lang_coloumn = '<td style="font-weight: bold;">Language</td>';
} else {
$cols .= $lang_coloumn = sprintf('<td style="font-weight: bold; vertical-align: top;">' . $link_one_language . '<br><span style="font-weight: normal; font-size: smaller;">%s</span></td>', $langs[$l], $l);
}
@@ -257,33 +268,50 @@
$en_language = array_shift($languages); // shift English for proper sorting
krsort($languages, SORT_NUMERIC);
- $enFiles = array_map(function ($e) { return str_replace('en/', '', $e); }, $enFiles);
// add language coloumn repeating
$lang_line = array();
$num_of_h_col = 0;
+ $add_last_coloumn = FALSE;
+ $resources = ($restore_resources ? '&nbsp;' : count($enFiles) . ' resources');
foreach ($enFiles as $lang_chunk) {
$num_of_h_col++;
- $lang_line[] = $lang_chunk;
+ if ($restore_resources) {
+ $lang_line[] = str_replace('en/', '', $lang_chunk);
+ } else {
+ $lang_line[] = '<a href="?r=' . $lang_chunk . '" title="see only this resource">' . str_replace('en/', '', $lang_chunk) . '</a>';
+ }
if ($num_of_h_col % $num_clmns_to_repeat == 0 && $num_of_h_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) {
- $lang_line[] = '&nbsp;';
+ $lang_line[] = $resources;
+ $add_last_coloumn = TRUE;
}
}
- $lang_line[] = '&nbsp;';// last h coloumn
-
+ if ($add_last_coloumn) {
+ $lang_line[] = $resources;// last h coloumn
+ }
+
$thfiles = '<th>' . implode('</th><th>', $lang_line) . '</th>' . PHP_EOL;
- $count = count($otherLangs);
+ if ($restore_languages) {
+ echo '<p>Restore <a href="?l=all" title="see all languages">all languages</a>.</p>';
+ $count = '&nbsp;';
+ } else {
+ $count = count($otherLangs) . ' languages';
+ }
+ if ($restore_resources) {
+ echo '<p>Restore <a href="?r=all" title="see all resources">all resources</a>.</p>';
+ }
$chunks = array_chunk($languages, $num_lines_to_repeat = 8); // add header repeating
$table_body = array();
foreach ($chunks as $chunk) {
- $table_body = array_merge($table_body, $chunk, array(count($chunk) > ($num_lines_to_repeat / 2) ? '<tr><th>&nbsp;</th><th>File</th>' . $thfiles : ''));
+ $table_body = array_merge($table_body, $chunk, array(count($chunk) > ($num_lines_to_repeat / 2) ? '<tr><th>' . $count . '</th><th>' . $resources . '</th>' . $thfiles : ''));
}
array_unshift($table_body, $en_language); // unshift English back
$s = implode($table_body);
+
echo <<<S
<table border="1">
<thead><tr>
- <th><a href="?l=all" title="see all languages">{$count} languages</a></th>
+ <th>{$count}</th>
<th>Progress</th>
{$thfiles}
</tr></thead>