Hello,
Sharing a problem we hit on our staging server and how we resolved it, in case it helps others.
Symptom
All reader-facing pages (preprint list, detail, archive) lost their styling. The theme stylesheet was missing from the HTML entirely, while plugin stylesheets and the uploaded custom stylesheet were still present. Clearing caches and restarting the web server made no difference.
Error log
Plugin ...\DefaultThemePlugin failed to handle the hook
PluginRegistry::categoryLoaded::themes
TypeError: Locale::setDefault(): Argument #1 ($locale) must be of
type string, null given in .../lib/pkp/classes/i18n/Locale.php:163
What we found
Locale::setLocale() passes the full weblate language list (798 entries) to Locale::lookup():
$locales = array_keys($this->getWeblateLocaleNames());
\Locale::setDefault(\Locale::lookup($locales, $locale, true));
That list contains und, which cannot be canonicalized. With und in the candidate list, lookup() does not return a usable result. When it returns null, setDefault() throws, DefaultThemePlugin::init() aborts before addStyle() runs, and no theme CSS is ever registered.
Removing und makes it work again:
php -r '
$f="/path/to/ops/lib/pkp/lib/weblateLanguages/languages.json";
$l=array_keys(json_decode(file_get_contents($f),true));
printf("PHP=%s ICU=%s count=%d\n", PHP_VERSION, INTL_ICU_VERSION, count($l));
var_dump(\Locale::lookup($l,"ja",true));
var_dump(\Locale::lookup(array_values(array_diff($l,["und"])),"ja",true));
var_dump(\Locale::canonicalize("und"));
'
Results across three environments
| PHP | ICU | with und |
without und |
pages |
|---|---|---|---|---|
| 8.4.25 | 70.1 | NULL |
ja |
broken |
| 8.4.23 | 76.1 | "" |
ja |
fine |
| 8.4.17 | 74.2 | "" |
ja |
(OPS 3.3) |
The lookup fails on every version we tested, so this does not appear to be specific to one PHP or ICU release. Only the null case raises the TypeError; where an empty string is returned the page renders normally even though locale resolution has silently failed and setDefault("") is called. Our server ran fine for four months on PHP 8.4.18 and broke after an unattended upgrade to 8.4.25, with no change to OPS code or the database.
As a side note, the PHP manual states a maximum of 100 entries for the lookup() candidate list; OPS passes 798.
Our workaround
We patched Locale::setLocale() locally:
$locales = array_diff(array_keys($this->getWeblateLocaleNames()), ['und']);
\Locale::setDefault(\Locale::lookup($locales, $locale, true) ?: $locale);
After clearing the cache and restarting PHP-FPM, the pages render correctly again. We are aware this will be overwritten on upgrade and are tracking it as a local patch.
Posting mainly because sites where an empty string is returned will not show any symptom at all, so this may be present without anyone noticing.
Environment: OPS 3.5.0-5, Ubuntu 22.04, Apache 2 + PHP-FPM 8.4, MariaDB10.11.15.