/** * Global translate function # 3 * This function performs print OR vprintf on a translated String * * @param string $key * @param array|null $args */ function __p(string $key, array $args = null) { $translated = Translator::getInstance()->translate($key); if (is_string($translated)) { if (is_array($args)) { vprintf($translated, $args); } else { print $translated; } } }
/** * Register Translator (i18n) Component * @param string $lang * @return Translator\Language */ protected function getCachedLanguage(string $lang) : Translator\Language { // Get cache Disk instance $cache = $this->disks->pull("cache"); // Cached language file $langFile = sprintf("bootstrap.lang_%s.php.cache", strtolower($lang)); try { $lang = unserialize($cache->read($langFile)); } catch (DiskException $e) { } // Got language? if (!isset($lang) || !$lang instanceof Translator\Language) { $lang = $this->translator->language($lang); // Write to cache $cache->write($langFile, serialize($lang), Disk::WRITE_FLOCK); } // Return Language instance return $lang; }