isLanguageCode.php
Table of Contents
Functions
- isLanguageCode() : bool
- Checks whether a value is a language tag safe to use as an identifier.
Functions
isLanguageCode()
Checks whether a value is a language tag safe to use as an identifier.
isLanguageCode(mixed $value) : bool
A language tag rarely stays a value: it names a key of a translations map
(alternateName.fr), a directory, a template, or an attribute of a stored
document — places where it is written verbatim rather than passed as a
parameter. Anything interpolating a tag has to prove it harmless first, and
this helper is that proof.
A valid tag is a two or three letter primary subtag, optionally followed by
dash-separated subtags (region, script, variant): fr, en, pt-BR,
zh-Hant-TW. The primary subtag is lowercase — callers normalise before
asking, so FR is rejected rather than silently accepted under two spellings.
⚠ A tag carrying a dash is valid here but is not always reachable through
dot notation (alternateName.pt-BR reads as a subtraction in several query
languages). The caller emits the bracket form for it; this helper only says
the tag is safe.
Parameters
- $value : mixed
-
The value to check.
Tags
Return values
bool —True when $value is a safe language tag.