Example #1
0
 protected function createComponentFormAddTranslation()
 {
     $form = new Form();
     $langs = Intl::getLocaleBundle()->getLocaleNames();
     $filtered = [];
     foreach ($langs as $locale => $name) {
         try {
             $lang = substr($locale, 0, -strlen(strrchr($locale, '_')));
             \Bazo\Translation\Langs::getPluralRule($lang);
             $filtered[$locale] = $name;
         } catch (\InvalidArgumentException $ex) {
         }
     }
     $form->addSelect('lang', 'Language', $filtered);
     $form->addSubmit('btnSubmit', 'Create');
     $form->onSuccess[] = callback($this, 'formAddTranslationSubmitted');
     return $form;
 }
Example #2
0
 public function importTemplate($data, \Project $project)
 {
     $translations = $project->getTranslations();
     if ($translations->count() === 0) {
         return 0;
     }
     $imported = 0;
     $singleTranslation = $this->prepareTranslationsArray(1);
     $translationsData = [];
     foreach ($translations as $translation) {
         $pluralsCount = Langs::getPluralsCount($translation->getLang());
         $translationsData[$translation->getLang()] = array('pluralsCount' => $pluralsCount, 'translations' => $this->prepareTranslationsArray($pluralsCount));
     }
     foreach ($translations as $translation) {
         $translationData = $translationsData[$translation->getLang()];
         foreach ($data['messages'] as $messageId => $messageData) {
             $project->addTemplateMessage($messageId, $messageData);
             $message = $this->prepareMessage($messageData, $translationData['translations'], $singleTranslation, $translationData['pluralsCount']);
             $added = $translation->addMessage($messageId, $message);
             if ($added) {
                 $this->dm->persist($message);
                 $imported++;
             }
         }
         $this->dm->persist($translation);
     }
     $this->dm->persist($project);
     $this->dm->flush();
     return $imported;
 }