Skip to content

Commit

Permalink
Merge pull request #2214 from omeka/fix-default-locale
Browse files Browse the repository at this point in the history
Fix default locale when using debug
  • Loading branch information
zerocrates authored Jul 16, 2024
2 parents d816da2 + 184c1a8 commit 0ee0598
Showing 1 changed file with 20 additions and 6 deletions.
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

0 comments on commit 0ee0598

Please sign in to comment.