Example #1
0
 /**
  * Compare reference and localized raw file
  *
  * @param array  $website  Website data
  * @param string $locale   Locale to analyze
  * @param string $filename File to analyze
  *
  * @return array Results from comparison
  */
 public static function compareRawFiles($website, $locale, $filename)
 {
     $results = [];
     // Store reference file hash and last update date
     $reference_locale = Project::getReferenceLocale($website);
     $reference_filename = Project::getLocalFilePath($website, $reference_locale, $filename);
     if (file_exists($reference_filename)) {
         $reference_content = sha1_file($reference_filename);
         $results['reference_exists'] = true;
         $results['reference_url'] = Project::getPublicFilePath($website, $reference_locale, $filename);
         $results['reference_lastupdate'] = Utils::getSVNCommitTimestamp($reference_filename);
     } else {
         $results['reference_exists'] = false;
         $results['cmp_result'] = 'missing_reference';
     }
     // Generate locale file hash and last update date
     $locale_filename = Project::getLocalFilePath($website, $locale, $filename);
     if (file_exists($locale_filename)) {
         $locale_content = sha1_file($locale_filename);
         $results['locale_exists'] = true;
         $results['locale_url'] = Project::getPublicFilePath($website, $locale, $filename);
         $results['locale_lastupdate'] = Utils::getSVNCommitTimestamp($locale_filename);
         if ($results['reference_exists']) {
             if ($locale_content == $reference_content) {
                 $results['cmp_result'] = 'untranslated';
             } elseif ($results['reference_lastupdate'] > $results['locale_lastupdate']) {
                 // I check dates only if content is not identical
                 $results['cmp_result'] = 'outdated';
             } else {
                 $results['cmp_result'] = 'ok';
             }
         }
     } else {
         $results['locale_exists'] = false;
         $results['cmp_result'] = 'missing_locale';
     }
     return $results;
 }
$table_end_code = "\n</tbody>\n</table>";
// We only consider mozilla.org for this view, so $sites[0]
$current_website = $sites[0];
$reference_locale = Project::getReferenceLocale($current_website);
foreach (Project::getWebsiteFiles($current_website) as $current_filename) {
    // I need to check only files that can be activated
    if (!in_array($current_filename, $no_active_tag)) {
        // Read en-US data only once
        $reference_data = LangManager::loadSource($current_website, $reference_locale, $current_filename);
        $supported_locales = Project::getSupportedLocales($current_website, $current_filename, $langfiles_subsets);
        foreach ($supported_locales as $current_locale) {
            if ($current_locale == $reference_locale) {
                // Ignore reference language
                continue;
            }
            if (!file_exists(Project::getLocalFilePath($current_website, $current_locale, $current_filename))) {
                // If the .lang file does not exist, just skip the locale for this file
                continue;
            }
            if (Project::isObsoleteFile($current_website, $current_filename, $current_locale)) {
                // If the .lang file is obsolete, skip it
                continue;
            }
            $locale_analysis = LangManager::analyzeLangFile($current_website, $current_locale, $current_filename, $reference_data);
            $todo = count($locale_analysis['Identical']) + count($locale_analysis['Missing']) + LangManager::countErrors($locale_analysis['errors']);
            $activation_status = $locale_analysis['activated'] ? 'yes' : 'no';
            if ($todo == 0 && $activation_status == 'no') {
                $svn_path = 'http://viewvc.svn.mozilla.org/vc/projects/mozilla.com/trunk/locales/' . $current_locale . '/' . $current_filename;
                $table_rows .= "  <tr>\n";
                $table_rows .= '    <td><a href="./?locale=' . $current_locale . '" title="See full status of this locale">' . $current_locale . "</a></td>\n";
                $table_rows .= '    <td><a href="' . $svn_path . '" target="_blank" title="Open this file on SVN">' . $current_filename . "</a></td>\n";
Example #3
0
            }
        }
    }
    if ($reference_with_errors) {
        $reference_output .= "      </div>\n\n";
        $htmloutput .= $reference_output;
    }
}
foreach (Project::getWebsitesByDataType($sites, 'raw') as $current_website) {
    $reference_with_errors = false;
    $current_website_name = Project::getWebsiteName($current_website);
    $reference_locale = Project::getReferenceLocale($current_website);
    $reference_output = "      <h2>Reference locale: {$reference_locale}</h2>\n";
    $opening_div = "      <div class='website_container'>\n" . "        <h2>{$current_website_name}</h2>\n";
    foreach (Project::getWebsiteFiles($current_website) as $current_filename) {
        $reference_filename = Project::getLocalFilePath($current_website, $reference_locale, $current_filename);
        if (!file_exists($reference_filename)) {
            if (!$reference_with_errors) {
                $reference_with_errors = true;
                $reference_output .= $opening_div;
            }
            $reference_output .= "        <p><strong>{$current_filename}</strong> is missing</p>\n";
        }
    }
    if ($reference_with_errors) {
        $reference_output .= "      </div>\n\n";
        $htmloutput .= $reference_output;
    }
}
if ($htmloutput == '') {
    // There are no errors
 /**
  * Load file, remove empty lines and return an array of strings
  *
  * @param array  $website  Website data
  * @param string $locale   Locale to analyze
  * @param string $filename File to analyze
  *
  * @return array Data parsed from lang file
  */
 public static function loadSource($website, $locale, $filename)
 {
     $is_reference_language = $locale == Project::getReferenceLocale($website);
     $path = Project::getLocalFilePath($website, $locale, $filename);
     return DotLangParser::parseFile($path, $is_reference_language);
 }