Пример #1
0
 public function testCountErrors()
 {
     require_once TEST_FILES . 'config/sources.php';
     $obj = new _LangManager();
     $reference_data = $obj->loadSource($sites[2], 'en-US', 'page.lang');
     $locale_data = $obj->loadSource($sites[2], 'it', 'page.lang');
     $analysis_data = $obj->analyzeLangFile($sites[2], 'it', 'page.lang', $reference_data);
     $this->integer($obj->countErrors($analysis_data['errors'], 'all'))->isEqualTo(6);
     $this->integer($obj->countErrors($analysis_data['errors']))->isEqualTo(6);
     $this->integer($obj->countErrors($analysis_data['errors'], 'python'))->isEqualTo(5);
     $this->integer($obj->countErrors($analysis_data['errors'], 'length'))->isEqualTo(1);
     $this->integer($obj->countErrors($analysis_data['errors'], 'random'))->isEqualTo(0);
 }
use Transvision\Json;
// This view works only for snippets (website ID 6)
$current_website = $sites[6];
$current_locale = $locale;
$json_data = [];
if ($locale == '') {
    exit(Json::invalidAPICall('Missing locale code in the request'));
}
if (!Project::isSupportedLocale($current_website, $current_locale)) {
    exit(Json::invalidAPICall('This locale is not supported for snippets'));
}
foreach (Project::getWebsiteFiles($current_website) as $current_filename) {
    if (!Project::isSupportedLocale($current_website, $current_locale, $current_filename, $langfiles_subsets)) {
        // File is not managed for this website+locale, ignore it
        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;
    }
    $locale_data = LangManager::loadSource($current_website, $current_locale, $current_filename);
    foreach ($locale_data['strings'] as $reference_string => $translated_string) {
        if ($reference_string != $translated_string) {
            // Interested only in translated strings, clean up {ok}
            $json_data[$reference_string] = Utils::cleanString($translated_string);
        }
    }
}
ksort($json_data);
$callback = isset($_GET['callback']) ? $_GET['callback'] : false;
exit(Json::output($json_data, $callback, true));
        }
        foreach (Project::getWebsiteFiles($current_website) as $current_filename) {
            // File not supported
            if (!Project::isSupportedLocale($current_website, $current_locale, $current_filename, $langfiles_subsets)) {
                continue;
            }
            // File marked as obsolete
            if (Project::isObsoleteFile($current_website, $current_filename, $current_locale)) {
                continue;
            }
            // File doesn't exist
            if (!file_exists(Project::getLocalFilePath($current_website, $current_locale, $current_filename))) {
                continue;
            }
            $reference_data = LangManager::loadSource($current_website, $reference_locale, $current_filename);
            $locale_analysis = LangManager::analyzeLangFile($current_website, $current_locale, $current_filename, $reference_data);
            $untranslated[$current_locale] += count($locale_analysis['Identical']) + count($locale_analysis['Missing']);
            $translated[$current_locale] += count($locale_analysis['Translated']);
            $file_count[$current_locale] += 1;
        }
    }
    $all_strings[$current_locale] = $untranslated[$current_locale] + $translated[$current_locale];
}
// I need locales with more untranslated strings first
arsort($untranslated);
if ($json) {
    die(Json::output($untranslated, false, true));
}
// General table with untranslated/translated strings per locale
$rows = '';
foreach ($untranslated as $locale => $untranslated_count) {
Пример #4
0
            break;
        }
    }
    if ($reference_string == '') {
        // String not found, throw error
        http_response_code(400);
        die("No string available with id: {$string_id}.");
    }
    $supported_locales = Project::getSupportedLocales($current_website, $current_filename, $langfiles_subsets);
    $json_data[$string_id][$reference_locale] = $reference_string;
    foreach ($supported_locales as $current_locale) {
        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;
        }
        $locale_data = LangManager::loadSource($current_website, $current_locale, $current_filename);
        // Add string to Json only if localized
        if (LangManager::isStringLocalized($reference_string, $locale_data, $reference_data)) {
            $json_data[$string_id][$current_locale] = Utils::cleanString($locale_data['strings'][$reference_string]);
        }
    }
    if (isset($_GET['plaintext'])) {
        header("Content-type: text/plain; charset=utf-8");
        foreach ($json_data[$string_id] as $key => $value) {
            echo "\n{$key} : {$value}\n";
        }
        exit;
    }
    $callback = isset($_GET['callback']) ? $_GET['callback'] : false;
    exit(Json::output($json_data, $callback, true));
}
Пример #5
0
 $displayed_filename = $website_data_source == 'lang' ? $filename : basename($filename);
 $file_flags = Project::getFileFlags($website, $filename, $current_locale);
 if ($website_data_source == 'lang') {
     $locale_filename = Project::getLocalFilePath($website, $current_locale, $filename);
     if (!is_file($locale_filename) || Project::isObsoleteFile($website, $filename, $current_locale)) {
         // File is missing or marked as obsolete
         continue;
     }
     // Load reference strings
     $reference_data = LangManager::loadSource($website, $reference_locale, $filename);
     $locale_analysis = LangManager::analyzeLangFile($website, $current_locale, $filename, $reference_data);
     $export_data[$website_name][$displayed_filename]['identical'] = count($locale_analysis['Identical']);
     $export_data[$website_name][$displayed_filename]['missing'] = count($locale_analysis['Missing']);
     $export_data[$website_name][$displayed_filename]['obsolete'] = count($locale_analysis['Obsolete']);
     $export_data[$website_name][$displayed_filename]['translated'] = count($locale_analysis['Translated']);
     $export_data[$website_name][$displayed_filename]['errors'] = LangManager::countErrors($locale_analysis['errors']);
 } else {
     $file_analysis = RawManager::compareRawFiles($website, $current_locale, $filename);
     $cmp_result = $file_analysis['cmp_result'];
     $export_data[$website_name][$displayed_filename]['status'] = $cmp_result;
 }
 $export_data[$website_name][$displayed_filename]['data_source'] = $website_data_source;
 if (Project::isCriticalFile($website, $filename, $current_locale)) {
     $export_data[$website_name][$displayed_filename]['critical'] = true;
 } else {
     $export_data[$website_name][$displayed_filename]['critical'] = false;
 }
 // Flags
 if ($file_flags) {
     $export_data[$website_name][$displayed_filename]['flags'] = $file_flags;
 }