formatLocale.

@param string  $locale
@param Closure $callback

@throws \BadFunctionCallException

@return string
765605
public function formatLocale($locale = null, Closure $callback = null)
    {
        if (!class_exists('\NumberFormatter')) {
            throw new BadFunctionCallException('Class NumberFormatter not exists. Require ext-intl extension.');
        }

        $formatter = new \NumberFormatter($locale ?: static::getLocale(), \NumberFormatter::CURRENCY);

        if (is_callable($callback)) {
            $callback($formatter);
        }

        return $formatter->formatCurrency($this->getValue(), $this->currency->getCurrency());
    }
941920
public function setLocale($locale = null, $remember = false)
    {
        $this->_locale->setLocale($locale);
        $t = $this->getTranslator();
        if ($t->isAvailable($this->_locale))
            $t->setLocale($this->_locale);
        if ($remember) $this->_session->locale = $this->_locale->toString();
    }
797950
public function getLocalization($locale)
    {
        $dataCollection = $this->getLocalizations();
        $data = $dataCollection->get($locale);

        return $data;
    }
569527
public function setLocale($locale = null)
    {
        $locale = self::_prepareLocale($locale);

        if (isset(self::$_localeData[(string) $locale]) === false) {
            $region = substr((string) $locale, 0, 3);
            if (isset($region[2]) === true) {
                if (($region[2] === '_') or ($region[2] === '-')) {
                    $region = substr($region, 0, 2);
                }
            }

            if (isset(self::$_localeData[(string) $region]) === true) {
                $this->_locale = $region;
            } else {
                $this->_locale = 'root';
            }
        } else {
            $this->_locale = $locale;
        }
    }
777456
protected function parseLocale($locale)
	{
		if ( ! is_null($locale))
		{
			return array_filter(array($locale, $this->fallback));
		}
		else
		{
			return array_filter(array($this->locale, $this->fallback));
		}
	}
1249335
protected function setLocale($locale)
    {
        if (is_null($locale) || $locale === 'auto') {
            $locale = app()->getLocale();
        }

        $this->locale = $locale;

        return $this;
    }
239005
public function generateRewrittenUrl($locale)
    {
        if ($this->isNew()) {
            throw new \RuntimeException(sprintf('Object %s must be saved before generating url', $this->getRewrittenUrlViewName()));
        }
        // Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe

        $this->setLocale($locale);

        $generateEvent = new GenerateRewrittenUrlEvent($this, $locale);

        $this->dispatchEvent(TheliaEvents::GENERATE_REWRITTENURL, $generateEvent);

        if ($generateEvent->isRewritten()) {
            return $generateEvent->getUrl();
        }

        $title = $this->getTitle();

        if (null == $title) {
            throw new \RuntimeException('Impossible to create an url if title is null');
        }
        // Replace all weird characters with dashes
        $string = preg_replace('/[^\w\-~_\.]+/u', '-', $title);

        // Only allow one dash separator at a time (and make string lowercase)
        $cleanString = mb_strtolower(preg_replace('/--+/u', '-', $string), 'UTF-8');

        $urlFilePart = rtrim($cleanString, '.-~_') . ".html";

        try {
            $i=0;
            while (URL::getInstance()->resolve($urlFilePart)) {
                $i++;
                $urlFilePart = sprintf("%s-%d.html", $cleanString, $i);
            }
        } catch (UrlRewritingException $e) {
            $rewritingUrl = new RewritingUrl();
            $rewritingUrl->setUrl($urlFilePart)
                ->setView($this->getRewrittenUrlViewName())
                ->setViewId($this->getId())
                ->setViewLocale($locale)
                ->save()
            ;
        }

        return $urlFilePart;
    }
1095625
protected function normalizeLocale($key, $locale, $useFallback)
    {
        if (in_array($locale, $this->getTranslatedLocales($key)) || ! $useFallback)
            return $locale;

        return config('app.fallback_locale') ?: $locale;
    }
650461
public function locale($locale = null)
    {
        if ($locale) {
            $this->_locale = $locale;
        }
        if ($this->_locale) {
            return $this->_locale;
        }
        if (isset($this->_params['locale'])) {
            return $this->_params['locale'];
        }
    }
