class LocaleManager

Constants

REVISION_STAMP_KEY

A setting any extension can bump to declare that translations have changed somewhere the registered files cannot show — the database, most obviously. Its value is opaque: only whether it differs matters.

Properties

protected array $locales
protected array $js
protected array $css
protected list<string> $registered Every translation file registered on this instance, as `<locale>|<prefix>|<file>`.

Methods

__construct(Translator $translator, string|null $cacheDir = null, SettingsRepositoryInterface|null $settings = null)

No description

string
revision()

Identifies the translations this instance has been given.

string
revisionStamp()

No description

string
getLocale()

No description

void
setLocale(string $locale)

No description

void
addLocale(string $locale, string $name)

No description

array
getLocales()

No description

bool
hasLocale(string $locale)

No description

void
addTranslations(string $locale, string $file, string|null $module = null)

No description

void
addJsFile(string $locale, string $js)

No description

array
getJsFiles(string $locale)

No description

void
addCssFile(string $locale, string $css)

No description

array
getCssFiles(string $locale)

No description

getTranslator()

No description

void
setTranslator(Translator $translator)

No description

void
clearCache()

No description

Details

__construct(Translator $translator, string|null $cacheDir = null, SettingsRepositoryInterface|null $settings = null)

Parameters

Translator $translator
string|null $cacheDir
SettingsRepositoryInterface|null $settings

string revision()

Identifies the translations this instance has been given.

A compiled catalogue's filename covers only the fallback locales, and in production `ConfigCache::isFresh()` answers `is_file()` — so once a catalogue exists nothing detects that the translations behind it have changed. Enabling an extension on one instance therefore leaves every other instance serving a catalogue that predates it, indefinitely: no mtime, no TTL and no revision would ever say otherwise, and only deleting the file forces a rebuild. This is derived from what an instance can see for itself — the files it was given, plus a stamp for translations that live elsewhere — so an instance that has been told nothing still works out that its catalogue is stale. Two instances given the same translations arrive at the same value, which is what keeps them from rebuilding in turn forever. Deliberately not derived from the contents or timestamps of those files: that would mean asking each registered resource whether it is fresh, which runs third-party code that has never executed in production — some of it resolving services and querying the database on every request. A file edited in place, with nothing added or removed and no stamp bumped, is the one change this does not see; clearing the cache covers it, which a deployment does anyway.

Return Value

string

protected string revisionStamp()

Return Value

string

string getLocale()

Return Value

string

void setLocale(string $locale)

Parameters

string $locale

Return Value

void

void addLocale(string $locale, string $name)

Parameters

string $locale
string $name

Return Value

void

array getLocales()

Return Value

array

bool hasLocale(string $locale)

Parameters

string $locale

Return Value

bool

void addTranslations(string $locale, string $file, string|null $module = null)

Parameters

string $locale
string $file
string|null $module

Return Value

void

void addJsFile(string $locale, string $js)

Parameters

string $locale
string $js

Return Value

void

array getJsFiles(string $locale)

Parameters

string $locale

Return Value

array

void addCssFile(string $locale, string $css)

Parameters

string $locale
string $css

Return Value

void

array getCssFiles(string $locale)

Parameters

string $locale

Return Value

array

Translator getTranslator()

Return Value

Translator

void setTranslator(Translator $translator)

Parameters

Translator $translator

Return Value

void

void clearCache()

Return Value

void