/** * @Route("/inline-edit", name="KunstmaanTranslatorBundle_settings_translations_inline_edit") * @Method({"POST"}) */ public function inlineEditAction(Request $request) { $values = $request->request->all(); $adminListConfigurator = $this->getAdminListConfigurator(); if (!$adminListConfigurator->canEditInline($values)) { throw new AccessDeniedHttpException("Not allowed to edit this translation"); } $id = isset($values['pk']) ? (int) $values['pk'] : 0; $em = $this->getDoctrine()->getManager(); /** * @var Translator $translator */ $translator = $this->get('translator'); try { if ($id !== 0) { // Find existing translation $translation = $em->getRepository('KunstmaanTranslatorBundle:Translation')->find($id); if (is_null($translation)) { return new Response($translator->trans('translator.translator.invalid_translation'), 500); } } else { // Create new translation $translation = new Translation(); $translation->setDomain($values['domain']); $translation->setKeyword($values['keyword']); $translation->setLocale($values['locale']); $translation->setTranslationId($values['translationId']); } $translation->setText($values['value']); $em->persist($translation); $em->flush(); return new JsonResponse(array('success' => true, 'uid' => $translation->getId()), 200); } catch (\Exception $e) { return new Response($translator->trans('translator.translator.fatal_error_occurred'), 500); } }
public function profileTranslation($id, $parameters, $domain, $locale, $trans) { if ($this->container->getParameter('kuma_translator.profiler') === false) { return; } if ($locale === null) { $locale = $this->container->get('request')->get('_locale'); } $translation = new Translation(); $translation->setKeyword($id); $translation->setDomain($domain); $translation->setLocale($locale); $translation->setText($trans); $translationCollection = $this->container->get('request')->request->get('usedTranslations'); if (!$translationCollection instanceof \Doctrine\Common\Collections\ArrayCollection) { $translationCollection = new ArrayCollection(); } $translationCollection->set($domain . $id . $locale, $translation); $this->container->get('request')->request->set('usedTranslations', $translationCollection); }