/** * @param Message $message * * @return array */ protected function getProject(Message $message) { if (isset($this->projects[$message->getDomain()])) { return $this->projects[$message->getDomain()]; } // Return the first project that has the correct domain and locale foreach ($this->projects as $project) { if (in_array($message->getDomain(), $project['domains'])) { if (in_array($project['locales'], $message->getLocale())) { return $project; } } } }
/** * @param Request $request * @param string $token * * @return Message */ protected function getMessage(Request $request, $token) { $profiler = $this->get('profiler'); $profiler->disable(); $messageId = $request->request->get('message_id', $request->query->get('message_id')); $profile = $profiler->loadProfile($token); $messages = $profile->getCollector('translation')->getMessages(); if (!isset($messages[$messageId])) { throw $this->createNotFoundException(sprintf('No message with key "%s" was found.', $messageId)); } $message = new Message($messages[$messageId]); if ($message->getState() === DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK) { $message->setLocale($profile->getCollector('request')->getLocale())->setTranslation(sprintf('[%s]', $message->getTranslation())); } return $message; }