Ejemplo n.º 1
0
<?php

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);
Ejemplo n.º 2
0
<?php

namespace Transvision;

$tmx_target2 = Utils::getRepoStrings($locale2, $check['repo']);
if ($search->isPerfectMatch()) {
    $locale3_strings = preg_grep($search->getRegex(), $tmx_target2);
} else {
    $locale3_strings = $tmx_target2;
    foreach (Utils::uniqueWords($initial_search) as $word) {
        $search->setRegexSearchTerms($word);
        $locale3_strings = preg_grep($search->getRegex(), $locale3_strings);
    }
}
array_splice($locale3_strings, 200);
foreach (Project::getRepositories() as $repository) {
    $loc_list[$repository] = Project::getRepositoryLocales($repository);
    $target_locales_list2[$repository] = Utils::getHtmlSelectOptions($loc_list[$repository], $locale2);
}
$case_sensitive = $get_option('case_sensitive') ? '' : 'i';
if ($get_option('perfect_match')) {
    $regex = '~' . $whole_word . trim('^' . preg_quote($initial_search, '~') . '$') . $whole_word . '~' . $case_sensitive . 'u';
    if ($request->parameters[2] == 'entities') {
        $entities = ShowResults::searchEntities($source_strings, $regex);
        $source_strings = array_intersect_key($source_strings, array_flip($entities));
    } else {
        $source_strings = preg_grep($regex, $source_strings);
        $entities = array_keys($source_strings);
    }
} else {
    foreach (Utils::uniqueWords($initial_search) as $word) {
        $regex = '~' . $whole_word . preg_quote($word, '~') . $whole_word . '~' . $case_sensitive . 'u';
        if ($request->parameters[2] == 'entities') {
            $entities = ShowResults::searchEntities($source_strings, $regex);
            $source_strings = array_intersect_key($source_strings, array_flip($entities));
        } else {
            $source_strings = preg_grep($regex, $source_strings);
            $entities = array_keys($source_strings);
        }
    }
}
// We have our list of filtered source strings, get corresponding target locale strings
$target_strings = array_intersect_key(Utils::getRepoStrings($request->parameters[5], $request->parameters[3]), array_flip($entities));
// We sort arrays by key before array_splice() to keep matching keys
ksort($source_strings);
ksort($target_strings);
// Limit results to 200
array_splice($source_strings, 200);
array_splice($target_strings, 200);
return $json = ShowResults::getRepositorySearchResults($entities, [$source_strings, $target_strings]);
Ejemplo n.º 4
0
$initial_search = Utils::cleanString($request->parameters[5]);
$terms = Utils::uniqueWords($initial_search);
// Define our regex
$search = (new Search())->setSearchTerms(Utils::cleanString($initial_search))->setRegexWholeWords($get_option('whole_word'))->setRegexCaseInsensitive($get_option('case_sensitive'))->setRegexPerfectMatch($get_option('perfect_match'));
// We loop through all repositories and merge the results
foreach ($repositories as $repository) {
    $source_strings = Utils::getRepoStrings($request->parameters[3], $repository);
    foreach ($terms as $word) {
        $search->setRegexSearchTerms($word);
        $source_strings = preg_grep($search->getRegex(), $source_strings);
    }
    /*
        If we don't have any match for a repo, no need to do heavy calculations,
        just skip to the next repo.
    */
    if (empty($source_strings)) {
        continue;
    }
    /*
        We are only interested in target strings with keys in common with our
        source strings.
    */
    $target_strings = Utils::getRepoStrings($request->parameters[4], $repository);
    foreach ($source_strings as $key => $value) {
        if (isset($target_strings[$key]) && !empty($target_strings[$key])) {
            $output[] = [$value, $target_strings[$key]];
        }
    }
    unset($source_strings, $target_strings);
}
return $json = ShowResults::getTranslationMemoryResults($output, $initial_search, $get_option('max_results'), $get_option('min_quality'));
Ejemplo n.º 5
0
<?php

namespace Transvision;

