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

Fix default locale when using debug #2214

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
26 changes: 20 additions & 6 deletions application/src/Mvc/MvcListeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,31 @@ public function bootstrapLocale(MvcEvent $event)
// The translator already loaded the configured locale.
$locale = $translator->getDelegatedTranslator()->getLocale();
}
if (extension_loaded('intl')) {
\Locale::setDefault($locale);
}
$this->setDefaultLocale($locale);
$translator->getDelegatedTranslator()->setLocale($locale);

// Enable automatic translation for validation error messages.
AbstractValidator::setDefaultTranslator($translator);
}

/**
* Set the default locale.
*
* Note that we only set a defualt locale when the intl extension is loaded
* and when the locale isn't "debug". The "debug" locale is a special case
* used by Omeka to detect translated strings on the page wihout switching
* to another language. Otherwise there will be a "Found unconstructed
* IntlDateFormatter" error.
*
* @param string $locale
*/
public function setDefaultLocale($locale)
{
if (extension_loaded('intl') && 'debug' !== $locale) {
\Locale::setDefault($locale);
}
}

/**
* Redirect all requests to install route if Omeka is not installed.
*
Expand Down Expand Up @@ -354,9 +370,7 @@ public function preparePublicSite(MvcEvent $event)
// locale.
$locale = $services->get('Omeka\Settings\Site')->get('locale');
if ($locale) {
if (extension_loaded('intl')) {
\Locale::setDefault($locale);
}
$this->setDefaultLocale($locale);
$services->get('MvcTranslator')->getDelegatedTranslator()->setLocale($locale);
}
}
Expand Down
Loading