Magento – Magento 2 – Where is the value of locale in Magento system

localemagento2

In Magento 2, Where is the value of locale in Magento system? Ex: from database or machine, or some place.

In file: Magento\Framework\Stdlib\DateTime\Timezone

/**
     * {@inheritdoc}
     */
    public function getDateFormat($type = \IntlDateFormatter::SHORT)
    {
        return (new \IntlDateFormatter(
            $this->_localeResolver->getLocale(),
            $type,
            \IntlDateFormatter::NONE
        ))->getPattern();
    }

focus this line: $this->_localeResolver->getLocale()

Best Answer

Locale stored in system config (table core_config_data):

data

By default the locale is set in the Magento\Framework\Locale\Resolver::getDefaultLocale():

public function getDefaultLocale()
{
    if (!$this->defaultLocale) {
        $locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
        if (!$locale) {
            $locale = self::DEFAULT_LOCALE;
        }
        $this->defaultLocale = $locale;
    }
    return $this->defaultLocale;
}

For receiving the current locale use Magento\Framework\Locale\Resolver::getLocale().