function it_translate_checkbox_state(TranslatorInterface $translator)
 {
     $translator->translate('yes', 'MSC')->shouldBeCalled();
     $this->format('1', 'test', [])->shouldReturn('ja');
     $translator->translate('no', 'MSC')->shouldBeCalled();
     $this->format('', 'test', [])->shouldReturn('nein');
 }
Exemple #2
0
 /**
  * Translate a string.
  *
  * @param string $name   The string to translate.
  * @param array  $params Translation params.
  * @param null   $domain Translation domain.
  *
  * @return mixed
  */
 public function translate($name, $params = array(), $domain = null)
 {
     if (!$domain) {
         $domain = $this->defaultDomain;
     }
     return $this->translator->translate($name, $domain, $params);
 }
 /**
  * Get edit map link wizard.
  *
  * @param \DataContainer $dataContainer The dataContainer driver.
  *
  * @return string
  */
 public function getEditMapLink($dataContainer)
 {
     if ($dataContainer->value < 1) {
         return '';
     }
     $pattern = 'title="%s" style="padding-left: 3px" onclick="Backend.openModalIframe(';
     $pattern .= '{\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"';
     return sprintf('<a href="%s%s&amp;popup=1&amp;rt=%s" %s>%s</a>', 'contao/main.php?do=leaflet_map&amp;table=tl_leaflet_map&amp;act=edit&amp;id=', $dataContainer->value, \RequestToken::get(), sprintf($pattern, specialchars($this->translator->translate('editalias.1', 'tl_content', [$dataContainer->value])), specialchars(str_replace("'", "\\'", sprintf($this->translator->translate('editalias.1', 'tl_content', [$dataContainer->value]))))), \Image::getHtml('alias.gif', $this->translator->translate('editalias.0', 'tl_content', [$dataContainer->value]), 'style="vertical-align:top"'));
 }
