CurrentLanguage
in package
Resolves the language the user is currently working in.
The currentlanguage setting is only written when the user actively picks a
language from the navbar dropdown. Two situations leave it unset or stale, and
both used to surface as "no language selected" even though the navbar showed
one:
- A user who has just created their first language has never fired the
dropdown's
changeevent. With exactly one language there is no other option to switch to, so the event can never fire and the setting can never be written — the install is stuck in that state permanently. - The setting can point at a language that has since been deleted.
In both cases the navbar still looked right: it renders a <select> and
marks an option selected only when the id matches, so with no match the
browser falls back to displaying the first option. The display and the stored
state disagreed, and every server-side consumer read 0.
This resolver is the single answer to "which language is active?". It is read-only on purpose: it never writes the setting, so a plain GET has no side effects and the same request always resolves the same way.
Callers that need the id to agree with what the navbar displays must use this
rather than reading the setting directly — the fallback ordering here matches
the navbar's (LgName, skipping unnamed rows).
Table of Contents
Methods
- resolveId() : int
- Resolve the effective current language ID.
- exists() : bool
- Check whether a language ID still exists.
- firstAvailableId() : int
- Get the first language the navbar would list.
Methods
resolveId()
Resolve the effective current language ID.
public
static resolveId() : int
Returns the stored setting when it still points at an existing language, otherwise the first language the navbar would list. Returns 0 only when the user genuinely has no languages yet.
Return values
int —Language ID, or 0 if none is available
exists()
Check whether a language ID still exists.
private
static exists(int $languageId) : bool
Parameters
- $languageId : int
-
Language ID to check
Return values
bool —True if the language exists
firstAvailableId()
Get the first language the navbar would list.
private
static firstAvailableId() : int
Mirrors the navbar's own filter and ordering so the resolved fallback is the language the user already sees displayed.
Return values
int —Language ID, or 0 if the user has no languages