From b0e15407a664677201a3b9b8251786652b5e147f Mon Sep 17 00:00:00 2001 From: Filip Komar Date: Sat, 8 Mar 2014 21:21:32 +0000 Subject: further preparation of l10n report family w/o 3 exceptions (nav, license, constitution) to gettext system --- langs/lib.php | 20 +++++++++++--------- langs/missing.php | 20 +++++++++++++++----- langs/report.php | 33 ++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 25 deletions(-) (limited to 'langs') diff --git a/langs/lib.php b/langs/lib.php index 05740418d..15f133131 100644 --- a/langs/lib.php +++ b/langs/lib.php @@ -91,13 +91,13 @@ function _po_diff($locale, $resource) $missing = array(); foreach ($source_l as $escaped_string => $subarray) { - if ($escaped_string == $subarray["msgid"]) { // filter out header + if (!empty($subarray["msgid"])) { // filter out header $pot_strings[$escaped_string] = $subarray["msgid"]; } } foreach ($target_l as $escaped_string => $subarray) { - if ($escaped_string == $subarray["msgid"]) { // filter out header + if (!empty($subarray["msgid"])) { // filter out header $po_strings[$escaped_string] = $subarray["msgstr"][0]; } } @@ -115,10 +115,10 @@ function _po_diff($locale, $resource) return array( 'a' => count($pot_strings), // # of original strings // 'b' => count($po_strings), // # of target strings - 'missing' => $missing, // probably could be empty array() of missing strings - 'notrans' => $untrans, // array of untranslated strings - 'extra' => array(), // could be empty array() of unused (old) strings - 'dup_str' => array(), // could be empty array() of duplicate strings + 'missing' => $missing, + 'notrans' => $untrans, + 'extra' => array(), + 'dup_str' => array(), ); } @@ -189,7 +189,9 @@ function _lang_file_switch($s, $l) */ function _po_file_switch($s, $l) { - $s = str_replace('.pot', '.po', $s); + if($l != 'en') { + $s = str_replace('.pot', '.po', $s); + } return str_replace('en/', $l . '/', $s); } @@ -208,9 +210,9 @@ function _extract_resource($source_file, $extension = '.pot') return str_replace('en/', '', $resource); } -function get_lang_references() +function get_lang_references($pattern = '*') { - return glob_recursive('en/*', GLOB_MARK); + return glob_recursive('en/' . $pattern, GLOB_MARK); } function get_other_langs() diff --git a/langs/missing.php b/langs/missing.php index 3cca031a9..870835337 100644 --- a/langs/missing.php +++ b/langs/missing.php @@ -12,13 +12,23 @@ if (is_null($s)) { die; } -if($s =='en/about/constitution.en.lang') { +if (strrpos($s, '.pot')) { + $gettext = true; + $resource = _extract_resource($s); + $file = _po_file_switch($s, $l); +} else { + $gettext = false; + $resource = _extract_resource($s, '.en.lang'); + $file = _lang_file_switch($s, $l); +} + +if($resource =='constitution') { $constitution = true; } else { $constitution = false; } -if($s =='en/about/license.en.lang') { +if($resource =='license') { $license = true; } else { $license = false; @@ -28,12 +38,12 @@ if ($s == '../_nav/langs/en.lang') { $file = substr(_lang_file_switch($s, $l), 14); $note = ' NOTE: THIS IS TRANSLATION OF NAVIGATION SO LOCATION FOR COMMIT IS DIFFERENT!'; $commit = 'web/www/trunk/_nav/langs/' . $file . ' and for now to the web/nav/langs/' . $file . ' too'; - $iframe = '//www.mageia.org/_nav/langs/en.lang'; + $iframe = '//' . $_SERVER['SERVER_NAME'] .'/_nav/langs/en.lang'; } else { - $file = _lang_file_switch($s, $l); +// $file = _lang_file_switch($s, $l); $note = ''; $commit = 'web/www/trunk/langs/' . $file; - $iframe = '//www.mageia.org/langs/'.$s; + $iframe = '//' . $_SERVER['SERVER_NAME'] .'/langs/'.$s; } $constitution_or_license = ''; diff --git a/langs/report.php b/langs/report.php index 17db69d4e..25ea9a398 100644 --- a/langs/report.php +++ b/langs/report.php @@ -40,7 +40,6 @@ include 'lib.php'; $one_language = isset($_GET['l']) ? strip_tags(trim($_GET['l'])) : null; $one_resource = isset($_GET['r']) ? strip_tags(trim($_GET['r'])) : null; - define('APP_ROOT', realpath(__DIR__ . '/..')); $restore_languages = FALSE; $restore_resources = FALSE; @@ -49,8 +48,8 @@ $enFiles = array($one_resource); $restore_resources = TRUE; } else { - $enFiles = get_lang_references(); - array_unshift($enFiles, '../_nav/langs/en.lang'); // added navigation file + $enFiles = array_merge(array('../_nav/langs/en.lang'), get_lang_references('*.lang'), get_lang_references('*.pot')); // added navigation file + sort($enFiles); } if (isset($one_language) && $one_language != 'all') { @@ -91,6 +90,15 @@ foreach ($enFiles as $f) { + if (strrpos($f, '.pot')) { + $gettext = true; + $resource = _extract_resource($f); + $langF = _po_file_switch($f, $l); + } else { + $gettext = false; + $resource = _extract_resource($f, '.en.lang'); + $langF = _lang_file_switch($f, $l); + } $enStringsCount[$f] = 0; if ($f == '../_nav/langs/en.lang') { $nav = true; @@ -98,19 +106,18 @@ $nav = false; } - $langF = str_replace('.en.lang', '.' . $l . '.lang', $f); if ($nav) { $langF = '../_nav/langs/' . $l . '.lang'; } else { $langF = $l . substr($langF, 2); } - $link = str_replace(array('en/', '.en.lang', 'index'), '', $f); + $link = str_replace('index', '', $resource); if ($nav) { - $dest_en = sprintf('%s/%s/%s', APP_ROOT, '_nav/langs', 'en.lang'); - $dest_l = sprintf('%s/%s/%s', APP_ROOT, '_nav/langs', $l . '.lang'); + $dest_en = sprintf('%s/%s/%s', G_APP_ROOT, '_nav/langs', 'en.lang'); + $dest_l = sprintf('%s/%s/%s', G_APP_ROOT, '_nav/langs', $l . '.lang'); } else { - $dest_en = sprintf('%s/%s/%s/%s', APP_ROOT, 'en', $link, 'index.php'); - $dest_l = sprintf('%s/%s/%s/%s', APP_ROOT, $l, $link, 'index.php'); + $dest_en = sprintf('%s/%s/%s/%s', G_APP_ROOT, 'en', $link, 'index.php'); + $dest_l = sprintf('%s/%s/%s/%s', G_APP_ROOT, $l, $link, 'index.php'); } // if symlink e.g. does directly translated page exist? @@ -126,12 +133,16 @@ $stats[$l]['files'] += 1; - $test = _lang_diff($f, $langF); + if ($gettext) { + $test = _po_diff($l, $resource); + } else { + $test = _lang_diff($f, $langF); + } $num_of_untranslated_strings = count($test['notrans']); $num_of_duplicated_strings = count($test['dup_str']); if ($link == 'about/constitution') { - $constitution_results = aproximate_number_of_untranslated_constitution_lines(APP_ROOT, $l, $unique_lines_in_eng_constitution); + $constitution_results = aproximate_number_of_untranslated_constitution_lines(G_APP_ROOT, $l, $unique_lines_in_eng_constitution); if ($l == 'en') { $unique_lines_in_eng_constitution = $constitution_results['unique_lines_in_constitution']; $number_of_unique_lines_in_eng_constitution = count($unique_lines_in_eng_constitution); -- cgit v1.2.1