182272
public function getLocaleChain(Locale $locale)
    {
        $fallbackRule = $this->configuration->getFallbackRule();
        $localeChain = [(string)$locale => $locale];

        if ($fallbackRule['strict'] === true) {
            foreach ($fallbackRule['order'] as $localeIdentifier) {
                $localeChain[$localeIdentifier] = new Locale($localeIdentifier);
            }
        } else {
            $locale = $this->findBestMatchingLocale($locale);
            while ($locale !== null) {
                $localeChain[(string)$locale] = $locale;
                $locale = $this->getParentLocaleOf($locale);
            }
            foreach ($fallbackRule['order'] as $localeIdentifier) {
                $locale = new Locale($localeIdentifier);
                $locale = $this->findBestMatchingLocale($locale);
                while ($locale !== null) {
                    $localeChain[(string)$locale] = $locale;
                    $locale = $this->getParentLocaleOf($locale);
                }
            }
        }
        $locale = $this->configuration->getDefaultLocale();
        $localeChain[(string)$locale] = $locale;

        return $localeChain;
    }
185046
private function getFallbackLocale($locale = null)
    {
        if ($locale && $this->isLocaleCountryBased($locale)) {
            if ($fallback = $this->getLanguageFromCountryBasedLocale($locale)) {
                return $fallback;
            }
        }

        $locales = $this->getLocales();

        foreach ($locales as $code) {
            if ($this->getTranslationByLocaleKey($code) !== null)
                return $code;
        }

        return app()->make('config')->get('revy.translatable.fallback_locale');
    }
1308694
protected function getUrlLanguage($locale = null)
    {
        // Check if the functionality is activated
        if (!ConfigQuery::isMultiDomainActivated()) {
            return null;
        }

        // If we don't have a locale value, use the locale value in the session
        if (!$locale) {
            $locale = $this->getCurrentEditionLocale();
        }

        return LangQuery::create()->findOneByLocale($locale)->getUrl();
    }
1285288
protected function currentLocaleChanged($locale)
    {
        PunicData::setDefaultLocale($locale);
        $app = Facade::getFacadeApplication();
        if ($app->bound('director')) {
            $event = new \Symfony\Component\EventDispatcher\GenericEvent();
            $event->setArgument('locale', $locale);
            $app->make('director')->dispatch('on_locale_load', $event);
        }
    }
685444
public static function setLocale(string $locale, string $backup) : array {
		$result = [
			'locale_locales' => [],
			'locale_locale_js' => null,
			'locale_set_name' => null,
			'locale_options' => [],
			'locale_override_class' => null
		];
		$temp = $locale;
		$result['locale_locales'] = [];
		$result['locale_locales'][] = $temp;
		if (strpos($temp, '@') !== false) {
			$temp = explode('@', $temp);
			$temp = $temp[0];
			$result['locale_locales'][] = $temp;
		}
		if (strpos($temp, '.') !== false) {
			$temp = explode('.', $temp);
			$temp = $temp[0];
			$result['locale_locales'][] = $temp;
		}
		$result['locale_locale_js'] = str_replace('_', '-', $temp);
		$result['locale_set_name'] = setlocale(LC_ALL, $result['locale_locales']);
		// grab settings
		$result['locale_options'] = localeconv();
		// form a class name from locale name
		// todo: finilize locale
		$class = str_replace('-', '', $locale);
		$class = str_replace('.', '_', $class);
		$class = strtolower($class);
		// see if class exists
		$override_format_filename = __DIR__ . '/Object/Format/Locales/' . $class . '.php';
		if (file_exists($override_format_filename)) {
			require_once($override_format_filename);
			$class = 'object_format_locales_' . $class;
			$result['locale_override_class'] = $class;
			// grab overrides
			$result['locale_options'] = $class::localeconv($result['locale_options']);
			// if locale does not exists but we have override we simply accept it
			if (empty($result['locale_set_name'])) {
				$result['locale_set_name'] = $locale;
			}
		} else if (empty($result['locale_set_name']) && !empty($backup)) {
			$result = self::setLocale($backup, '');
		}
		return $result;
	}
406690
private function normalizeLocale(string $locale): string
    {
        return \preg_replace_callback('/^([a-z]{2})[-_]([a-z]{2})$/i', static function (array $matches): string {
            return \sprintf('%s_%s', $matches[1], \mb_strtoupper($matches[2]));
        }, $locale);
    }
186682
public function getUnitPriceFormatted($locale = null)
    {
        return $this->priceFormatter->format((float)$this->getUnitPrice(), null, $locale);
    }
250118
protected function getFormatter($locale) {
		if (! isset($this->formatters[$locale])) {
			$this->formatters[$locale] = new NumberFormatter($locale, NumberFormatter::CURRENCY);
		}
		
		return $this->formatters[$locale];
	}