<?php

namespace Langchecker;

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);
        }
    }
Example #2
0
<?php

namespace Langchecker;

use Transvision\Json;
$json_data = [];
// $filename is set in /inc/init.php
$current_filename = $filename != '' ? $filename : 'snippets.lang';
$string_id = isset($_GET['stringid']) ? Utils::secureText($_GET['stringid']) : false;
$supported_file = false;
// Search which website has the requested file
foreach (Project::getWebsitesByDataType($sites, 'lang') as $site) {
    if (in_array($current_filename, Project::getWebsiteFiles($site))) {
        $current_website = $site;
        $supported_file = true;
        break;
    }
}
if (!$supported_file) {
    // File is not managed, throw error
    http_response_code(400);
    die("File {$current_filename} is not supported. Check the file name and try again.");
}
$reference_locale = Project::getReferenceLocale($current_website);
$reference_data = LangManager::loadSource($current_website, $reference_locale, $current_filename);
if (!$string_id) {
    // Display list of links to strings
    header("Content-type:text/html; charset=utf-8");
    echo "<ul>\n";
    foreach ($reference_data['strings'] as $current_string => $value) {
        $string_hash = sha1($current_string);
Example #3
0
<?php

namespace Langchecker;

use Transvision\Json;
$export_data = [];
$current_locale = $locale;
foreach ($sites as $website) {
    if (Project::isSupportedLocale($website, $current_locale)) {
        $website_data_source = Project::getWebsiteDataType($website);
        foreach (Project::getWebsiteFiles($website) as $filename) {
            if (!Project::isSupportedLocale($website, $current_locale, $filename, $langfiles_subsets)) {
                // File is not managed for this website+locale, ignore it
                continue;
            }
            $reference_locale = Project::getReferenceLocale($website);
            $website_name = Project::getWebsiteName($website);
            $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']);
Example #4
0
 /**
  * @dataProvider getWebsiteFilesDP
  */
 public function testGetWebsiteFiles($a, $b)
 {
     $obj = new _Project();
     $this->array($obj->getWebsiteFiles($a))->isEqualTo($b);
 }
use Transvision\Json;
ob_start();
// $filename is set in /inc/init.php
$current_filename = $filename;
if (!isset($sites[$website])) {
    // This website is not available
    if ($json) {
        die(Json::invalidAPICall("{$website} is not a supported website. Check the value and try again."));
    } else {
        die("<p>This website is not supported.</p>");
    }
}
$current_website = $sites[$website];
$website_data_source = Project::getWebsiteDataType($current_website);
if ($current_filename == '' || !in_array($current_filename, Project::getWebsiteFiles($current_website))) {
    if ($json) {
        die(Json::invalidAPICall("File {$current_filename} does not exist. Check the value and try again."));
    } else {
        die("<p>ERROR: file {$current_filename} does not exist</p>");
    }
}
$complete_locales_count = 0;
$complete_locales_list = [];
$json_data = [];
$reference_locale = Project::getReferenceLocale($current_website);
if ($website_data_source == 'lang') {
    // Websites using .lang files
    $activated_locales_count = 0;
    $activated_locales_list = [];
    $file_activable = !in_array($current_filename, $no_active_tag);