public function testAnalyzeLangFile() { 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->boolean($analysis_data['activated'])->isTrue(); // Identical should be equal to 2, also empty string is considered identical $this->integer(count($analysis_data['Identical']))->isEqualTo(2); $this->integer(count($analysis_data['Missing']))->isEqualTo(1); $this->integer(count($analysis_data['Obsolete']))->isEqualTo(1); $this->integer(count($analysis_data['Translated']))->isEqualTo(13); $this->integer(count($analysis_data['errors']['python']))->isEqualTo(5); $this->string($analysis_data['errors']['python']['String with %(num)s tags']['text'])->isEqualTo('Stringa con etichette e variabile sbagliata'); $this->string($analysis_data['errors']['python']['String with %(num)s tags']['var'])->isEqualTo('%(num)s'); $this->boolean($obj->isStringLocalized('Hello', $locale_data, $reference_data))->isTrue(); $this->boolean($obj->isStringLocalized('Test', $locale_data, $reference_data))->isFalse(); }
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)); }