/** * Return the translation for a string * @param string $string The string we want the translation for * @return string The translation of the string or the source string if not translated */ public function get($string) { if (isset($this->translations['strings'][$string])) { return Utils::cleanString($this->translations['strings'][$string]); } return $string; }
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));
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)); }
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) { if (LangManager::isStringLocalized($string_id, $locale_data, $reference_data)) { $all_strings[$string_id][$current_locale] = Utils::cleanString($locale_data['strings'][$string_id]); } } } // If request output is JSON, we're ready if ($json) { die(Json::output($all_strings, false, true)); } // Colors used to display tags $bg_colors = ['#459E09', '#B29EF9', '#2D68BA', '#E39530', '#D6D6D4', '#E3309E', '#FF4040', '#F5F562', '#F562C7', '#C0FCF2']; $font_colors = ['#FFF', '#FFF', '#FFF', '#FFF', '#000', '#FFF', '#FFF', '#000', '#FFF', '#000']; if (isset($reference_data['tag_bindings'])) { $tag_bindings = $reference_data['tag_bindings']; // I want keys in $available_tags to be progressive $available_tags = array_values(array_unique(array_values($tag_bindings))); } else {
/** * @dataProvider cleanStringDP */ public function testCleanString($a, $b) { $obj = new _Utils(); $this->string($obj->cleanString($a))->isEqualTo($b); }