Reset messages of a locale (all locale if no locale passed).
Remove custom messages and reload initial messages from matching
file in Lang directory.

@param string|null $locale

@return bool
963242
public function resetMessages($locale = null)
    {
        if ($locale === null) {
            $this->messages = [];

            return true;
        }

        foreach ($this->getDirectories() as $directory) {
            $directory = rtrim($directory, '\\/');
            if (file_exists($filename = "$directory/$locale.php")) {
                $this->messages[$locale] = require $filename;
                $this->addResource('array', $this->messages[$locale], $locale);

                return true;
            }
        }

        return false;
    }
591944
public function setLocale($locale)
    {
        if ($locale instanceof Locale) {
            $this->locale = $locale;
            return $this;
        }
        $this->locale = strtolower($locale);
        return $this;
    }
69694
public function setLocale($locale)
    {
        $locale = substr($locale, 0, 2);
        if (in_array($locale, $this->locales)) {
            $this->locale = $locale;
            return true;
        }
        return false;
    }
690270
protected function checkLocale($locale)
    {
        $languageFound = null;
        $language = strstr($locale, '_', true);

        foreach ($this->configuration['locales'] as $availableLocale) {
            // If locale matches, the exact matching was found.
            if ($availableLocale === $locale) {
                return $availableLocale;
            }

            // Check if language (without locale) matches.
            if ($language == $availableLocale) {
                $languageFound = $availableLocale;
            }
        }

        if ($languageFound) {
            return $languageFound;
        }

        return null;
    }
254118
public function setDefaultLocale($locale) {

		$this->defaultLocale = $locale;

		if (NULL === $this->locale) {
			$this->setPhpDefaultLocale($locale);
		}

	}
402149
public function resetForLocale(LocaleEntity $locale)
    {
        $this->createQueryBuilder('t')
            ->delete()
            ->where('t.locale = :locale')->setParameter('locale', $locale)
            ->getQuery()->execute();
    }
118918
public function translate($locale = null)
    {
        if (!$locale) {
            $locale = \localizer\locale()->id();
        } else {
            $locale = (int)$locale;
        }

        return $this->getTranslation($locale);
    }
85499
public function setLocale($locale)
    {
        $this->locale = LanguageNormalize::toLanguageTag($locale);

        $this->localises[$locale] = null;

        return $this;
    }
369208
public function switchLocale($locale)
    {
        if (in_array($locale, $this->config['locales'])) {
            app('session')->put('administrator_locale', $locale);
        }

        return redirect()->back();
    }
689831
public function setMessages($locale, $messages)
    {
        $this->loadMessagesFromFile($locale);
        $this->addResource('array', $messages, $locale);
        $this->messages[$locale] = array_merge(
            isset($this->messages[$locale]) ? $this->messages[$locale] : [],
            $messages
        );

        return $this;
    }
334704
public function setLocale(
        $locale = null
    ) {
        if (empty($locale)) {
            $locale = $this->getDefaultLocale();
        }

        if (empty($locale)) {
            // @todo warning or error
            return;
        }

        /* Conversion for Ubuntu and Mac local settings. */
        if (!setlocale(LC_MONETARY, $locale . '.utf8')) {
            if (!setlocale(LC_MONETARY, $locale . '.UTF-8')) {
                setlocale(LC_MONETARY, 'en_US.UTF-8');
            }
        }

        /* Conversion for Ubuntu and Mac local settings. */
        if (!setlocale(LC_NUMERIC, $locale . '.utf8')) {
            if (!setlocale(LC_NUMERIC, $locale . '.UTF-8')) {
                setlocale(LC_NUMERIC, 'en_US.UTF-8');
            }
        }

        /* Conversion for Ubuntu and Mac local settings. */
        if (!setlocale(LC_TIME, $locale . '.utf8')) {
            if (!setlocale(LC_TIME, $locale . '.UTF-8')) {
                setlocale(LC_TIME, 'en_US.UTF-8');
            }
        }

        \Locale::setDefault($locale);
    }
285015
public function deleteTranslation(string $locale)
    {
        $model = $this;

        $this->forgetAllTranslations($locale);
        $this->save();

        Event::fire(new ModelUpdate($model, 'Deleted', $locale));
    }
1234881
public function resetForLocaleTranslatables(LocaleEntity $locale, $translatables)
    {
        $this->resetForLocale($locale);
        $translatableIDs = [];
        if ($translatables) {
            if ($translatables instanceof TranslatableEntity) {
                $translatableIDs[] = $translatables->getID();
            } elseif (is_int($translatables)) {
                $translatableIDs[] = $translatables;
            } elseif (is_array($translatables)) {
                foreach ($translatables as $translatable) {
                    if ($translatable instanceof TranslatableEntity) {
                        $translatableIDs[] = $translatable->getID();
                    } elseif (is_int($translatable)) {
                        $translatableIDs[] = $translatable;
                    } else {
                        throw new UserMessageException(t('Invalid translatable string specified'));
                    }
                }
            }
        }
        if (empty($translatableIDs)) {
            throw new UserMessageException(t('Invalid translatable string specified'));
        }
        $this->getEntityManager()->getConnection()->executeQuery(
            '
                delete s.*
                from CommunityTranslationStats as s
                inner join CommunityTranslationTranslatablePlaces as p on s.packageVersion = p.packageVersion
                where s.locale = ?
                and (p.translatable = ' . implode(' or p.translatable = ', $translatableIDs) . ')
            ',
            [$locale->getID()]
        );
    }
859794
private function setLocale($locale)
    {
        $path = __DIR__ . DIRECTORY_SEPARATOR .
            'assets' . DIRECTORY_SEPARATOR .
            'php' . DIRECTORY_SEPARATOR .
            'locale' . DIRECTORY_SEPARATOR . $locale . '.php';

        if (!file_exists($path)) {
            $this->locale = 'en';
            $path = __DIR__ . DIRECTORY_SEPARATOR .
                'assets' . DIRECTORY_SEPARATOR .
                'php' . DIRECTORY_SEPARATOR .
                'locale' . DIRECTORY_SEPARATOR . $this->locale . '.php';
        }
        $this->data = require_once($path);
    }
86418
public function deleteTranslation($locale)
    {
        if ($this->hasTranslation($locale))
        {
            if ($deleted = $this->getTranslation($locale)->delete())
            {
                $this->load('translations');

                return true;
            }
        }

        return false;
    }
463908
public static function setDefaultLocale($locale)
		{

			static::$_defaultLocale = $locale;
			
			// Apply to PHP locale
			if (is_null(static::$_locale)) {
				$sysLocales = \ChickenWire\Application::getConfiguration()->systemLocales;
				if (array_key_exists($locale, $sysLocales)) {
					setlocale(LC_ALL, $sysLocales[$locale]);
				}				
			}
		}
656030
private function hasLocale(string $locale): bool
    {
        assert(empty($locale) === false);

        $result = in_array($locale, $this->getLocales());

        return $result;
    }