コード例 #1
0
 public function onRegistration(BundleTranslationsEvent $event)
 {
     $bundleAlias = $event->getBundleAlias();
     $bundle = $this->kernel->getBundle($bundleAlias);
     $bundleNamespace = $bundle->getNamespace();
     $bundlePath = $bundle->getPath();
     if (!is_dir("{$bundlePath}/Api")) {
         return;
     }
     $classes = $this->classCollector->collect("{$bundlePath}/Api", false, false);
     foreach ($classes as $class) {
         $classRefl = new ReflectionClass($class);
         $fileLocation = "@" . str_replace($bundlePath, $bundleAlias, $classRefl->getFileName());
         $traitProps = $this->getTraitProperties($classRefl);
         foreach ($classRefl->getProperties() as $propRefl) {
             if ($propRefl->class !== $class || array_key_exists($propRefl->name, $traitProps)) {
                 continue;
             }
             $name = $this->annotationReader->getPropertyAnnotation($propRefl, "Agit\\ApiBundle\\Annotation\\Property\\Name");
             if (!$name) {
                 continue;
             }
             $translation = new Translation($name->get("context"), $name->get("value"));
             $translation->addReference($fileLocation);
             $event->addTranslation($translation);
             $names[] = $name->get("value");
         }
     }
 }
コード例 #2
0
 public function onRegistration(BundleTranslationsEvent $event)
 {
     $defaultLocale = $this->localeService->getDefaultLocale();
     $availableLocales = $this->localeService->getAvailableLocales();
     $lists = ["month" => $this->timeAdapter->getMonths($defaultLocale, $availableLocales), "weekday" => $this->timeAdapter->getWeekdays($defaultLocale, $availableLocales)];
     foreach ($availableLocales as $locale) {
         foreach ($lists as $type => $list) {
             foreach ($list as $id => $elem) {
                 $longTrans = new Translation("", $elem->getName($defaultLocale));
                 $longTrans->setTranslation($elem->getName($locale));
                 $longTrans->addReference("localedata:{$type}");
                 $event->addTranslation($locale, $longTrans);
                 $abbrTrans = new Translation("", $elem->getAbbr($defaultLocale));
                 $abbrTrans->setTranslation($elem->getAbbr($locale));
                 $abbrTrans->addReference("localedata:{$type}:{$id}");
                 $event->addTranslation($locale, $abbrTrans);
             }
         }
     }
 }