Skip to content

fix(i18n): resolve regional locales to the catalogue shipped for their language - #42

Merged
ph33nx merged 1 commit into
mainfrom
fix/regional-locale-fallback
Aug 5, 2026
Merged

fix(i18n): resolve regional locales to the catalogue shipped for their language#42
ph33nx merged 1 commit into
mainfrom
fix/regional-locale-fallback

Conversation

@ph33nx

@ph33nx ph33nx commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

WordPress matches translation files by exact locale. A site set to es_AR looks for roxyapi-es_AR.mo, finds none, and renders English — even though roxyapi-es_ES.mo is sitting in the same folder.

Found by installing 1.7.5 from the WordPress.org directory into a clean container and setting the site language to Spanish (Argentina), which is a real customer configuration. 1.7.5 would not have helped them.

Why a filter rather than more files

WordPress offers dozens of regional Spanish, Portuguese, German and French locales. Shipping one catalogue per variant means copying the same file ~20 times and copying it again whenever a locale is added upstream. This maps by language prefix instead, so one file per language covers every current and future variant.

The filter only ever sees paths WordPress could not read, so an official wp.org language pack for the exact locale always wins and is never shadowed.

Verified live, clean install from the directory

Site language Result
es_AR Datos de nacimiento / Fecha de nacimiento / Calcular carta
es_MX Datos de nacimiento / Fecha de nacimiento / Calcular carta
pt_PT Dados de nascimento / Data de nascimento / Calcular mapa
de_AT Geburtsdaten / Geburtsdatum / Chart berechnen
fr_CA Données de naissance / Date de naissance / Calculer le thème

Guarded by test-locale-fallback.php, including a non-vacuity check, an assertion that an exact match passes through untouched, that other text domains are never touched, and that an unsupported language (ja) is left alone rather than handed an unrelated catalogue.

…r language

WordPress matches translation files by exact locale, so a site set to es_AR
looked for roxyapi-es_AR.mo, found none, and rendered English even though
roxyapi-es_ES.mo was sitting in the same folder. Found by installing 1.7.5 from
the directory into a clean WordPress and setting the site to Spanish
(Argentina), which is a real customer configuration.

WordPress offers dozens of regional Spanish, Portuguese, German and French
locales, so the alternative was copying one catalogue per variant and copying it
again whenever a locale is added upstream. This maps by language prefix instead:
any xx_YY resolves to whichever xx_* catalogue is shipped, so one file per
language covers every current and future variant.

The filter only sees paths WordPress could not read, so an official wp.org
language pack for the exact locale always wins and is never shadowed.

Verified live across es_AR, es_MX, pt_PT, de_AT and fr_CA.
@ph33nx
ph33nx merged commit 9931a1f into main Aug 5, 2026
11 checks passed
@ph33nx
ph33nx deleted the fix/regional-locale-fallback branch August 5, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant