Пример #1
0
namespace Transvision;

$source = Utils::getRepoStrings(Project::getReferenceLocale($repo), $repo);
$target = Utils::getRepoStrings($locale, $repo);
// Set up channel selector, ignore mozilla.org
$channels = Project::getSupportedRepositories();
unset($channels['mozilla_org']);
$channel_selector = Utils::getHtmlSelectOptions($channels, $repo, true);
// Build the target locale switcher
$target_locales_list = Utils::getHtmlSelectOptions(Project::getRepositoryLocales($repo), $locale);
$source = array_map(['Transvision\\AnalyseStrings', 'cleanUpEntities'], $source);
$target = array_map(['Transvision\\AnalyseStrings', 'cleanUpEntities'], $target);
// We need to ignore some strings because of false positives
$ignored_strings = ['mail/chrome/messenger/aboutRights.dtd:rights.webservices-term4', 'suite/chrome/branding/aboutRights.dtd:rights.webservices-term4', 'toolkit/chrome/global/aboutRights.dtd:rights.webservices-term5'];
$var_errors = AnalyseStrings::differences($source, $target, $repo, $ignored_strings);
$error_count = count($var_errors);
// Add component filter
if (in_array($repo, $desktop_repos)) {
    // Build logic to filter components
    $javascript_include = ['component_filter.js'];
    $components = Project::getComponents(array_flip($var_errors));
    $filter_block = '';
    foreach ($components as $value) {
        $filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>";
    }
}
// RTL support
$direction1 = RTLSupport::getDirection($source_locale);
$direction2 = RTLSupport::getDirection($locale);
$bugzilla_base_link = 'https://bugzilla.mozilla.org/enter_bug.cgi?format=__default__&component=' . Bugzilla::getURLencodedBugzillaLocale($locale, 'products') . '&product=Mozilla%20Localizations&status_whiteboard=%5Btransvision-feedback%5D';
Пример #2
0
 /**
  * Html table of search results used by the main view (needs a lot of refactoring)
  *
  * @param array  $search_id      Identifier for the current search
  * @param array  $search_results List of rows
  * @param string $recherche      The words searched for
  * @param string $locale1        Reference locale to search in, usually en-US
  * @param string $locale2        Target locale to search in
  * @param array  $search_options All the search options from the query
  *
  * @return string html table to insert in the view
  */
 public static function resultsTable($search_id, $search_results, $recherche, $locale1, $locale2, $search_options)
 {
     $direction1 = RTLSupport::getDirection($locale1);
     $direction2 = RTLSupport::getDirection($locale2);
     if (isset($search_options['extra_locale'])) {
         $locale3 = $search_options['extra_locale'];
         $direction3 = RTLSupport::getDirection($locale3);
         $extra_column_header = "<th>{$locale3}</th>";
     } else {
         $extra_column_header = '';
     }
     $table = "<table class='collapsable results_table {$search_id}'>\n                      <tr class='column_headers'>\n                        <th>Entity</th>\n                        <th>{$locale1}</th>\n                        <th>{$locale2}</th>\n                        {$extra_column_header}\n                      </tr>";
     if (!$search_options['whole_word'] && !$search_options['perfect_match']) {
         $recherche = Utils::uniqueWords($recherche);
     } else {
         $recherche = [$recherche];
     }
     $current_repo = $search_options['repo'];
     foreach ($search_results as $key => $strings) {
         // Don't highlight search matches in entities when searching strings
         if ($search_options['search_type'] == 'strings') {
             $result_entity = self::formatEntity($key);
         } else {
             $result_entity = self::formatEntity($key, $recherche[0]);
         }
         $component = explode('/', $key)[0];
         $source_string = trim($strings[0]);
         $target_string = trim($strings[1]);
         $entity_link = "?sourcelocale={$locale1}" . "&locale={$locale2}" . "&repo={$current_repo}" . "&search_type=entities&recherche={$key}";
         $bz_link = [Bugzilla::reportErrorLink($locale2, $key, $source_string, $target_string, $current_repo, $entity_link)];
         if (isset($search_options['extra_locale'])) {
             $target_string2 = trim($strings[2]);
             $entity_link = "?sourcelocale={$locale1}" . "&locale={$search_options['extra_locale']}" . "&repo={$current_repo}" . "&search_type=entities&recherche={$key}";
             $bz_link[] = Bugzilla::reportErrorLink($search_options['extra_locale'], $key, $source_string, $target_string2, $current_repo, $entity_link);
         } else {
             $target_string2 = '';
         }
         foreach ($recherche as $val) {
             $source_string = Utils::markString($val, $source_string);
             $target_string = Utils::markString($val, $target_string);
             if (isset($search_options["extra_locale"])) {
                 $target_string2 = Utils::markString($val, $target_string2);
             }
         }
         // Escape HTML before highlighing search terms
         $source_string = htmlspecialchars($source_string);
         $target_string = htmlspecialchars($target_string);
         $source_string = Utils::highlightString($source_string);
         $target_string = Utils::highlightString($target_string);
         if (isset($search_options["extra_locale"])) {
             $target_string2 = htmlspecialchars($target_string2);
             $target_string2 = Utils::highlightString($target_string2);
         }
         $replacements = [' ' => '<span class="highlight-gray" title="Non breakable space"> </span>', ' ' => '<span class="highlight-red" title="Thin space"> </span>', '…' => '<span class="highlight-gray">…</span>', '&hellip;' => '<span class="highlight-gray">…</span>'];
         $target_string = Strings::multipleStringReplace($replacements, $target_string);
         $temp = explode('-', $locale1);
         $locale1_short_code = $temp[0];
         $temp = explode('-', $locale2);
         $locale2_short_code = $temp[0];
         switch ($current_repo) {
             case 'mozilla_org':
                 $locale1_path = VersionControl::gitPath($locale1, $current_repo, $key);
                 $locale2_path = VersionControl::gitPath($locale2, $current_repo, $key);
                 break;
             case 'firefox_ios':
                 $locale1_path = VersionControl::svnPath($locale1, $current_repo, $key);
                 $locale2_path = VersionControl::svnPath($locale2, $current_repo, $key);
                 break;
             default:
                 $locale1_path = VersionControl::hgPath($locale1, $current_repo, $key);
                 $locale2_path = VersionControl::hgPath($locale2, $current_repo, $key);
                 break;
         }
         // errors
         $error_message = '';
         // check for final dot
         if (substr(strip_tags($source_string), -1) == '.' && substr(strip_tags($target_string), -1) != '.') {
             $error_message = '<em class="error"> No final dot?</em>';
         }
         // check abnormal string length
         $length_diff = Utils::checkAbnormalStringLength($source_string, $target_string);
         if ($length_diff) {
             switch ($length_diff) {
                 case 'small':
                     $error_message = $error_message . '<em class="error"> Small string?</em>';
                     break;
                 case 'large':
                     $error_message = $error_message . '<em class="error"> Large String?</em>';
                     break;
             }
         }
         // Missing string error
         if (!$source_string) {
             $source_string = '<em class="error">warning: missing string</em>';
             $error_message = '';
         }
         if (!$target_string) {
             $target_string = '<em class="error">warning: missing string</em>';
             $error_message = '';
         }
         if (!$target_string2) {
             $target_string2 = '<em class="error">warning: missing string</em>';
             $error_message = '';
         }
         // Replace / and : in the key name and use it as an anchor name
         $anchor_name = str_replace(['/', ':'], '_', $key);
         $clipboard_target_string = 'clip_' . md5($target_string);
         // 3locales view
         if (isset($search_options["extra_locale"])) {
             switch ($current_repo) {
                 case 'mozilla_org':
                     $locale3_path = VersionControl::gitPath($locale3, $current_repo, $key);
                     break;
                 case 'firefox_ios':
                     $locale3_path = VersionControl::svnPath($locale3, $current_repo, $key);
                     break;
                 default:
                     $locale3_path = VersionControl::hgPath($locale3, $current_repo, $key);
                     break;
             }
             $clipboard_target_string2 = 'clip_' . md5($target_string2);
             $extra_column_rows = "\n                <td dir='{$direction3}' lang='{$locale3}'>\n                    <span class='celltitle'>{$locale3}</span>\n                    <div class='string' id='{$clipboard_target_string2}'>{$target_string2}</div>\n                    <div dir='ltr' class='result_meta_link'>\n                      <a class='source_link' href='{$locale3_path}'>\n                        &lt;source&gt;\n                      </a>\n                      &nbsp;\n                      <a class='bug_link' target='_blank' href='{$bz_link[1]}'>\n                        &lt;report a bug&gt;\n                      </a>\n                      <span class='clipboard' data-clipboard-target='#{$clipboard_target_string2}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>\n                    </div>\n                  </td>";
         } else {
             $extra_column_rows = '';
         }
         $table .= "\n                <tr class='{$component} {$search_id}'>\n                  <td>\n                    <span class='celltitle'>Entity</span>\n                    <a class='resultpermalink tag' id='{$anchor_name}' href='#{$anchor_name}' title='Permalink to this result'>link</a>\n                    <a class='l10n tag' href='/string/?entity={$key}&amp;repo={$current_repo}' title='List all translations for this entity'>l10n</a>\n                    <a class='link_to_entity' href=\"/{$entity_link}\">{$result_entity}</a>\n                  </td>\n                  <td dir='{$direction1}' lang='{$locale1}'>\n                    <span class='celltitle'>{$locale1}</span>\n                    <div class='string'>\n                      {$source_string}\n                    </div>\n                    <div dir='ltr' class='result_meta_link'>\n                      <a class='source_link' href='{$locale1_path}'>\n                        &lt;source&gt;\n                      </a>\n                      <span>Translate with:</span>\n                      <a href='http://translate.google.com/#{$locale1_short_code}/{$locale2_short_code}/" . urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string)))) . "' target='_blank'>Google</a>\n                      <a href='http://www.bing.com/translator/?from={$locale1_short_code}&to={$locale2_short_code}&text=" . urlencode(strip_tags(html_entity_decode(html_entity_decode($source_string)))) . "' target='_blank'>BING</a>\n                    </div>\n                  </td>\n\n                  <td dir='{$direction2}' lang='{$locale2}'>\n                    <span class='celltitle'>{$locale2}</span>\n                    <div class='string' id='{$clipboard_target_string}'>{$target_string}</div>\n                    <div dir='ltr' class='result_meta_link'>\n                      <a class='source_link' href='{$locale2_path}'>\n                        &lt;source&gt;\n                      </a>\n                      &nbsp;\n                      <a class='bug_link' target='_blank' href='{$bz_link[0]}'>\n                        &lt;report a bug&gt;\n                      </a>\n                      <span class='clipboard' data-clipboard-target='#{$clipboard_target_string}' alt='Copy to clipboard'><img src='/img/copy_icon_black_18x18.png'></span>\n                      {$error_message}\n                    </div>\n                  </td>\n                {$extra_column_rows}\n                </tr>";
     }
     $table .= "  </table>";
     return $table;
 }
