/** * @return array */ public function getStats() { $stats = array(); $countByDomains = $this->storage->getCountTransUnitByDomains(); foreach ($countByDomains as $domain => $total) { $stats[$domain] = array(); $byLocale = $this->storage->getCountTranslationByLocales($domain); foreach ($this->localeManager->getLocales() as $locale) { $localeCount = isset($byLocale[$locale]) ? $byLocale[$locale] : 0; $stats[$domain][$locale] = array('keys' => $total, 'translated' => $localeCount, 'completed' => $total > 0 ? floor($localeCount / $total * 100) : 0); } } return $stats; }
/** * Updates a trans unit from the request. * * @param integer $id * @param Request $request * @throws NotFoundHttpException * @return \Lexik\Bundle\TranslationBundle\Model\TransUnit */ public function updateFromRequest($id, Request $request) { $transUnit = $this->storage->getTransUnitById($id); if (!$transUnit) { throw new NotFoundHttpException(sprintf('No TransUnit found for "%s"', $id)); } $translationsContent = array(); foreach ($this->localeManager->getLocales() as $locale) { $translationsContent[$locale] = $request->request->get($locale); } $this->transUnitManager->updateTranslationsContent($transUnit, $translationsContent); if ($transUnit instanceof TransUnitDocument) { $transUnit->convertMongoTimestamp(); } $this->storage->flush(); return $transUnit; }
/** * Format a single TransUnit. * * @param array $transUnit * @return array */ protected function formatOne($transUnit) { if (is_object($transUnit)) { $transUnit = $this->toArray($transUnit); } elseif (StorageInterface::STORAGE_MONGODB == $this->storage) { $transUnit['id'] = $transUnit['_id']->{'$id'}; } $formatted = array('_id' => $transUnit['id'], '_domain' => $transUnit['domain'], '_key' => $transUnit['key']); // add locales in the same order as in managed_locales param foreach ($this->localeManager->getLocales() as $locale) { $formatted[$locale] = ''; } // then fill locales value foreach ($transUnit['translations'] as $translation) { if (in_array($translation['locale'], $this->localeManager->getLocales())) { $formatted[$translation['locale']] = $translation['content']; } } return $formatted; }
/** * {@inheritdoc} */ public function createFormData() { return $this->transUnitManager->newInstance($this->localeManager->getLocales()); }