class Service (View source)

A Service which provides further information about a given locale and the current state of the i18n and L10n components.

Properties

protected array $settings
protected PackageManager $packageManager
protected LocaleCollection $localeCollection

A collection of Locale objects representing currently installed locales, in a hierarchical manner.

protected VariableFrontend $cache
protected Configuration $configuration
protected string $localeBasePath

The base path to use in filesystem operations. It is changed only in tests.

Methods

void
injectSettings(array $settings)

No description

void
initializeObject()

Initializes the locale service

getConfiguration()

No description

array
getLocalizedFilename(string $pathAndFilename, Locale $locale = null, bool $strict = false)

Returns the path to the existing localized version of file given.

array
getXliffFilenameAndPath(string $path, string $sourceName, Locale $locale = null)

Returns the path to the existing localized version of file given.

array
getLocaleChain(Locale $locale)

Build a chain of locale objects according to the fallback rule and the available locales.

Locale|null
getParentLocaleOf(Locale $locale)

Returns a parent Locale object of the locale provided.

mixed
findBestMatchingLocale(Locale $locale)

Returns Locale object which is the most similar to the "template" Locale object given as parameter, from the collection of locales available in the current Flow installation.

void
generateAvailableLocalesCollectionFromSettings()

Generates the available Locales Collection from the configuration setting Neos.Flow.i18n.availableLocales.

string
getScanExcludePattern()

Returns a regex pattern including enclosing characters, that matches any of the configured exclude list configured inside "Neos.Flow.i18n.scan.excludePatterns".

void
generateAvailableLocalesCollectionByScanningFilesystem()

Finds all Locale objects representing locales available in the Flow installation. This is done by scanning all Private and Public resource files of all active packages, in order to find localized files.

Details

void injectSettings(array $settings)

No description

Parameters

array $settings

Return Value

void

void initializeObject()

Initializes the locale service

Return Value

void

Configuration getConfiguration()

No description

Return Value

Configuration

array getLocalizedFilename(string $pathAndFilename, Locale $locale = null, bool $strict = false)

Returns the path to the existing localized version of file given.

Searching is done for the current locale if no $locale parameter is provided. The search is done according to the configured fallback rule.

If parameter $strict is provided, searching is done only for the provided / current locale (without searching of files localized for more generic locales).

If no localized version of file is found, $filepath is returned without any change.

Parameters

string $pathAndFilename

Path to the file

Locale $locale

Desired locale of localized file

bool $strict

Whether to match only provided locale (true) or search for best-matching locale (false)

Return Value

array

Path to the localized file (or $filename when no localized file was found) and the matched locale

See also

Configuration::setFallbackRule

array getXliffFilenameAndPath(string $path, string $sourceName, Locale $locale = null)

Returns the path to the existing localized version of file given.

Searching is done for the current locale if no $locale parameter is provided. The search is done according to the configured fallback rule.

If parameter $strict is provided, searching is done only for the provided / current locale (without searching of files localized for more generic locales).

If no localized version of file is found, $filepath is returned without any change.

Parameters

string $path

Base directory to the translation files

string $sourceName

name of the translation source

Locale $locale

Desired locale of XLIFF file

Return Value

array

Path to the localized file (or $filename when no localized file was found) and the matched locale

See also

Configuration::setFallbackRule

array getLocaleChain(Locale $locale)

Build a chain of locale objects according to the fallback rule and the available locales.

Parameters

Locale $locale

Return Value

array

Locale|null getParentLocaleOf(Locale $locale)

Returns a parent Locale object of the locale provided.

Parameters

Locale $locale

The Locale to search parent for

Return Value

Locale|null

Existing Locale instance or NULL on failure

mixed findBestMatchingLocale(Locale $locale)

Returns Locale object which is the most similar to the "template" Locale object given as parameter, from the collection of locales available in the current Flow installation.

Parameters

Locale $locale

The "template" Locale to be matched

Return Value

mixed

Existing Locale instance on success, NULL on failure

protected void generateAvailableLocalesCollectionFromSettings()

Generates the available Locales Collection from the configuration setting Neos.Flow.i18n.availableLocales.

Note: result of this method invocation is cached

Return Value

void

protected string getScanExcludePattern()

Returns a regex pattern including enclosing characters, that matches any of the configured exclude list configured inside "Neos.Flow.i18n.scan.excludePatterns".

Return Value

string

The regex pattern matching the configured exclude list

protected void generateAvailableLocalesCollectionByScanningFilesystem()

Finds all Locale objects representing locales available in the Flow installation. This is done by scanning all Private and Public resource files of all active packages, in order to find localized files.

Localized files have a locale identifier added before their extension (or at the end of filename, if no extension exists). For example, a localized file for foobar.png, can be foobar.en.png, foobar.en_GB.png, etc.

Also, all folder names inside '/Private/Translations' are scanned for valid locales.

Just one localized resource file causes the corresponding locale to be regarded as available (installed, supported).

Note: result of this method invocation is cached

Return Value

void