Пример #3
0
<?php

namespace Transvision;

// RTL support
$direction1 = RTLSupport::getDirection($source_locale);
$direction2 = RTLSupport::getDirection($locale);
if ($url['path'] == '3locales') {
    $direction3 = RTLSupport::getDirection($locale2);
    $extra_column_header = "<th>{$locale2}</th>";
} else {
    $extra_column_header = '';
}
$entities = ShowResults::searchEntities($tmx_source, $search->getRegex());
// Display a search hint for the closest string we have if we have no search results
if (count($entities) == 0) {
    $merged_strings = [];
    $best_matches = Strings::getSimilar($initial_search, array_keys($tmx_source), 3);
    include VIEWS . 'results_similar.php';
    return;
}
Пример #4
0
// Error management
if (isset($error)) {
    if ($error == 1) {
        print "<p>No entity asked for, goodbye.</p>";
    } elseif ($error == 2) {
        print "<p>Entity does not exist for this repo, goodbye.</p>";
    }
    return;
}
// We have no error, display results
$page_descr = $entity;
// Promote API view
include VIEWS . 'templates/api_promotion.php';
?>

<table>
    <tr>
        <th>Locale</th>
        <th>Translation</th>
        <th>&nbsp;</th>
    </tr>
    <?php 
$reference_locale = Project::getReferenceLocale($repo);
foreach ($translations as $locale => $translation) {
    $rtl_support = RTLSupport::isRTL($locale) ? 'dir="rtl"' : '';
    $search_link = "/?sourcelocale={$reference_locale}&locale={$locale}&repo={$repo}&search_type=entities&recherche={$entity}&perfect_match=perfect_match";
    echo "<tr id='{$locale}''>\n" . "  <th><a href='#{$locale}'>{$locale}</a></th>\n" . "  <td lang='#{$locale}' {$rtl_support} >" . Utils::secureText($translation) . "</td>\n" . "  <td><a class='onestring_search' href='{$search_link}' title='Search for the entity in this locale'>�</a></td>\n" . "</tr>\n";
}
?>
</table>
<?php 
Пример #5
0
<?php

