/**
  * Checks if the given value is a valid DateTime object.
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @api
  */
 protected function isValid($value)
 {
     if ($value instanceof \DateTime) {
         return;
     }
     if (!isset($this->options['locale'])) {
         $locale = $this->localizationService->getConfiguration()->getDefaultLocale();
     } elseif (is_string($this->options['locale'])) {
         $locale = new \TYPO3\Flow\I18n\Locale($this->options['locale']);
     } elseif ($this->options['locale'] instanceof \TYPO3\Flow\I18n\Locale) {
         $locale = $this->options['locale'];
     } else {
         $this->addError('The "locale" option can be only set to string identifier, or Locale object.', 1281454676);
         return;
     }
     $strictMode = $this->options['strictMode'];
     $formatLength = $this->options['formatLength'];
     \TYPO3\Flow\I18n\Cldr\Reader\DatesReader::validateFormatLength($formatLength);
     $formatType = $this->options['formatType'];
     \TYPO3\Flow\I18n\Cldr\Reader\DatesReader::validateFormatType($formatType);
     if ($formatType === \TYPO3\Flow\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_TIME) {
         if ($this->datetimeParser->parseTime($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid time is expected.', 1281454830);
         }
     } elseif ($formatType === \TYPO3\Flow\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_DATETIME) {
         if ($this->datetimeParser->parseDateAndTime($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid date and time is expected.', 1281454831);
         }
     } else {
         if ($this->datetimeParser->parseDate($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid date is expected.', 1281454832);
         }
     }
 }
 /**
  * Checks if the given value is a valid number.
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @api
  * @todo Currency support should be added when it will be supported by NumberParser
  */
 protected function isValid($value)
 {
     if (!isset($this->options['locale'])) {
         $locale = $this->localizationService->getConfiguration()->getDefaultLocale();
     } elseif (is_string($this->options['locale'])) {
         $locale = new \TYPO3\Flow\I18n\Locale($this->options['locale']);
     } elseif ($this->options['locale'] instanceof \TYPO3\Flow\I18n\Locale) {
         $locale = $this->options['locale'];
     } else {
         $this->addError('The "locale" option can be only set to string identifier, or Locale object.', 1281286579);
         return;
     }
     $strictMode = $this->options['strictMode'];
     $formatLength = $this->options['formatLength'];
     \TYPO3\Flow\I18n\Cldr\Reader\NumbersReader::validateFormatLength($formatLength);
     $formatType = $this->options['formatType'];
     \TYPO3\Flow\I18n\Cldr\Reader\NumbersReader::validateFormatType($formatType);
     if ($formatType === \TYPO3\Flow\I18n\Cldr\Reader\NumbersReader::FORMAT_TYPE_PERCENT) {
         if ($this->numberParser->parsePercentNumber($value, $locale, $formatLength, $strictMode) === false) {
             $this->addError('A valid percent number is expected.', 1281452093);
         }
         return;
     } else {
         if ($this->numberParser->parseDecimalNumber($value, $locale, $formatLength, $strictMode) === false) {
             $this->addError('A valid decimal number is expected.', 1281452094);
         }
     }
 }
Esempio n. 3
0
 /**
  * Initializes some basic stuff that will basically be needed for each and
  * every action that is executed later on.
  */
 public function initializeAction()
 {
     // get the account of the authenticated user
     $this->account = $this->securityContext->getAccount();
     // set the locale
     $this->locale = $this->localeDetector->detectLocaleFromLocaleTag($this->settings['defaultLanguage']);
     if ($this->l18nService->getConfiguration()->getCurrentLocale() !== $this->locale) {
         $this->l18nService->getConfiguration()->setCurrentLocale($this->locale);
     }
 }
Esempio n. 4
0
 /**
  * Returns the localized name of a country or - if no localization was found - the country code
  *
  * @param $countryCode
  * @return string
  */
 public function getTerritoryNameForIsoCode($countryCode)
 {
     // get the localized country names from the CLDR data
     $i18nConfiguration = $this->i18nService->getConfiguration();
     $cldrModel = $this->cldrRepository->getModel('main/' . $i18nConfiguration->getCurrentLocale()->getLanguage());
     $countries = $cldrModel->findNodesWithinPath('localeDisplayNames/territories', 'territory');
     if (array_key_exists('territory[@type="' . strtoupper($countryCode) . '"]', $countries)) {
         return $countries['territory[@type="' . strtoupper($countryCode) . '"]'];
     } else {
         return $countryCode;
     }
 }
 /**
  * Translaterates UTF-8 string to ASCII. (北京 to 'Bei Jing')
  *
  * Accepts language parameter that maps to a configurable array of special transliteration rules if present.
  *
  * @param string $text Text to transliterate
  * @param string $language Optional language for specific rules (falls back to current locale if not provided)
  * @return string
  */
 public function transliterate($text, $language = null)
 {
     $language = $language ?: $this->localizationService->getConfiguration()->getCurrentLocale()->getLanguage();
     if (isset($this->transliterationRules[$language])) {
         // Apply special transliteration (not supported in library)
         $text = strtr($text, $this->transliterationRules[$language]);
     }
     // Transliterate (transform 北京 to 'Bei Jing')
     if (preg_match('/[\\x80-\\xff]/', $text) && Transliterator::validUtf8($text)) {
         $text = Transliterator::utf8ToAscii($text);
     }
     return $text;
 }
 /**
  * Replaces all placeholders in text with corresponding values.
  *
  * A placeholder is a group of elements separated with comma. First element
  * is required and defines index of value to insert (numeration starts from
  * 0, and is directly used to access element from $values array). Second
  * element is a name of formatter to use. It's optional, and if not given,
  * value will be simply string-casted. Remaining elements are formatter-
  * specific and they are directly passed to the formatter class.
  *
  * @param string $textWithPlaceholders String message with placeholder(s)
  * @param array $arguments An array of values to replace placeholders with
  * @param \TYPO3\Flow\I18n\Locale $locale Locale to use (NULL for default one)
  * @return string The $text with placeholders resolved
  * @throws \TYPO3\Flow\I18n\Exception\InvalidFormatPlaceholderException When encountered incorrectly formatted placeholder
  * @throws \TYPO3\Flow\I18n\Exception\IndexOutOfBoundsException When trying to format nonexistent value
  * @api
  */
 public function resolvePlaceholders($textWithPlaceholders, array $arguments, \TYPO3\Flow\I18n\Locale $locale = null)
 {
     if ($locale === null) {
         $locale = $this->localizationService->getConfiguration()->getDefaultLocale();
     }
     $lastPlaceHolderAt = 0;
     while ($lastPlaceHolderAt < strlen($textWithPlaceholders) && ($startOfPlaceholder = strpos($textWithPlaceholders, '{', $lastPlaceHolderAt)) !== false) {
         $endOfPlaceholder = strpos($textWithPlaceholders, '}', $lastPlaceHolderAt);
         $startOfNextPlaceholder = strpos($textWithPlaceholders, '{', $startOfPlaceholder + 1);
         if ($endOfPlaceholder === false || $startOfPlaceholder + 1 >= $endOfPlaceholder || $startOfNextPlaceholder !== false && $startOfNextPlaceholder < $endOfPlaceholder) {
             // There is no closing bracket, or it is placed before the opening bracket, or there is nothing between brackets
             throw new \TYPO3\Flow\I18n\Exception\InvalidFormatPlaceholderException('Text provided contains incorrectly formatted placeholders. Please make sure you conform the placeholder\'s syntax.', 1278057790);
         }
         $contentBetweenBrackets = substr($textWithPlaceholders, $startOfPlaceholder + 1, $endOfPlaceholder - $startOfPlaceholder - 1);
         $placeholderElements = explode(',', str_replace(' ', '', $contentBetweenBrackets));
         $valueIndex = $placeholderElements[0];
         if (!array_key_exists($valueIndex, $arguments)) {
             throw new \TYPO3\Flow\I18n\Exception\IndexOutOfBoundsException('Placeholder "' . $valueIndex . '" was not provided, make sure you provide values for every placeholder.', 1278057791);
         }
         if (isset($placeholderElements[1])) {
             $formatterName = $placeholderElements[1];
             $formatter = $this->getFormatter($formatterName);
             $formattedPlaceholder = $formatter->format($arguments[$valueIndex], $locale, array_slice($placeholderElements, 2));
         } else {
             // No formatter defined, just string-cast the value
             $formattedPlaceholder = (string) $arguments[$valueIndex];
         }
         $textWithPlaceholders = str_replace('{' . $contentBetweenBrackets . '}', $formattedPlaceholder, $textWithPlaceholders);
         $lastPlaceHolderAt = $startOfPlaceholder + strlen($formattedPlaceholder);
     }
     return $textWithPlaceholders;
 }
Esempio n. 7
0
 /**
  * Is called if authentication failed.
  *
  * @param AuthenticationRequiredException $exception The exception thrown while the authentication process
  * @return void
  */
 protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null)
 {
     $responseIdentifier = 0;
     /** @var TokenInterface $token */
     foreach ($this->authenticationManager->getTokens() as $token) {
         if ($token->getAuthenticationStatus() > $responseIdentifier) {
             $responseIdentifier = $token->getAuthenticationStatus();
         }
     }
     $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
     $package = $this->controllerContext->getRequest()->getControllerPackageKey();
     $this->view->assign('value', array('responseText' => $this->translator->translateById('authentication.response.' . $responseIdentifier, array(), NULL, $locale, 'Main', $package), 'responseIdentifier' => $responseIdentifier));
     if ($this->request->getHttpRequest()->getMethod() !== 'OPTIONS') {
         $this->response->setStatus(401);
     }
 }
 /**
  * Renders an RSS feed
  *
  * @return string
  */
 public function rssAction()
 {
     /** @var NodeInterface $blogDocumentNode */
     $rssDocumentNode = $this->request->getInternalArgument('__documentNode');
     if ($rssDocumentNode === NULL) {
         return 'Error: The Blog Post Plugin cannot determine the current document node. Please make sure to include this plugin only by inserting it into a page / document.';
     }
     $blogDocumentNode = $rssDocumentNode->getParent();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($this->request->getMainRequest());
     $uriBuilder->setCreateAbsoluteUri(TRUE);
     if ($this->settings['feed']['uri'] !== '') {
         $feedUri = $this->settings['feed']['uri'];
     } else {
         $uriBuilder->setFormat('xml');
         $feedUri = $uriBuilder->uriFor('show', array('node' => $rssDocumentNode), 'Frontend\\Node', 'TYPO3.Neos');
     }
     $channel = new Channel();
     $channel->setTitle($this->settings['feed']['title']);
     $channel->setDescription($this->settings['feed']['description']);
     $channel->setFeedUri($feedUri);
     $channel->setWebsiteUri($this->request->getHttpRequest()->getBaseUri());
     $channel->setLanguage((string) $this->i18nService->getConfiguration()->getCurrentLocale());
     foreach ($blogDocumentNode->getChildNodes('RobertLemke.Plugin.Blog:Post') as $postNode) {
         /* @var $postNode NodeInterface */
         $uriBuilder->setFormat('html');
         $postUri = $uriBuilder->uriFor('show', array('node' => $postNode), 'Frontend\\Node', 'TYPO3.Neos');
         $item = new Item();
         $item->setTitle($postNode->getProperty('title'));
         $item->setGuid($postNode->getIdentifier());
         // TODO: Remove this once all old node properties are migrated:
         $publicationDate = $postNode->getProperty('datePublished');
         if (is_string($publicationDate)) {
             $publicationDate = \DateTime::createFromFormat('Y-m-d', $publicationDate);
             $postNode->setProperty('datePublished', $publicationDate);
         }
         $item->setPublicationDate($postNode->getProperty('datePublished'));
         $item->setItemLink((string) $postUri);
         $item->setCommentsLink((string) $postUri . '#comments');
         // TODO: Remove this once all old node properties are migrated:
         $author = $postNode->getProperty('author');
         if ($author === NULL) {
             $author = 'Robert Lemke';
             $postNode->setProperty('author', $author);
         }
         $item->setCreator($author);
         #			$item->setCategories(array('test'));
         $description = $this->contentService->renderTeaser($postNode) . ' <a href="' . $postUri . '">Read more</a>';
         $item->setDescription($description);
         $channel->addItem($item);
     }
     // This won't work yet (plugin sub responses can't set headers yet) but keep that as a reminder:
     $headers = $this->response->getHeaders();
     $headers->setCacheControlDirective('s-max-age', 3600);
     $headers->set('Content-Type', 'application/rss+xml');
     $feed = new Feed();
     $feed->addChannel($channel);
     return $feed->render();
 }
 /**
  * Returns best-matching Locale object based on the template Locale object
  * provided as parameter. System default locale will be returned if no
  * successful matches were done.
  *
  * @param \TYPO3\Flow\I18n\Locale $locale The template Locale object
  * @return \TYPO3\Flow\I18n\Locale Best-matching existing Locale instance
  * @api
  */
 public function detectLocaleFromTemplateLocale(\TYPO3\Flow\I18n\Locale $locale)
 {
     $bestMatchingLocale = $this->localeCollection->findBestMatchingLocale($locale);
     if ($bestMatchingLocale !== null) {
         return $bestMatchingLocale;
     }
     return $this->localizationService->getConfiguration()->getDefaultLocale();
 }
 /**
  * Check if a form has a localized version and deliver it if available
  *
  * @param $formName
  * @param $localeOverride
  * @return string
  */
 public function getFormNameRespectingLocale($formName, $localeOverride = '')
 {
     // if we override the locale anyway (and it isn't english), we return early
     if (!empty($localeOverride) && $localeOverride !== 'en') {
         return $formName . ucfirst($localeOverride);
     }
     $currentLanguage = $this->i18nService->getConfiguration()->getCurrentLocale()->getLanguage();
     /*
      * a localized version has the language iso code as uppercased suffix, e.g. dataSheetFormFr
      * english is the default language and has no suffix, therefore we return the unchanged name if
      * no translation was found
      */
     if ($this->formPersistenceManager->exists($formName . ucfirst($currentLanguage))) {
         $formName = $formName . ucfirst($currentLanguage);
     }
     return $formName;
 }
 /**
  * Override this method in your custom FormElements if needed
  *
  * @return void
  */
 public function initializeFormElement()
 {
     // the not localized country codes and names
     $selectOptions = $this->getProperties()['options'];
     // get the localized country names from the CLDR data
     $i18nConfiguration = $this->i18nService->getConfiguration();
     $cldrModel = $this->cldrRepository->getModel('main/' . $i18nConfiguration->getCurrentLocale()->getLanguage());
     $countries = $cldrModel->findNodesWithinPath('localeDisplayNames/territories', 'territory');
     // if the country is found in the CLDR data, use the localized name
     $localizedSelectOptions = array();
     foreach ($selectOptions as $countryCode => $countryName) {
         if (array_key_exists('territory[@type="' . strtoupper($countryCode) . '"]', $countries)) {
             $localizedSelectOptions[$countryCode] = $countries['territory[@type="' . strtoupper($countryCode) . '"]'];
         } else {
             $localizedSelectOptions[$countryCode] = $countryName;
         }
     }
     $this->setProperty('options', $localizedSelectOptions);
 }
 /**
  * Get the locale to use for all locale specific functionality.
  *
  * @throws InvalidVariableException
  * @return I18n\Locale The locale to use or NULL if locale should not be used
  */
 protected function getLocale()
 {
     if (!$this->hasArgument('forceLocale')) {
         return null;
     }
     $forceLocale = $this->arguments['forceLocale'];
     $useLocale = null;
     if ($forceLocale instanceof I18n\Locale) {
         $useLocale = $forceLocale;
     } elseif (is_string($forceLocale)) {
         try {
             $useLocale = new I18n\Locale($forceLocale);
         } catch (I18n\Exception $exception) {
             throw new InvalidVariableException('"' . $forceLocale . '" is not a valid locale identifier.', 1342610148, $exception);
         }
     } elseif ($forceLocale === true) {
         $useLocale = $this->localizationService->getConfiguration()->getCurrentLocale();
     }
     return $useLocale;
 }
 /**
  * Renders the view
  *
  * @return string The rendered view
  * @throws \Exception if no node is given
  * @api
  */
 public function render()
 {
     $currentNode = $this->getCurrentNode();
     $currentSiteNode = $currentNode->getContext()->getCurrentSiteNode();
     $typoScriptRuntime = $this->getTypoScriptRuntime($currentSiteNode);
     $dimensions = $currentNode->getContext()->getDimensions();
     if (array_key_exists('language', $dimensions) && $dimensions['language'] !== array()) {
         $currentLocale = new Locale($dimensions['language'][0]);
         $this->i18nService->getConfiguration()->setCurrentLocale($currentLocale);
         $this->i18nService->getConfiguration()->setFallbackRule(array('strict' => false, 'order' => array_reverse($dimensions['language'])));
     }
     $typoScriptRuntime->pushContextArray(array('node' => $currentNode, 'documentNode' => $this->getClosestDocumentNode($currentNode) ?: $currentNode, 'site' => $currentSiteNode, 'editPreviewMode' => isset($this->variables['editPreviewMode']) ? $this->variables['editPreviewMode'] : null));
     try {
         $output = $typoScriptRuntime->render($this->typoScriptPath);
         $output = $this->mergeHttpResponseFromOutput($output, $typoScriptRuntime);
     } catch (RuntimeException $exception) {
         throw $exception->getPrevious();
     }
     $typoScriptRuntime->popContext();
     return $output;
 }
 /**
  * Returns translated $stringToTranslate from a file defined by $sourceName using the function $functionName of the XliffModel.
  *
  * Chooses particular form of label if available and defined in $pluralForm.
  *
  * @param string $functionName The name of the function in the XliffModel to get the translation from
  * @param string $stringToTranslate String passed to function in order to find translation
  * @param \TYPO3\Flow\I18n\Locale $locale Locale to use
  * @param float|int|null $quantity A number to find plural form for (float or int), NULL to not use plural forms
  * @param string $sourceName A relative path to the filename with translations (labels' catalog)
  * @param string $packageKey Key of the package containing the source file
  * @return mixed Translated label or FALSE on failure
  * @throws \TYPO3\Flow\I18n\TranslationProvider\Exception\InvalidPluralFormException
  */
 protected function getTranslationByFunction($functionName, $stringToTranslate, \TYPO3\Flow\I18n\Locale $locale = null, $quantity = null, $sourceName = 'Main', $packageKey = 'TYPO3.Flow')
 {
     if ($locale === null) {
         $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
     }
     $translation = false;
     foreach ($this->localizationService->getLocaleChain($locale) as $localeInChain) {
         $model = $this->getModel($packageKey, $sourceName, $localeInChain);
         if ($quantity !== null) {
             $pluralFormsForProvidedLocale = $this->pluralsReader->getPluralForms($localeInChain);
             $pluralForm = $this->pluralsReader->getPluralForm($quantity, $localeInChain);
             // We need to convert plural form's string to index, as they are accessed using integers in XLIFF files
             $pluralFormIndex = (int) array_search($pluralForm, $pluralFormsForProvidedLocale);
         } else {
             $pluralFormIndex = 0;
         }
         //if we find a valid translation, we don't have to search in the remaining locale chain
         if (($translation = $model->{$functionName}($stringToTranslate, $pluralFormIndex)) !== false) {
             break;
         }
     }
     return $translation;
 }
 /**
  * Returns translated string found under the $labelId.
  *
  * Searches for a translation in the source as defined by $sourceName
  * (interpretation depends on concrete translation provider used).
  *
  * If any arguments are provided in the $arguments array, they will be inserted
  * to the translated string (in place of corresponding placeholders, with
  * format defined by these placeholders).
  *
  * If $quantity is provided, correct plural form for provided $locale will
  * be chosen and used to choose correct translation variant.
  *
  * @param string $labelId Key to use for finding translation
  * @param array $arguments An array of values to replace placeholders with
  * @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms
  * @param \TYPO3\Flow\I18n\Locale $locale Locale to use (NULL for default one)
  * @param string $sourceName Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/
  * @param string $packageKey Key of the package containing the source file
  * @return string Translated message or $labelId on failure
  * @api
  * @see \TYPO3\Flow\I18n\Translator::translateByOriginalLabel()
  */
 public function translateById($labelId, array $arguments = array(), $quantity = null, \TYPO3\Flow\I18n\Locale $locale = null, $sourceName = 'Main', $packageKey = 'TYPO3.Flow')
 {
     if ($locale === null) {
         $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
     }
     $pluralForm = $this->getPluralForm($quantity, $locale);
     $translatedMessage = $this->translationProvider->getTranslationById($labelId, $locale, $pluralForm, $sourceName, $packageKey);
     if ($translatedMessage === false) {
         return $labelId;
     } elseif (!empty($arguments)) {
         return $this->formatResolver->resolvePlaceholders($translatedMessage, $arguments, $locale);
     }
     return $translatedMessage;
 }
 /**
  * @param mixed $stringToFormat
  * @param mixed $locale string or boolean or \TYPO3\Flow\I18n\Locale
  * @param string $currencySign
  *
  * @throws \TYPO3\Fluid\Core\ViewHelper\Exception\InvalidVariableException
  * @return string
  */
 protected function renderUsingLocale($stringToFormat, $locale, $currencySign)
 {
     if ($locale instanceof I18n\Locale) {
         $useLocale = $locale;
     } elseif (is_string($locale)) {
         try {
             $useLocale = new I18n\Locale($locale);
         } catch (I18n\Exception $exception) {
             throw new InvalidVariableException('"' . $locale . '" is not a valid locale identifier.', 1342610148, $exception);
         }
     } else {
         $useLocale = $this->localizationService->getConfiguration()->getCurrentLocale();
     }
     return $this->numberFormatter->formatCurrencyNumber($stringToFormat, $useLocale, $currencySign);
 }
Esempio n. 17
0
 /**
  * @return \TYPO3\Flow\I18n\Locale
  */
 public function getLocale()
 {
     return $this->i18nService->getConfiguration()->getCurrentLocale();
 }
 /**
  * Set the locale according to the user settings
  *
  * @return void
  */
 protected function initializeObject()
 {
     $this->_localizationService->getConfiguration()->setCurrentLocale(new \TYPO3\Flow\I18n\Locale($this->_userService->getInterfaceLanguage()));
 }
 /**
  * @param \DateTime $dateTime
  * @param mixed $locale string or boolean or \TYPO3\Flow\I18n\Locale
  * @param array $formatConfiguration The format configuration to use, index 0 is the type, index 1 is the format length
  *
  * @throws \TYPO3\Fluid\Core\ViewHelper\Exception\InvalidVariableException
  * @throws \TYPO3\Fluid\Core\ViewHelper\Exception
  * @return string
  */
 protected function renderUsingLocale(\DateTime $dateTime, $locale, array $formatConfiguration)
 {
     if ($locale instanceof I18n\Locale) {
         $useLocale = $locale;
     } elseif (is_string($locale)) {
         try {
             $useLocale = new I18n\Locale($locale);
         } catch (I18n\Exception $exception) {
             throw new ViewHelper\Exception\InvalidVariableException('"' . $locale . '" is not a valid locale identifier.', 1342610148, $exception);
         }
     } else {
         $useLocale = $this->localizationService->getConfiguration()->getCurrentLocale();
     }
     try {
         $return = $this->formatter->format($dateTime, $useLocale, $formatConfiguration);
     } catch (I18n\Exception $exception) {
         throw new ViewHelper\Exception(sprintf('An error occurred while trying to format the given date/time: "%s"', $exception->getMessage()), 1342610987, $exception);
     }
     return $return;
 }
Esempio n. 20
0
 /**
  * @return string
  */
 public function getNameByForCurrentLocale()
 {
     $locale = $this->i18nService->getConfiguration()->getCurrentLocale();
     return $this->getNameForLocale($locale);
 }
Esempio n. 21
0
 /**
  * Tries to parse the input using the NumberParser.
  *
  * @param string $source
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
  * @return float|\TYPO3\Flow\Validation\Error Parsed float number or error
  * @throws \TYPO3\Flow\Property\Exception\InvalidPropertyMappingConfigurationException
  */
 protected function parseUsingLocaleIfConfigured($source, \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration)
 {
     $configuration = $this->getConfigurationKeysAndValues($configuration, array('locale', 'strictMode', 'formatLength', 'formatType'));
     if ($configuration['locale'] === NULL) {
         return $source;
     } elseif ($configuration['locale'] === TRUE) {
         $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
     } elseif (is_string($configuration['locale'])) {
         $locale = new \TYPO3\Flow\I18n\Locale($configuration['locale']);
     } elseif ($configuration['locale'] instanceof \TYPO3\Flow\I18n\Locale) {
         $locale = $configuration['locale'];
     }
     if (!$locale instanceof \TYPO3\Flow\I18n\Locale) {
         $exceptionMessage = 'Determined locale is not of type "\\TYPO3\\Flow\\I18n\\Locale", but of type "' . (is_object($locale) ? get_class($locale) : gettype($locale)) . '".';
         throw new InvalidPropertyMappingConfigurationException($exceptionMessage, 1334837413);
     }
     if ($configuration['strictMode'] === NULL || $configuration['strictMode'] === TRUE) {
         $strictMode = TRUE;
     } else {
         $strictMode = FALSE;
     }
     if ($configuration['formatLength'] !== NULL) {
         $formatLength = $configuration['formatLength'];
         NumbersReader::validateFormatLength($formatLength);
     } else {
         $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT;
     }
     if ($configuration['formatType'] !== NULL) {
         $formatType = $configuration['formatType'];
         \TYPO3\Flow\I18n\Cldr\Reader\NumbersReader::validateFormatType($formatType);
     } else {
         $formatType = NumbersReader::FORMAT_TYPE_DECIMAL;
     }
     if ($formatType === NumbersReader::FORMAT_TYPE_PERCENT) {
         $return = $this->numberParser->parsePercentNumber($source, $locale, $formatLength, $strictMode);
         if ($return === FALSE) {
             $return = new Error('A valid percent number is expected.', 1334839253);
         }
     } else {
         $return = $this->numberParser->parseDecimalNumber($source, $locale, $formatLength, $strictMode);
         if ($return === FALSE) {
             $return = new Error('A valid decimal number is expected.', 1334839260);
         }
     }
     return $return;
 }