<?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); } }
echo "\n <tr>\n <td class='maincolumn'>{$locale_link}</td>\n <td><span class='rawstatus {$cmp_result}'>" . str_replace('_', ' ', $cmp_result) . "</span></td>\n </tr>\n"; } $coverage = Project::getUserBaseCoverage($complete_locales_list, $adu) . '%'; echo ' </tbody> <tfoot> <tr> <td colspan= "2">' . $complete_locales_count . ' translated locales (' . round($complete_locales_count / count($supported_locales) * 100) . '%)<br>' . $coverage . ' of our l10n user base' . '</td> </tr> </tfoot> </table> '; } $htmlresult = ob_get_contents(); ob_clean(); if ($json) { if ($locale == 'all' || $locale == '') { echo Json::output($json_data, false, true); } else { // Only one locale if (isset($json_data[$current_filename][$locale])) { $single_locale_json[$current_filename][$locale] = $json_data[$current_filename][$locale]; echo Json::output($single_locale_json, false, true); } else { // Unknown locale die(Json::invalidAPICall("Unknown locale: {$locale}. Check the value and try again.")); } } } else { echo $htmlresult; }
<?php namespace Langchecker; use Transvision\Json; if (!isset($_GET['locales'])) { die(Json::invalidAPICall('ERROR: missing list of locales.')); } $locales = $_GET['locales']; if (!is_array($locales)) { die(Json::invalidAPICall('ERROR: locales is not an array.')); } echo Project::getUserBaseCoverage($locales, $adu);
// $filename is set in /inc/init.php $current_filename = $filename != '' ? $filename : 'snippets.lang'; $show_status = isset($_GET['show']) ? 'auto' : 'none'; $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) { $error_message = "<p>ERROR: file {$filename} does not exist</p>"; if ($json) { die(Json::invalidAPICall($error_message)); } else { die($error_message); } } $reference_locale = Project::getReferenceLocale($current_website); $reference_data = LangManager::loadSource($current_website, $reference_locale, $current_filename); $all_strings = []; $supported_locales = Project::getSupportedLocales($current_website, $current_filename, $langfiles_subsets); 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); foreach ($reference_data['strings'] as $string_id => $string_value) {