Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set locale in fallback_locale and timezone on config/app.php #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/Mcamara/LaravelLocalization/LaravelLocalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function setLocale($locale = null)

// If the locale is determined by env, use that
// Note that this is how per-locale route caching is performed.
if ( ! $locale) {
if (! $locale) {
$locale = $this->getForcedLocale();
}
}
Expand Down Expand Up @@ -175,6 +175,13 @@ public function setLocale($locale = null)

$this->app->setLocale($this->currentLocale);

// Set locale in fallback_locale on config/app.php
config(['app.fallback_locale' => $this->currentLocale]);

// set locale in timezone on config/app.php
$timezone = config('laravellocalization.supportedLocales.' . $this->currentLocale . '.timezone', 'UTC');
config(['app.timezone' => $timezone]);

// Regional locale such as de_DE, so formatLocalized works in Carbon
$regional = $this->getCurrentLocaleRegional();
$suffix = $this->configRepository->get('laravellocalization.utf8suffix');
Expand Down Expand Up @@ -283,7 +290,7 @@ public function getLocalizedURL($locale = null, $url = null, $attributes = [], $
return $this->getURLFromRouteNameTranslated($locale, $translatedRoute, $attributes, $forceDefaultLocation);
}

if (!empty($locale)) {
if (!empty($locale)) {
if ($forceDefaultLocation || $locale != $this->getDefaultLocale() || !$this->hideDefaultLocaleInURL()) {
$parsed_url['path'] = $locale.'/'.ltrim($parsed_url['path'], '/');
}
Expand Down Expand Up @@ -558,7 +565,7 @@ public function checkLocaleInSupportedLocales($locale)
protected function substituteAttributesInRoute($attributes, $route)
{
foreach ($attributes as $key => $value) {
if ($value instanceOf UrlRoutable) {
if ($value instanceof UrlRoutable) {
$value = $value->getRouteKey();
}
$route = str_replace(array('{'.$key.'}', '{'.$key.'?}'), $value, $route);
Expand Down Expand Up @@ -776,7 +783,7 @@ public function getSerializedTranslatedRoutes()
*/
public function setSerializedTranslatedRoutes($serializedRoutes)
{
if ( ! $serializedRoutes) {
if (! $serializedRoutes) {
return;
}

Expand Down Expand Up @@ -917,14 +924,14 @@ protected function unparseUrl($parsed_url)
* @param array $attributes The attributes
* @return array The normalized attributes
*/
protected function normalizeAttributes($attributes)
{
if (array_key_exists('data', $attributes) && \is_array($attributes['data']) && ! \count($attributes['data'])) {
$attributes['data'] = null;
return $attributes;
}
return $attributes;
}
protected function normalizeAttributes($attributes)
{
if (array_key_exists('data', $attributes) && \is_array($attributes['data']) && ! \count($attributes['data'])) {
$attributes['data'] = null;
return $attributes;
}
return $attributes;
}

/**
* Returns the forced environment set route locale.
Expand Down
Loading