Static-PHP i18n at OVH scale
An i18n stack that works on cheap shared hosting where mod_rewrite QSA breaks: URL path parsing in PHP + a JS link-rewriter at boot. No frameworks, no build step.
Most i18n stacks assume a real framework. We needed PT and ES versions of a static-ish PHP site on OVH shared hosting, where mod_rewrite's QSA flag sometimes drops query strings before PHP sees them.
Two pieces:
- Server side: a
lang()helper that reads$_GET['lang']first, falls back to a regex against$_SERVER['REQUEST_URI']for/pt/or/es/. Belt and braces — works whether the rewrite forwards QS or not. - Client side: a 12-line JS at boot that detects the URL locale and rewrites every internal
<a href="/...">to prepend/pt/or/es/. Same locale persists through every internal click.
No React, no Next, no router library. Three locales (EN, PT, ES) sitting on a Cockpit headless CMS that holds the translated strings. Sitemap.php emits all three URL variants with hreflang alternates.
Boring stack. Ships fast. Works on hosting that costs €4/month.