/** * 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; }
namespace Stores; use Langchecker\Utils; $template = true; switch ($url['path']) { case '/': $controller = 'home'; break; case 'api/documentation': $controller = 'api_doc'; break; case Utils::StartsWith($url['path'], 'api'): $controller = 'api'; $template = false; break; case Utils::StartsWith($url['path'], 'locale'): $controller = 'locale'; break; default: $controller = 'home'; break; } if ($template) { ob_start(); include CONTROLLERS . $controller . '_controller.php'; $content = ob_get_contents(); ob_end_clean(); // display the page require_once TEMPLATES . 'html.php'; } else { include CONTROLLERS . $controller . '_controller.php';
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 {
public function testGetCliParam() { $obj = new _Utils(); $options = [1 => 'test']; // Missing string param $this->string($obj->getCliParam(2, $options))->isEqualTo(''); // Missing string param with fallback $this->string($obj->getCliParam(2, $options, 'foo'))->isEqualTo('foo'); // Existing param $this->string($obj->getCliParam(1, $options, 'foo'))->isEqualTo('test'); }