// Set $repo to get the correct list of locales for Gaia from l10n-init.php
$repo = 'gaia';
require_once INC . 'l10n-init.php';
// Functions
$get_or_set = function ($arr, $value, $fallback) {
    return isset($_GET[$value]) && in_array($_GET[$value], $arr) ? $_GET[$value] : $fallback;
};
$get_repo_strings = function ($locale, $repo) {
    return array_filter(Utils::getRepoStrings($locale, $repo), 'strlen');
};
$build_select = function ($array_in, $selected_elm) use($repos_nice_names) {
    $string_out = '';
    foreach ($array_in as $elm) {
        $ch = $elm == $selected_elm ? ' selected' : '';
        $elm_nice_name = isset($repos_nice_names[$elm]) ? $repos_nice_names[$elm] : $elm;
        $string_out .= "<option" . $ch . " value=" . $elm . ">" . $elm_nice_name . "</option>\n";
    }
    return $string_out;
};
// Variables
// Project::getGaiaRepositories() returns ordered repos from newest to oldest
$repo1 = 'gaia';
$repo2 = Project::getLastGaiaBranch();
$locale = $get_or_set($all_locales, 'locale', $locale);
$repo1 = $get_or_set($gaia_repos, 'repo1', $repo1);
$repo2 = $get_or_set($gaia_repos, 'repo2', $repo2);
// Get the locale list
Ejemplo n.º 6
0
<?php

namespace Transvision;

$strings = Utils::getRepoStrings(Project::getReferenceLocale($repo), $repo);
// Invalid entity, we don't do any calculation and get back to the view
if (!$entity) {
    return $error = 1;
} elseif (!array_key_exists($entity, $strings)) {
    return $error = 2;
}
include MODELS . 'api/entity.php';
Ejemplo n.º 7
0
<?php

namespace Transvision;

require_once INC . 'l10n-init.php';
$chan1 = 'aurora';
$chan2 = 'beta';
if (isset($_GET['chan1']) && in_array($_GET['chan1'], $desktop_repos)) {
    $chan1 = $_GET['chan1'];
}
if (isset($_GET['chan2']) && in_array($_GET['chan2'], $desktop_repos)) {
    $chan2 = $_GET['chan2'];
}
$strings = [];
$strings[$chan1] = Utils::getRepoStrings($locale, $chan1);
$strings[$chan2] = Utils::getRepoStrings($locale, $chan2);
$chan_selector1 = $chan_selector2 = '';
foreach ($desktop_repos as $repo) {
    $ch1 = $repo == $chan1 ? ' selected' : '';
    $ch2 = $repo == $chan2 ? ' selected' : '';
    $chan_selector1 .= "\t<option" . $ch1 . " value=" . $repo . ">" . $repos_nice_names[$repo] . "</option>\n";
    $chan_selector2 .= "\t<option" . $ch2 . " value=" . $repo . ">" . $repos_nice_names[$repo] . "</option>\n";
}
// Get the locale list
$loc_list = Project::getRepositoryLocales($repo);
// Build the target locale switcher
$target_locales_list = '';
foreach ($loc_list as $loc) {
    $ch = $loc == $locale ? ' selected' : '';
    $target_locales_list .= "\t<option" . $ch . " value=" . $loc . ">" . $loc . "</option>\n";
}
Ejemplo n.º 8
0
<?php

namespace Transvision;

