Documentation

Translator extends Translator
in package
implements WarmableInterface

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Interfaces

WarmableInterface
Interface for classes that support warming their cache.

Properties

$catalogues  : array<string|int, MessageCatalogueInterface>
$container  : mixed
$loaderIds  : mixed
$options  : mixed
$cacheDir  : string|null
$cacheVary  : array<string|int, mixed>
$configCacheFactory  : mixed
$debug  : bool
$enabledLocales  : array<string|int, string>
$fallbackLocales  : array<string|int, string>
$formatter  : mixed
$hasIntlFormatter  : bool
$loaders  : array<string|int, LoaderInterface>
$locale  : string
$parentLocales  : array<string|int, mixed>
$resourceFiles  : array<string|int, array<string|int, string>>
$resourceLocales  : array<int, string>
$resources  : array<string|int, array<string|int, mixed>>
Holds parameters from addResource() calls so we can defer the actual parent::addResource() calls until initialize() is executed.
$scannedDirectories  : array<string|int, string>

Methods

__construct()  : mixed
Constructor.
addLoader()  : mixed
Adds a Loader.
addResource()  : mixed
Adds a Resource.
getCatalogue()  : MessageCatalogueInterface
Gets the catalogue by locale.
getCatalogues()  : array<string|int, MessageCatalogueInterface>
Returns all catalogues of the instance.
getLocale()  : string
Returns the default locale.
setConfigCacheFactory()  : mixed
setFallbackLocales()  : mixed
Sets the fallback locales.
setLocale()  : mixed
Sets the current locale.
trans()  : string
Translates the given message.
warmUp()  : array<string|int, string>
Warms up the cache.
assertValidLocale()  : mixed
Asserts that the locale is valid, throws an Exception if not.
computeFallbackLocales()  : mixed
getLoaders()  : array<string|int, LoaderInterface>
Gets the loaders.
initialize()  : mixed
initializeCatalogue()  : mixed
loadCatalogue()  : mixed
addResourceFiles()  : void
dumpCatalogue()  : void
getAllMessages()  : array<string|int, mixed>
getCatalogueCachePath()  : string
getConfigCacheFactory()  : ConfigCacheFactoryInterface
Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
getFallbackContent()  : string
initializeCacheCatalogue()  : void
loadFallbackCatalogues()  : void

Properties

$options

protected mixed $options = ['cache_dir' => null, 'debug' => false, 'resource_files' => [], 'scanned_directories' => [], 'cache_vary' => []]

$cacheVary

private array<string|int, mixed> $cacheVary

$configCacheFactory

private mixed $configCacheFactory

$enabledLocales

private array<string|int, string> $enabledLocales

$fallbackLocales

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

$hasIntlFormatter

private bool $hasIntlFormatter

$parentLocales

private array<string|int, mixed> $parentLocales

$resourceFiles

private array<string|int, array<string|int, string>> $resourceFiles

$resourceLocales

private array<int, string> $resourceLocales

$resources

Holds parameters from addResource() calls so we can defer the actual parent::addResource() calls until initialize() is executed.

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

$scannedDirectories

private array<string|int, string> $scannedDirectories

Methods

__construct()

Constructor.

public __construct(ContainerInterface $container, MessageFormatterInterface $formatter, string $defaultLocale[, array<string|int, mixed> $loaderIds = [] ][, array<string|int, mixed> $options = [] ][, array<string|int, mixed> $enabledLocales = [] ]) : mixed

Available options:

  • cache_dir: The cache directory (or null to disable caching)
  • debug: Whether to enable debugging or not (false by default)
  • resource_files: List of translation resources available grouped by locale.
  • cache_vary: An array of data that is serialized to generate the cached catalogue name.
Parameters
$container : ContainerInterface
$formatter : MessageFormatterInterface
$defaultLocale : string
$loaderIds : array<string|int, mixed> = []
$options : array<string|int, mixed> = []
$enabledLocales : array<string|int, mixed> = []
Tags
throws
InvalidArgumentException

addResource()

Adds a Resource.

public addResource(string $format, mixed $resource, string $locale[, string $domain = null ]) : mixed
Parameters
$format : string

The name of the loader (@see addLoader())

$resource : mixed

The resource name

$locale : string
$domain : string = null

getLocale()

Returns the default locale.

public getLocale() : string
Return values
string

setFallbackLocales()

Sets the fallback locales.

public setFallbackLocales(array<string|int, string> $locales) : mixed
Parameters
$locales : array<string|int, string>
Tags
throws
InvalidArgumentException

If a locale contains invalid characters

setLocale()

Sets the current locale.

public setLocale(string $locale) : mixed
Parameters
$locale : string

trans()

Translates the given message.

public trans(string|null $id[, array<string|int, mixed> $parameters = [] ][, string $domain = null ][, string $locale = null ]) : string
Parameters
$id : string|null

The message id (may also be an object that can be cast to string)

$parameters : array<string|int, mixed> = []

An array of parameters for the message

$domain : string = null

The domain for the message or null to use the default

$locale : string = null

The locale or null to use the default

Return values
string

warmUp()

Warms up the cache.

public warmUp(string $cacheDir) : array<string|int, string>
Parameters
$cacheDir : string
Return values
array<string|int, string>

assertValidLocale()

Asserts that the locale is valid, throws an Exception if not.

protected assertValidLocale(string $locale) : mixed
Parameters
$locale : string
Tags
throws
InvalidArgumentException

If the locale contains invalid characters

computeFallbackLocales()

protected computeFallbackLocales(string $locale) : mixed
Parameters
$locale : string

initializeCatalogue()

protected initializeCatalogue(string $locale) : mixed
Parameters
$locale : string

loadCatalogue()

protected loadCatalogue(string $locale) : mixed
Parameters
$locale : string

addResourceFiles()

private addResourceFiles() : void

getCatalogueCachePath()

private getCatalogueCachePath(string $locale) : string
Parameters
$locale : string
Return values
string

initializeCacheCatalogue()

private initializeCacheCatalogue(string $locale) : void
Parameters
$locale : string

loadFallbackCatalogues()

private loadFallbackCatalogues(string $locale) : void
Parameters
$locale : string

        
On this page

Search results