LocalizedSettingKey
in package
Language variants of a setting key: `<base key>.<language alias>`.
cms_system_settings (module, key, value) has no language column and the schema should not
change for a few website identity texts. A language-dependent value therefore lives in its own
row with the language alias suffix (site.name.en, site.tagline.sk); the base key without a
suffix holds the value of the default language (the main localization language) and is also the
fallback for all others.
The dot does not collide with key parsing: a key is a flat string across the system (PK
module + key, SettingManager::get() is $map[$module][$key], no explode('.') or
nesting). The dotted convention area.key is only naming. A collision is possible only in the
namespace, so only keys listed by the caller (website identity) get language variants, not
arbitrary keys.
Read rules (resolve()):
- non-empty value of
<key>.<alias>for the page language, - otherwise the base
<key>(default language), - otherwise
''. An empty language value means "untranslated" and falls back, so a signature cannot be disabled in one language only. This is deliberate: an empty field in an admin language tab must not silently erase the website name on /en/.
Table of Contents
Constants
- SEPARATOR : string = '.'
- ALIAS_PATTERN : string = '~^[a-z]{2,3}(?:[-_][a-z0-9]{2,4})?$~'
- Language alias as kept in `cms_system_languages.alias` (cs, en, sk, ...).
Methods
- forLanguage() : string
- Key of a language variant; an invalid or empty alias gives the base key.
- isVariantOf() : bool
- Whether `$key` is a language variant of `$baseKey` (not the base key itself).
- resolve() : string
- Value for the page language with a fallback to the base key.
- normalizeAlias() : string|null
- toTrimmedString() : string
Constants
SEPARATOR
public
string
SEPARATOR
= '.'
ALIAS_PATTERN
Language alias as kept in `cms_system_languages.alias` (cs, en, sk, ...).
private
string
ALIAS_PATTERN
= '~^[a-z]{2,3}(?:[-_][a-z0-9]{2,4})?$~'
Methods
forLanguage()
Key of a language variant; an invalid or empty alias gives the base key.
public
static forLanguage(string $baseKey, string|null $alias) : string
Parameters
- $baseKey : string
- $alias : string|null
Return values
stringisVariantOf()
Whether `$key` is a language variant of `$baseKey` (not the base key itself).
public
static isVariantOf(string $key, string $baseKey) : bool
Parameters
- $key : string
- $baseKey : string
Return values
boolresolve()
Value for the page language with a fallback to the base key.
public
static resolve(callable(string): mixed $read, string $baseKey, string|null $alias) : string
Parameters
- $read : callable(string): mixed
-
reads one key (null = does not exist)
- $baseKey : string
- $alias : string|null
Return values
stringnormalizeAlias()
private
static normalizeAlias(string|null $alias) : string|null
Parameters
- $alias : string|null
Return values
string|nulltoTrimmedString()
private
static toTrimmedString(mixed $value) : string
Parameters
- $value : mixed