laravel-lang/json-fallback
Adds a JSON fallback translator to Laravel so missing JSON translation keys resolve to your fallback locale instead of showing raw keys. Drop-in service provider, no config required.
?? 'fallback' guards in Blade, defensive lookups in JS, or a custom JsonLoader. That logic tends to sprawl across frontend and backend, is untested, and breaks silently. This package replaces it with a framework-native swap in a service provider. Decide to buy unless you need multi-tier fallback chains or nested JSON structures — both of which require extending it anyway.Adopt when:
lang/{locale}.json) — SPA/hybrid frontends, API-supplied strings, JS error messages, dynamic labels — and you have no fallback today.fr → en) resolved server-side, so no frontend code needs to know about it.__() / trans() call sites.Look elsewhere when:
pt-BR → pt-PT → en). Out of the box it's one tier; anything richer is custom work.spatie/laravel-translation-loader, Crowdin/Lokalise runtime delivery). Those vendors usually ship their own fallback semantics; integrating both is duplicated logic.Executives (30 seconds).
When a translation is missing in a launched market, users don't see an error — they see a blank button, a raw key like checkout.submit, or an empty label. That happens in the highest-value flows and it costs conversions quietly, without a support ticket. This package makes missing translations degrade gracefully to English instead of breaking the interface.
The ask is small: roughly a day of engineering, no licence cost, no vendor contract, and it's reversible. The strategic value is that translation completeness stops being a launch blocker. We can enter a market on schedule at 80% coverage, measure exactly which strings are falling back and how often, and spend translation budget where it actually costs us money rather than where a spreadsheet says we're incomplete. Whether this reduces support volume or lift is a hypothesis we should test in one flow before generalizing — I'd want the fallback-rate dashboard live before we make that claim externally.
Engineering (the working agreement).
The integration is a service provider that swaps Laravel's JsonLoader for a fallback-aware one. No changes to controllers, Blade, or existing __() calls. Configuration is a fallback locale. Cost is a file lookup on miss — negligible, but worth a quick benchmark against your largest JSON file.
The constraints to accept up front: flat keys only, single fallback tier, JSON files must be valid. If we need nested keys or pt-BR → pt-PT → en, that's our work, not the package's — estimate it before committing rather than discovering it mid-migration.
The dependency risk is real but bounded. Small surface area, MIT, one active maintainer. Mitigations: pin a version, vendor or fork it if maintenance lapses (a day's work given the scope), and keep fallback behaviour behind a single config point so it can be replaced.
Proposed sequence: (1) add JSON validation to CI so we can trust the files at all; (2) pilot in one revenue-critical flow in one locale; (3) instrument fallback hits and ship the per-locale, per-key report; (4) expand only if the data supports it. Do not roll this out globally before step three — the measurement is the point.
How can I help you explore Laravel packages today?