wikimedia/bcp-47-code
A lightweight PHP library offering value objects for BCP 47 language codes, letting you parse, validate, and format tags like en, de-AT, or zh-Hant safely instead of passing raw strings around.
hreflang emission, this package supplies the primitives: an immutable BCP 47 value object, canonical case normalization (language lowercase, script titlecase, region uppercase), and semantic equality checks instead of brittle string comparison at every call site.simple, be-tarask, zh-hant) are where homegrown helpers rot. This is a small buy: one class plus one interface, no transitive dependency weight.Bcp47Code) alongside a concrete value object, it can be introduced behind existing string-typed language fields and widened call-site by call-site, rather than as a flagged rewrite. That's a cheap architectural bet to approve.hreflang generation, locale-preference storage with canonical values, translation workflow keys, content-negotiation downstream of an Accept-Language parser (note: parsing is not in scope here), and any code path that currently compares 'en-US', 'en-us', and 'en_US' inconsistently.Adopt (or, more realistically, pilot) when:
Look elsewhere when:
Accept-Language parsing — use Symfony's HTTP foundation or a dedicated negotiation library.symfony/intl, ICU, or a locale-data package.To executives: This is a micro-dependency that prevents a recurring class of internationalization defects — mismatched language tags silently breaking translations, redirects, and SEO metadata. Cost is trivial; strategic weight is also trivial. Recommend a bounded spike, not a platform commitment.
To engineering: It gives you an interface plus an immutable, canonically-normalized language-code value object, which lets us stop passing raw strings that mean subtly different things. Integration is manual — no Laravel service provider, no validation rule, minimal docs — so we'd own the wiring and the Eloquent cast. Two caveats to weigh: the license is GPL-2.0, and the GitHub repo is a mirror of Wikimedia's Gerrit, so upstream contributions and issue triage follow MediaWiki process. Treat it as vendor-able code with a small surface, not as an unowned dependency to add casually.
Framing the risk honestly: The package's utility is real and its ecosystem traction is not. That combination argues for a time-boxed evaluation with a vendoring escape hatch written into the plan, rather than either dismissal or adoption at scale.
How can I help you explore Laravel packages today?