class FileTranslation extends StaticTranslation (View source)

File based string translation.

Translates a string when some systems are not available.

Used during the install process, when database, theme, and localization system is possibly not yet available.

Properties

protected array $translations

String translations

from  StaticTranslation
protected string $directory

Directory to find translation files in the file system.

protected FileSystemInterface $fileSystem

The file system.

Methods

__construct(string $directory, FileSystemInterface $file_system = NULL)

Constructs a StaticTranslation object.

string|false
getStringTranslation(string $langcode, string $string, string $context)

Retrieves English string to given language.

reset()

Resets translation cache.

array
getLanguage(string $langcode)

Retrieves translations for a given language.

array
findTranslationFiles(string $langcode = NULL)

Finds installer translations either for a specific or all languages.

string
getTranslationFilesPattern(string $langcode = NULL)

Provides translation file name pattern.

static array
filesToArray(string $langcode, array $files)

Reads the given Gettext PO files into a data structure.

Details

__construct(string $directory, FileSystemInterface $file_system = NULL)

Constructs a StaticTranslation object.

Parameters

string $directory

The directory to retrieve file translations from.

FileSystemInterface $file_system

The file system service.

string|false getStringTranslation(string $langcode, string $string, string $context)

Retrieves English string to given language.

Parameters

string $langcode

Language code to translate to.

string $string

The source string.

string $context

The string context.

Return Value

string|false

Translated string if there is a translation, FALSE if not.

reset()

Resets translation cache.

Since most translation systems implement some form of caching, this provides a way to delete that cache.

protected array getLanguage(string $langcode)

Retrieves translations for a given language.

Parameters

string $langcode

The langcode of the language.

Return Value

array

A multidimensional array of translations, indexed by the context the source string belongs to. The second level is using original strings as keys. An empty array will be returned when no translations are available.

array findTranslationFiles(string $langcode = NULL)

Finds installer translations either for a specific or all languages.

Filenames must match the pattern:

  • 'drupal-[version].[langcode].po (if langcode is provided)
  • 'drupal-[version].*.po (if no langcode is provided)

Parameters

string $langcode

(optional) The language code corresponding to the language for which we want to find translation files. If omitted, information on all available files will be returned.

Return Value

array

An associative array of file information objects keyed by file URIs as returned by FileSystemInterface::scanDirectory().

See also

FileSystemInterface::scanDirectory

protected string getTranslationFilesPattern(string $langcode = NULL)

Provides translation file name pattern.

Parameters

string $langcode

(optional) The language code corresponding to the language for which we want to find translation files.

Return Value

string

String file pattern.

static array filesToArray(string $langcode, array $files)

Reads the given Gettext PO files into a data structure.

Parameters

string $langcode

Language code string.

array $files

List of file objects with URI properties pointing to read.

Return Value

array

Structured array as produced by a PoMemoryWriter.

See also

PoMemoryWriter