CoolCMS API

AbstractTranslator
in package
implements TranslatorInterface

AbstractYes

Base class of route translators: keeps the list of route factories that use a translator.

Table of Contents

Interfaces

TranslatorInterface

Properties

$targetFactories  : array<string|int, string>

Methods

addTargetFactory()  : void
Registers a route factory that uses this translator.
getTargetFactories()  : array<string|int, string>
Returns the route factories that use this translator.
fromCacheWithLanguageFallback()  : TValue|null
Returns a value from a translation cache, falling back to the other languages.

Properties

$targetFactories

private array<string|int, string> $targetFactories = []

short names of the route factory classes that use this translator

Methods

addTargetFactory()

Registers a route factory that uses this translator.

public addTargetFactory(string $factoryClass) : void

Called from the factory constructor as addTargetFactory($this::class).

Parameters
$factoryClass : string

fully qualified factory class name

getTargetFactories()

Returns the route factories that use this translator.

public getTargetFactories() : array<string|int, string>
Return values
array<string|int, string> —

factory class names without namespace

fromCacheWithLanguageFallback()

Returns a value from a translation cache, falling back to the other languages.

protected fromCacheWithLanguageFallback(array<string|int, mixed> $cache, int $languageId, TKey $key) : TValue|null

IMPORTANT: without the fallback a translator returns null when the translation for the language is missing, and the route cannot build the URL at all ("No route for ..."). One untranslated category then breaks the whole foreign-language page, not just its own link.

Untranslated content shows in the main language instead of disappearing: the URL carries the main-language slug under /en/, until someone adds the translation.

Parameters
$cache : array<string|int, mixed>
$languageId : int
$key : TKey
Tags
template
Return values
TValue|null
On this page

Search results