namespace Transvision;

// Include the common simple search form
include __DIR__ . '/simplesearchform.php';
$search_id = 'unchanged_strings';
$content = "<h2><span class=\"results_count_{$search_id}\">" . Utils::pluralize(count($unchanged_strings), 'string') . "</span> identical to English</h2>\n";
if (isset($filter_block)) {
    $content .= "<div id='filters'>" . "  <h4>Filter by folder:</h4>\n" . "  <a href='#showall' id='showall' class='filter'>Show all results</a>\n" . $filter_block . "</div>\n";
}
$content .= "<table class='collapsable results_table {$search_id}'>\n";
$content .= "  <tr class='column_headers'>\n" . "    <th>String ID</th>\n" . "    <th>English</th>\n" . "    <th>Translation</th>\n" . "  </tr>\n";
foreach ($unchanged_strings as $string_id => $string_value) {
    $component = explode('/', $string_id)[0];
    $entity_link = "/?sourcelocale={$source_locale}" . "&locale={$locale}" . "&repo={$repo}" . "&search_type=entities&recherche={$string_id}";
    /*
        Since this view displays strings identical to source locale, I'll use the same
        direction, not the locale's default (for example I'll use LTR for English+Arabic).
    */
    $direction = RTLSupport::getDirection($source_locale);
    $content .= "  <tr class='{$component} {$search_id}'>\n" . "    <td dir='ltr'><a href='{$entity_link}'>{$string_id}</a></td>\n" . "    <td dir='{$direction}' lang='{$source_locale}'>{$string_value}</td>\n" . "    <td dir='{$direction}' lang='{$locale}'>" . $strings_locale[$string_id] . "</td>\n" . "  </tr>\n";
}
$content .= "</table>\n";
echo $content;