From 3a2f4b84559d12dcf2e73fdf97d14337876e069c Mon Sep 17 00:00:00 2001 From: Filip Komar Date: Sun, 12 Jan 2014 21:32:30 +0000 Subject: l10n report can be limited to only one resource + better management of untranslated lines in constitution --- langs/diff.php | 42 ++++++++++++++++++++++++----- langs/lib.php | 38 +++++++++++++++++++++++++- langs/report.php | 82 +++++++++++++++++++++++++++++++++++++------------------- 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 = '« back to langs report'; $s .= sprintf('

Differences between %s source and %s target

', substr($source_file, strpos($source_file, '/langs/')+7), $target_lang); +$diff['untranslated_lines_in_constitution'] = array(); if($constitution) { - $s .= '

Please translate constitution first

'; + $s .= '

Please translate constitution fully into ' . $langs[$target_lang] . ' first

'; $s .= '

You can find it in svn. '; + + $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 .= '

Please translate license into ' . $langs[$target_lang] . ' first

'; + $s .= '

Please translate license fully into ' . $langs[$target_lang] . ' first

'; $s .= sprintf('

You can find it in git. ', $target_lang); // git doesn't work yet on https } @@ -87,14 +101,30 @@ $s .= '

After translation:

  • or attach it to a mail to Mageia localization team (mageia-i18n, #mageia-i18n on Freenode).
  • '; -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 license file (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 constitution (in svn)', + 'untranslated_sentences_in_license' => 'untranslated msgid strings in ' . $num_of_untranslated_strings . ' sentences in separate license file (in git)', +); +foreach ($issues as $type => $name) { if (count($diff[$type]) > 0) { $s .= sprintf('

    %d %s:

    ', count($diff[$type]), $name); $s .= '
    ';
    -        $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 .= '
    '; } } @@ -113,7 +143,7 @@ header('Content-Type: text/html;charset=utf-8'); - +
    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 = ''; $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 = '%s'; @@ -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 = 'Language'; + $cols .= $lang_coloumn = 'Language'; } else { $cols .= $lang_coloumn = sprintf('' . $link_one_language . '
    %s', $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 ? ' ' : 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[] = '' . str_replace('en/', '', $lang_chunk) . ''; + } if ($num_of_h_col % $num_clmns_to_repeat == 0 && $num_of_h_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) { - $lang_line[] = ' '; + $lang_line[] = $resources; + $add_last_coloumn = TRUE; } } - $lang_line[] = ' ';// last h coloumn - + if ($add_last_coloumn) { + $lang_line[] = $resources;// last h coloumn + } + $thfiles = '' . implode('', $lang_line) . '' . PHP_EOL; - $count = count($otherLangs); + if ($restore_languages) { + echo '

    Restore all languages.

    '; + $count = ' '; + } else { + $count = count($otherLangs) . ' languages'; + } + if ($restore_resources) { + echo '

    Restore all resources.

    '; + } $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) ? ' File' . $thfiles : '')); + $table_body = array_merge($table_body, $chunk, array(count($chunk) > ($num_lines_to_repeat / 2) ? '' . $count . '' . $resources . '' . $thfiles : '')); } array_unshift($table_body, $en_language); // unshift English back $s = implode($table_body); + echo << - {$count} languages + {$count} Progress {$thfiles} -- cgit v1.2.1