/** * @Route("/add", name="ter_back_wording_add") * @Route("/add/domain/{code}", name="ter_back_wording_add_by_domain") * @Template() */ public function addAction($code = null) { $wording = new Wording(); if ($code) { $domain = $this->getDoctrine()->getRepository('TerTranslateBundle:Domain')->findOneByCode($code); if (!$domain) { throw new NotFoundHttpException('Domain is not found'); } else { $wording->setDomain($domain); } } $translate = $this->get('ter_translate.translate'); $form = $this->createForm(new WordingType($translate->getLocales(), $translate->getDefautLocale(), isset($domain) ? false : true), $wording); $form->handleRequest($this->get('request')); if ($form->isValid()) { $this->getDoctrine()->getManager()->persist($wording); $this->getDoctrine()->getManager()->flush(); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('flashmessage.save', [], 'TerAdminBundle')); /** On supprime le cache */ $this->get('ter.translation.cache')->clear(); $codeRedirect = $wording->getDomain()->getCode(); return $this->redirectToRoute("ter_back_wording_by_domain", array('code' => $codeRedirect)); } return array('form' => $form->createView()); }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Confirmez-vous l\'import des traductions ? (Y/N)</question>', false)) { return; } $translate = $this->getContainer()->get('ter_translate.translate'); foreach ($translate->getLocales() as $locale) { $messages = $this->getContainer()->get('translator')->getCatalogue($locale); foreach ($messages->all() as $domain => $values) { $repoDomain = $this->getContainer()->get('doctrine')->getRepository('TerTranslateBundle:Domain'); $addDomain = $repoDomain->findOneByCode($domain); if (!$addDomain) { $addDomain = new Domain(); $addDomain->setName('[BACK] Domain System - ' . $domain)->setCode($domain)->setDescription('Domain system import'); $this->getContainer()->get('doctrine')->getManager()->persist($addDomain); $output->writeln('<fg=green>Import du domaine ' . $domain . '</fg=green>'); } foreach ($values as $key => $value) { $wording = $this->getContainer()->get('doctrine')->getRepository('TerTranslateBundle:Wording')->findOneByCode($key); if (!$wording) { $wording = new Wording(); $wording->setCode($key); $wording->setDomain($addDomain); $output->writeln('<fg=blue>Import du wording ' . $key . '</fg=blue>'); } $wordingExists = $this->getContainer()->get('doctrine')->getRepository('TerTranslateBundle:WordingTranslation')->findOneBy(array('locale' => $locale, 'translatable' => $wording)); if (!$wordingExists) { $trans = (new WordingTranslation())->setLocale($locale)->setValue($value)->setTranslatable($wording); $wording->addTranslation($trans); $output->writeln('<fg=yellow>Import de la traduction [' . $locale . ' - ' . $key . ']</fg=yellow>'); } $this->getContainer()->get('doctrine')->getManager()->persist($wording); } } $this->getContainer()->get('doctrine')->getManager()->flush(); } }