private function translate_or_empty(ITranslator $translator, $formdata, $key) { if ($translator == null || !is_array($formdata)) { return ""; } return array_key_exists($key, $formdata) ? $translator->get($formdata[$key]) : ""; }
public function translate($message, $count = NULL, $parameters = array(), $domain = NULL, $locale = NULL) { if (is_array($count)) { $locale = $domain ?: NULL; $domain = $parameters ?: NULL; $parameters = $count ?: array(); $count = NULL; } return $this->translator->translate($message, $count, (array) $parameters, $domain, $locale); }
/** * @param \Nette\DI\IContainer */ protected function processRequests(\Nette\DI\IContainer $container) { $this->updating(); $httpRequest = $container->httpRequest; $httpResponse = $container->httpResponse; if ($httpRequest->getHeader(self::XHR_HEADER, FALSE)) { $data = FALSE; $this->translator->setLang($httpRequest->getPost('lang')); switch($httpRequest->getPost('action')) { case 'get': break; case 'extract': $this->extractor->run(); break; case 'save': $data = $httpRequest->getPost('data', ""); break; } $dictionaries = $this->getDictionaries($data); $response = new \Nette\Application\Responses\JsonResponse(array( 'status' => "OK", 'lang' => $this->translator->dictionaries, 'data' => $dictionaries, )); $response->send($httpRequest, $httpResponse); exit(255); } $this->freeze(); }
/** * Return the translated passed string * @param string $sentence * @return string|string */ public function _($sentence) { if ($this->translator != null && $this->translator instanceof ITranslator) { return $this->translator->_($sentence); } return $sentence; }
/** * Return the translated sentence * @param string $sentence * @return string */ public function _($sentence) { if ($this->translator === null) { return $sentence; } return $this->translator->_($sentence); }
/** * Init the translator of the application. * @param $locale Locale to use for the translator */ private static function initTranslator($locale) { $translatorClassName = Config::getInstance()->getString('properties/translator', 'I18nUtil'); if (class_exists($translatorClassName)) { $translator = new $translatorClassName(); if ($translator instanceof ITranslator) { self::$translator = $translator; self::$translator->setLocale(self::getSupportedLocale($locale)); } else { throw new ConfigurationException("The properties/translator configuration class does not implement ITranslator interface."); } } else { throw new ConfigurationException("The properties/translator configuration parameter is invalid."); } }