require_once INC . 'l10n-init.php';
$strings[$repo] = Utils::getRepoStrings($locale, $repo);
$strings_english[$repo] = Utils::getRepoStrings('en-US', $repo);
$channel_selector = Utils::getHtmlSelectOptions(array_intersect_key($repos_nice_names, array_flip($desktop_repos)), $repo, true);
// Get the locale list
$loc_list = Project::getRepositoryLocales($repo);
// build the target locale switcher
$target_locales_list = Utils::getHtmlSelectOptions($loc_list, $locale);
$akeys = array_filter(array_keys($strings[$repo]), function ($entity) {
    return substr($entity, -9) == 'accesskey';
});
$ak_labels = ['.label', '.title', '.title2'];
$ak_results = [];
foreach ($akeys as $akey) {
    $entity = substr($akey, 0, -10);
    $akey_value = $strings[$repo][$akey];
    foreach ($ak_labels as $ak_label) {
        if (isset($strings[$repo][$entity . $ak_label]) && !empty($strings[$repo][$entity . $ak_label]) && isset($strings_english[$repo][$akey]) && !empty($strings_english[$repo][$akey])) {
            if ($akey_value == '') {
                $ak_results[$akey] = $entity . $ak_label;
            } elseif (mb_stripos($strings[$repo][$entity . $ak_label], $akey_value) === false) {
                $ak_results[$akey] = $entity . $ak_label;
            } else {
                break;
            }
        }
    }
Ejemplo n.º 9
0
foreach ($repos as $val) {
    $ch = $val == $repo ? ' selected' : '';
    $channel_selector .= "\t<option" . $ch . " value=" . $val . ">" . $repos_nice_names[$val] . "</option>\n";
}
// Using a callback with strlen() avoids filtering out numeric strings with a value of 0
$strings['en-US'][$repo] = array_filter(Utils::getRepoStrings('en-US', $repo), 'strlen');
$gaia_locales = Project::getRepositoryLocales($repo);
// We don't want en-US in the repos
if ($key = array_search('en-US', $gaia_locales)) {
    unset($gaia_locales[$key]);
}
$string_count = [];
// Referen_ce locale count
$count_reference = count($strings['en-US'][$repo]);
foreach ($gaia_locales as $val) {
    $strings[$val][$repo] = array_filter(Utils::getRepoStrings($val, $repo), 'strlen');
    $string_count[$val] = ['total' => count($strings[$val][$repo]), 'missing' => count(array_diff_key($strings['en-US'][$repo], $strings[$val][$repo])), 'identical' => count(array_intersect_assoc($strings['en-US'][$repo], $strings[$val][$repo]))];
    unset($strings[$val][$repo]);
}
$json = [];
$table = '
<style>td {text-align:right;} form[name="searchform"] { text-align: center; }</style>
<table>
<tr>
    <th>Locale</th>
    <th>Total</th>
    <th>Missing</th>
    <th>Translated</th>
    <th>Identical</th>
    <th>Completion</th>
    <th>Status estimate</th>
Ejemplo n.º 10
0
<?php

namespace Transvision;

$missing_repos = $available_repos = $results = '';
$missing_repos_count = $repos_count = 0;
$strings = ['en-US' => [], $locale => []];
foreach ($repos as $repo) {
    if (isset($_GET[$repo])) {
        $cache_file_english = Utils::getRepoStrings(Project::getReferenceLocale($repo), $repo);
        if ($cache_file_english) {
            $cache_file_locale = Utils::getRepoStrings($locale, $repo);
            if ($repo == 'mozilla_org') {
                $cache_file_locale = array_map(function ($e) {
                    return trim(rtrim($e, '{ok}'));
                }, $cache_file_locale);
            }
            // If a repo is missing, we don't have additional keys
            if ($cache_file_locale) {
                $strings['en-US'] = array_merge($strings['en-US'], $cache_file_english);
                $strings[$locale] = array_merge($strings[$locale], $cache_file_locale);
                $repos_count++;
                $available_repos .= '<br>' . $repos_nice_names[$repo] . ' (' . $locale . ')';
                unset($cache_file_locale);
            } else {
                $missing_repos_count++;
                $missing_repos .= '<br>' . $repos_nice_names[$repo] . ' (' . $locale . ')';
            }
            unset($cache_file_english);
        }
    }
Ejemplo n.º 11
0
        $search->setRegexSearchTerms($word);
        $source_strings = preg_grep($search->getRegex(), $source_strings);
    }
    /*
        If we don't have any match for a repo, no need to do heavy calculations,
        just skip to the next repo.
    */
    if (empty($source_strings)) {
        continue;
    }
    /*
        We are only interested in target strings with keys in common with our
        source strings. Not sending noise to getTranslationMemoryResults() has
        a major performance and memory impact.
    */
    $target_strings = array_intersect_key(Utils::getRepoStrings($request->parameters[4], $repository), $source_strings);
    /*
        We are not interested in keeping duplicate strings that have
        different keys because this API does not take into account the
        frequency of matches but the similarity of the strings.
    */
    $target_strings = array_unique($target_strings);
    /*
       The + operator is slightly faster than array_merge and also easier
       to read. The functional difference doesn't matter in this case
       (http://stackoverflow.com/questions/7059721/array-merge-versus/27717809#27717809)
    */
    $source_strings_merged += $source_strings;
    $target_strings_merged += $target_strings;
    unset($source_strings, $target_strings);
}