Example #1
0
<?php

namespace Langchecker;

$html_output = '<p id="back"><a href="http://l10n.mozilla-community.org/webdashboard/">Back to Web Dashboard</a></p>';
// This view works only for mozilla.org (website ID 0)
$current_website = $sites[0];
$current_locale = $locale;
if (!Project::isSupportedLocale($current_website, $current_locale)) {
    exit($html_output . '<p>This locale is not supported on mozilla.org</p>');
}
// Create a list of opt-in pages
$optin_pages = [];
foreach (Project::getWebsiteFiles($current_website) as $current_filename) {
    if (in_array('opt-in', Project::getFileFlags($current_website, $current_filename, $current_locale))) {
        $optin_pages[$current_filename] = Project::getSupportedLocales($current_website, $current_filename, $langfiles_subsets);
    }
}
if (count($optin_pages) == 0) {
    exit($html_output . '<p>There are no optional pages available at the moment.</p>');
}
$html_output .= "<h1>List of optional pages for <span>{$current_locale}</span></h1>\n  <table class='optinpages'>\n    <thead>\n      <tr>\n        <th>Filename</th>\n        <th>URL</th>\n        <th>Strings</th>\n        <th>Words</th>\n        <th>Opted-in</th>\n        <th>Actions</th>\n      </tr>\n    </thead>\n    <tbody>\n";
$bugzilla_locale = urlencode(Bugzilla::getBugzillaLocaleField($current_locale, 'www'));
$available_optins = [];
foreach ($optin_pages as $current_filename => $supported_locales) {
    $reference_locale = Project::getReferenceLocale($current_website);
    $reference_data = LangManager::loadSource($current_website, $reference_locale, $current_filename);
    $get_words = function ($item) {
        return str_word_count(strip_tags($item));
    };
    $nb_words = array_sum(array_map($get_words, $reference_data['strings']));
      <th>Activated</th>
    </tr>
  </thead>
  <tbody>
';
$table_rows = '';
$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']);