CoolCMS API

AdminLocaleOptions
in package

FinalYes

Language options for the admin header switcher ({@see \App\UI\Admin\System\Components\LocaleSwitcherComponent\LocaleSwitcher}).

Pure logic without DB or presenter, so it can be tested alone.

The admin resolves its language in this order:

  1. persistent parameter lang (?lang=en) overrides everything else (LanguageInitTrait::initializeLanguage());
  2. localization language from the URL prefix /<loc>/admin... (loc is the localization key, default cs means no prefix; AdminRouteFactory);
  3. unknown localization falls back to en.

The user language (User::$languageId) does not affect the admin; nothing reads it on startup.

The switcher therefore links to loc = <localization key> and clears lang, otherwise a leftover ?lang=... would override the choice.

Table of Contents

Methods

build()  : array<int, array{key: string, alias: string, current: bool}>
Offered languages: active localizations whose language the admin supports. Each language appears once; with several localizations of the same language the main one wins, otherwise the first.
isSamePageIgnoringLocale()  : bool
Returns whether `$a` is the same admin page as `$b`, differing only in the language prefix (`/en/admin/x` vs `/admin/x`) or an overriding `?lang=`. Query parameters are compared regardless of order.
linkParams()  : array{loc: string, lang: null}
Parameters for `link('this', ...)`: a different prefix and no overriding `lang`; the link takes everything else (id, grid filters and paging) from the current request itself.
translatedAliases()  : array<int, string>
Languages (aliases) the admin has translated texts for, derived from the files `app/Locale/<modul>/<locale>/admin.<LOCALE>.neon` (`admin.en_US.neon` → `en`).
normalize()  : string

Methods

build()

Offered languages: active localizations whose language the admin supports. Each language appears once; with several localizations of the same language the main one wins, otherwise the first.

public static build(array<int, array{key: string, alias: ?string, active: bool, main: bool}> $localizations, array<int, string> $translatedAliases, string|null $currentAlias) : array<int, array{key: string, alias: string, current: bool}>
Parameters
$localizations : array<int, array{key: string, alias: ?string, active: bool, main: bool}>
$translatedAliases : array<int, string>
$currentAlias : string|null
Return values
array<int, array{key: string, alias: string, current: bool}>

isSamePageIgnoringLocale()

Returns whether `$a` is the same admin page as `$b`, differing only in the language prefix (`/en/admin/x` vs `/admin/x`) or an overriding `?lang=`. Query parameters are compared regardless of order.

public static isSamePageIgnoringLocale(string $a, string $b) : bool

Used when returning after a form save: after switching language on an edit page the Referer is the same edit in the original language, so "back" would lead to it (still with the original prefix).

Parameters
$a : string

path (without host), optionally with ?query

$b : string

path (without host), optionally with ?query

Return values
bool

linkParams()

Parameters for `link('this', ...)`: a different prefix and no overriding `lang`; the link takes everything else (id, grid filters and paging) from the current request itself.

public static linkParams(string $localizationKey) : array{loc: string, lang: null}
Parameters
$localizationKey : string
Return values
array{loc: string, lang: null}

translatedAliases()

Languages (aliases) the admin has translated texts for, derived from the files `app/Locale/<modul>/<locale>/admin.<LOCALE>.neon` (`admin.en_US.neon` → `en`).

public static translatedAliases(string $localeDir) : array<int, string>
Parameters
$localeDir : string
Return values
array<int, string>

normalize()

private static normalize(string $pathWithQuery) : string
Parameters
$pathWithQuery : string
Return values
string
On this page

Search results