/** * @param JsonSerializationVisitor $visitor * @param Narrative $narrative * @param array $type * @param Context $context * @return array */ public function translateNarrative(JsonSerializationVisitor $visitor, Narrative $narrative, array $type, Context $context) { $messageData = $narrative->getMessages(); foreach ($messageData as $key => &$messages) { foreach ($messages as &$message) { $message = $this->translationService->trans($message, $narrative->getSubstitutions(), $key, 'en'); } } return $messageData; }
public function testTrans() { $trans = new Translator('en'); $trans->register(array('test' => 'test-en')); $trans->register(array('test2' => 'test2-en'), 'en'); $trans->register(array('test' => 'test-fr'), 'fr'); $this->assertEquals('en', $trans->getLang()); $this->assertEquals('test-en', $trans->trans('test')); $this->assertEquals('test2-en', $trans->trans('test2')); $this->assertEquals('test-fr', $trans->trans('test', array(), 'fr')); }
/** * Adds an action to the list of available . * * @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.action * @param array $action - can contain the following keys: * 'label' => (required) what to display in the list * 'description' => (optional) short description of event * 'template' => (optional) template to use for the action's HTML in the stage builder * i.e AcmeMyBundle:StageAction:theaction.html.php * 'formType' => (optional) name of the form type SERVICE for the action; will use a default form with stage change only * 'formTypeOptions' => (optional) array of options to pass to formType * 'callback' => (optional) callback function that will be passed when the action is triggered; return true to * change the configured stages or false to ignore the action * The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs()) * Mautic\CoreBundle\Factory\MauticFactory $factory * Mautic\LeadBundle\Entity\Lead $lead * $eventDetails - variable sent from firing function to call back function * array $action = array( * 'id' => int * 'type' => string * 'name' => string * 'properties' => array() * ) * * @return void * @throws InvalidArgumentException */ public function addAction($key, array $action) { if (array_key_exists($key, $this->actions)) { throw new InvalidArgumentException("The key, '{$key}' is already used by another action. Please use a different key."); } //check for required keys and that given functions are callable $this->verifyComponent(array('group', 'label'), array('callback'), $action); //translate the label and group $action['label'] = $this->translator->trans($action['label']); $action['group'] = $this->translator->trans($action['group']); $this->actions[$key] = $action; }
/** * Upload image and create entity * * @param UploadedFile $file * @param array $attributes * * @return Local */ public function upload(UploadedFile $file, array $attributes) { $filesystem = new Filesystem(); $imagine = new Imagine(); $errors = array(); $mimeType = $file->getClientMimeType(); if (!in_array($mimeType, $this->supportedTypes)) { $errors[] = $this->translator->trans('ads.error.unsupportedType', array('%type%' => $mimeType)); } if (!file_exists($this->config['image_path']) || !is_writable($this->config['image_path'])) { $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['image_dir'])); } if (!file_exists($this->config['thumbnail_path']) || !is_writable($this->config['thumbnail_path'])) { $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['thumbnail_dir'])); } if (!empty($errors)) { return $errors; } $attributes = array_merge(array('content_type' => $mimeType), $attributes); $image = new Image($file->getClientOriginalName()); $this->orm->persist($image); $this->fillImage($image, $attributes); $this->orm->flush(); $imagePath = $this->generateImagePath($image->getId(), $file->getClientOriginalExtension()); $thumbnailPath = $this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension()); $image->setBasename($this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true)); $image->setThumbnailPath($this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension(), true)); $this->orm->flush(); try { $file->move($this->config['image_path'], $this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true)); $filesystem->chmod($imagePath, 0644); $imagine->open($imagePath)->resize(new Box($this->config['thumbnail_max_size'], $this->config['thumbnail_max_size']))->save($thumbnailPath, array()); $filesystem->chmod($thumbnailPath, 0644); } catch (\Exceptiom $e) { $filesystem->remove($imagePath); $filesystem->remove($thumbnailPath); $this->orm->remove($image); $this->orm->flush(); return array($e->getMessage()); } return $image; }
/** * @param string[] $roles * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node * * @return array */ public function getCreatableTypes(array $roles, ResourceNode $node) { $creatableTypes = array(); $creationRights = $this->rightsRepo->findCreationRights($roles, $node); if (count($creationRights) !== 0) { foreach ($creationRights as $type) { $creatableTypes[$type['name']] = $this->translator->trans($type['name'], array(), 'resource'); } } return $creatableTypes; }
public function fetchData(adUser $adUser, TokenInterface $token, adLDAP $adLdap) { $connected = $adLdap->connect(); $isAD = $adLdap->authenticate($adUser->getUsername(), $token->getCredentials()); if (!$isAD || !$connected) { $msg = $this->translator->trans('ztec.security.active_directory.ad.bad_response', array('%connection_status%' => var_export($connected, 1), '%is_AD%' => var_export($isAD, 1))); throw new \Exception($msg); } /** @var adLDAPUserCollection $user */ $user = $adLdap->user()->infoCollection($adUser->getUsername()); //$userInfo = $adLdap->user_info($this->username); if ($user) { $groups = array(); //$allGroups = $adLdap->search_groups(ADLDAP_SECURITY_GLOBAL_GROUP,true); $groups = $adLdap->user()->groups($adUser->getUsername(), $this->recursiveGrouproles); /*if ($this->recursiveGrouproles == true) { // get recursive groups via adLdap $groups = $adLdap->user()->groups($adUser->getUsername(), true); } else { foreach ($user->memberOf as $k => $group) { if ($k !== 'count' && $group) { $reg = '#CN=([^,]*)#'; preg_match_all($reg, $group, $out); $groups[] = $out[1][0]; /* if(array_key_exists($out[1][0],$allGroups)){ $groups[$out[1][0]] = $allGroups[$out[1][0]]; }*/ /*} } }*/ /** End Fetching */ $sfRoles = array(); $sfRolesTemp = array(); foreach ($groups as $r) { if (in_array($r, $sfRolesTemp) === false) { $sfRoles[] = 'ROLE_' . strtoupper(str_replace(' ', '_', $r)); $sfRolesTemp[] = $r; } } $adUser->setRoles($sfRoles); unset($sfRolesTemp); $adUser->setDisplayName($user->displayName); $adUser->setEmail($user->mail); return true; } }
public function handleRequest(Request $request) { $translator = new Translator(@$_COOKIE['lang']); foreach ($this->fieldsMap as $field => $constraints) { /** @var Constraint $constraint */ foreach ($constraints as $constraint) { if (!$constraint->validate($request->getValue($field))) { $msg = $constraint->getMessage($data); $this->errors[$field][] = $translator->trans($msg, $data); } } } if ($this->isValid()) { $this->record->setFromData($request->getRequestData()); } else { $this->record = $request->getRequestData(); } return $this; }
/** * Register plugin permissions in Newscoop ACL. * * @param PluginPermissionsEvent $event */ public function registerPermissions(PluginPermissionsEvent $event) { $event->registerPermissions($this->translator->trans('aes.name'), array('plugin_editor_api' => $this->translator->trans('aes.permissions.api'), 'plugin_editor_permissions' => $this->translator->trans('aes.permissions.permissions'), 'plugin_editor_styles' => $this->translator->trans('aes.permissions.styles'))); }
/** * {@inheritdoc} */ public function trans($id, array $parameters = array(), $domain = null, $locale = null) { return sprintf($this->getStringFormat($id, $domain, $locale), parent::trans($id, $parameters, $domain, $locale)); }