Exemple #4
0
 /**
  * Retrieve the label text for a condition setting or the default one.
  *
  * @param TranslatorInterface $translator The environment in use.
  *
  * @param string              $type       The type of the element.
  *
  * @return string
  */
 public function getLabelText(TranslatorInterface $translator, $type)
 {
     $label = $translator->translate('typedesc.' . $type, 'tl_metamodel_dcasetting_condition');
     if ($label == 'typedesc.' . $type) {
         $label = $translator->translate('typedesc._default_', 'tl_metamodel_dcasetting_condition');
         if ($label == 'typedesc._default_') {
             return $type;
         }
     }
     return $label;
 }
 /**
  * Translate an error collection.
  *
  * @param ErrorCollection $errorCollection The error collection to craeted.
  *
  * @return array
  */
 private function translateErrorCollection(ErrorCollection $errorCollection)
 {
     $errors = array();
     foreach ($errorCollection as $error) {
         list($message, $params, $collection) = $error;
         $message = $this->translator->translate($message, $this->domain, $params);
         if ($collection) {
             $collection = $this->translateErrorCollection($collection);
         }
         $errors[] = array($message, $collection);
     }
     return $errors;
 }
 /**
  * {@inheritdoc}
  */
 public function translatePluralized($string, $number, $domain = null, array $parameters = array(), $locale = null)
 {
     if ($this->translator) {
         return $this->translator->translatePluralized($string, $number, $domain, $parameters, $locale);
     }
     return $string;
 }
 /**
  * Add warning if the assets path is not set.
  *
  * @param mixed $value The value.
  *
  * @return mixed
  */
 public function addIncompleteWarning($value)
 {
     if ($value && !\Config::get('fv_assetPath')) {
         \Message::addError($this->translator->translate('fv_incompleteWarning', 'tl_form'));
     }
     return $value;
 }
 /**
  * Build the field sets.
  *
  * @param WidgetManager    $widgetManager  The widget manager in use.
  *
  * @param PaletteInterface $palette        The palette to use.
  *
  * @param PropertyValueBag $propertyValues The property values.
  *
  * @return array
  */
 private function buildFieldSet($widgetManager, $palette, $propertyValues)
 {
     $propertyDefinitions = $this->definition->getPropertiesDefinition();
     $isAutoSubmit = $this->environment->getInputProvider()->getValue('SUBMIT_TYPE') === 'auto';
     $fieldSets = [];
     $first = true;
     foreach ($palette->getLegends() as $legend) {
         $legendName = $this->translator->translate($legend->getName() . '_legend', $this->definition->getName());
         $fields = [];
         $hidden = [];
         $properties = $legend->getProperties($this->model, $propertyValues);
         if (!$properties) {
             continue;
         }
         foreach ($properties as $property) {
             $propertyName = $property->getName();
             $this->ensurePropertyExists($propertyName, $propertyDefinitions);
             // If this property is invalid, fetch the error.
             if (!$isAutoSubmit && $propertyValues && $propertyValues->hasPropertyValue($propertyName) && $propertyValues->isPropertyValueInvalid($propertyName)) {
                 $this->errors = array_merge($this->errors, $propertyValues->getPropertyValueErrors($propertyName));
             }
             $fields[] = $widgetManager->renderWidget($propertyName, $isAutoSubmit, $propertyValues);
             $hidden[] = sprintf('<input type="hidden" name="FORM_INPUTS[]" value="%s">', $propertyName);
         }
         $fieldSet['label'] = $legendName;
         $fieldSet['class'] = $first ? 'tl_tbox' : 'tl_box';
         $fieldSet['palette'] = implode('', $hidden) . implode('', $fields);
         $fieldSet['legend'] = $legend->getName();
         $fieldSets[] = $fieldSet;
         $first = false;
     }
     return $fieldSets;
 }
 /**
  * {@inheritDoc}
  */
 public function parse($raw, $tag, $params = null, $cache = true)
 {
     if ($params === null) {
         return '';
     }
     list($domain, $key) = explode(':', $params, 2);
     if ($key === null) {
         $key = $domain;
         $page = $this->getPage();
         if ($page) {
             $domain = 'page_';
             if ($page->alias) {
                 $domain .= str_replace('/', '_', $page->alias);
             } else {
                 $domain .= $page->id;
             }
         } else {
             $domain = 'website';
         }
     }
     $result = $this->translator->translate($key, $domain);
     // Fallback to global website domain.
     if ($domain !== 'website' && $result === $key) {
         $result = $this->translator->translate($key, 'website');
     }
     // Translator won't check if content is a string.
     if (is_array($result)) {
         return false;
     }
     return $this->replacer->replace($result, $cache);
 }
 /**
  * Assemble the format validator.
  *
  * @param Field           $field The validation field.
  * @param \FormFieldModel $model The field model.
  *
  * @return void
  */
 private function assembleCheckboxRequiredValidator(Field $field, \FormFieldModel $model)
 {
     if ($model->type === 'checkbox' && $model->mandatory) {
         if ($model->minlength > 0) {
             $options = array('min' => (int) $model->minlength);
             if ($model->maxlength > 0) {
                 $options['message'] = sprintf($this->translator->translate('ERR.between', null, [$model->label, $model->minlength, $model->maxlength]));
             } else {
                 $options['message'] = sprintf($this->translator->translate('ERR.minoption', null, [$model->label, $model->minlength]));
             }
         } else {
             $options = array('min' => 1);
             if ($model->maxlength > 0) {
                 $options['message'] = $this->translator->translate('ERR.maxoption', null, [$model->label, $model->maxlength]);
             } else {
                 $errorKey = $model->label ? 'ERR.mandatory' : 'ERR.mdtryNoLabel';
                 $options['message'] = $this->translator->translate($errorKey, null, [$model->label]);
             }
         }
         if ($model->maxlength > 0) {
             $options['max'] = (int) $model->maxlength;
         }
         $field->addValidator('choice', $options);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function generateHeaderFields(array $headerFields, ContentModel $model)
 {
     $label = $this->translator->translate('id.0', 'MSC');
     $headerFields[$label] = $model->id;
     foreach (array('type', 'invisible', 'start', 'stop') as $field) {
         $label = $this->translator->translate($field . '.0', 'tl_content');
         $headerFields[$label] = $this->translator->translate($model->{$field}, 'CTE');
     }
     return $headerFields;
 }
 /**
  * Get the paste buttons depending on the layer type.
  *
  * @param \DataContainer $dataContainer The dataContainer driver.
  * @param array          $row           The data row.
  * @param string         $table         The table name.
  * @param null           $whatever      Who knows what the purpose of this var is.
  * @param array          $children      The child content.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
 {
     $pasteAfterUrl = \Controller::addToUrl('act=' . $children['mode'] . '&amp;mode=1&amp;pid=' . $row['id'] . (!is_array($children['id']) ? '&amp;id=' . $children['id'] : ''));
     $buffer = sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $pasteAfterUrl, specialchars($this->translator->translate('pasteafter.1', $table, [$row['id']])), \Image::getHtml('pasteafter.gif', $this->translator->translate('pasteafter.1', $table, [$row['id']])));
     if (!empty($this->layers[$row['type']]['children'])) {
         $pasteIntoUrl = \Controller::addToUrl(sprintf('act=%s&amp;mode=2&amp;pid=%s%s', $children['mode'], $row['id'], !is_array($children['id']) ? '&amp;id=' . $children['id'] : ''));
         $buffer .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $pasteIntoUrl, specialchars($this->translator->translate('pasteinto.1', $table, [$row['id']])), \Image::getHtml('pasteinto.gif', $this->translator->translate('pasteinto.1', $table, [$row['id']])));
     } elseif ($row['id'] > 0) {
         $buffer .= \Image::getHtml('pasteinto_.gif');
     }
     return $buffer;
 }
 /**
  * Generate the move button.
  *
  * @param array $row The current row.
  *
  * @return string
  */
 private function generateMoveButton($row)
 {
     $clipboard = \Session::getInstance()->get('CLIPBOARD');
     $isClipboard = !empty($clipboard[$this->definition->getName()]);
     // Paste buttons
     if ($isClipboard) {
         $clipboard = $clipboard[$this->definition->getName()];
         if (\Input::get('mode') == 'cut' && $this->isChildOf($row, $clipboard['id'])) {
             return \Image::getHtml('pasteafter_.gif', $this->translator->translate('pasteafter.0', $this->definition->getName()));
         }
         $url = \Backend::addToUrl('act=' . $clipboard['mode'] . '&amp;mode=1&amp;pid=' . $row['id'] . '&amp;id=' . $clipboard['id']);
         return sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $url, specialchars(sprintf($this->translator->translate('pasteafter.1', $this->definition->getName()), $row['id'])), \Image::getHtml('pasteafter.gif', $this->translator->translate('pasteafter.0', $this->definition->getName())));
     }
     return '';
 }
 /**
  * Generate the form.
  *
  * @return array
  */
 private function generateForm()
 {
     $fields = array();
     // Loop over all attributes now.
     foreach ($this->metaModel->getAttributes() as $attribute) {
         $attrId = $attribute->get('id');
         if (!$this->accepts($attribute)) {
             continue;
         }
         if ($this->knowsAttribute($attribute)) {
             if ($this->input->hasValue('attribute_' . $attrId)) {
                 $fields[] = array('checkbox' => false, 'text' => $this->translator->translate('addAll_addsuccess', static::$table, array($attribute->getName())), 'class' => 'tl_confirm', 'attr_id' => $attrId);
                 continue;
             }
             $fields[] = array('checkbox' => false, 'text' => $this->translator->translate('addAll_alreadycontained', static::$table, array($attribute->getName())), 'class' => 'tl_info', 'attr_id' => $attrId);
             continue;
         }
         $fields[] = array('checkbox' => true, 'text' => $this->translator->translate('addAll_willadd', static::$table, array($attribute->getName())), 'class' => 'tl_new', 'attr_id' => $attrId);
         $this->template->hasCheckbox = true;
     }
     return $fields;
 }
 /**
  * {@inheritDoc}
  */
 public function format($value, $fieldName, array $fieldDefinition, $context = null)
 {
     return $this->translator->translate($value == '' ? 'no' : 'yes', 'MSC');
 }
Exemple #16
0
 /**
  * Translate a string via the translator.
  *
  * @param string $path The path within the translation where the string can be found.
  *
  * @return string
  */
 protected function translate($path)
 {
     $value = $this->translator->translate($path, $this->environment->getDataDefinition()->getName());
     if ($path !== $value) {
         return $value;
     }
     return $this->translator->translate($path);
 }
 /**
  * Format the grouping header for a checkbox option.
  *
  * @param mixed               $value      The given value.
  * @param TranslatorInterface $translator The translator.
  *
  * @return string
  */
 private function formatCheckboxOptionLabel($value, $translator)
 {
     return $value != '' ? ucfirst($translator->translate('yes', 'MSC')) : ucfirst($translator->translate('no', 'MSC'));
 }
 /**
  * Retrieve the label text for a filter setting.
  *
  * @param TranslatorInterface $translator The translator in use.
  *
  * @param ModelInterface      $model      The filter setting to render.
  *
  * @return mixed|string
  */
 protected function getLabelText(TranslatorInterface $translator, ModelInterface $model)
 {
     $type = $model->getProperty('type');
     $label = $translator->translate('typenames.' . $type, 'tl_metamodel_filtersetting');
     if ($label == 'typenames.' . $type) {
         return $type;
     }
     return $label;
 }
Exemple #19
0
 /**
  * Extract all languages from the MetaModel and return them as array.
  *
  * @param IMetaModel          $metaModel  The MetaModel to extract the languages from.
  *
  * @param TranslatorInterface $translator The translator to use.
  *
  * @return \string[]
  */
 private static function buildLanguageArray(IMetaModel $metaModel, TranslatorInterface $translator)
 {
     $languages = array();
     foreach ((array) $metaModel->getAvailableLanguages() as $langCode) {
         $languages[$langCode] = $translator->translate('LNG.' . $langCode, 'languages');
     }
     asort($languages);
     return $languages;
 }