class YamlWriter implements Writer (View source)

Write yml files compatible with ModuleYamlLoader

Note: YamlWriter may not correctly denormalise plural strings if writing outside of the default locale (en).

Properties

protected Dumper $dumper

Methods

protected
Dumper
getDumper()

No description

public
write(array $messages, string $locale, string $path)

No description

protected
array
denormaliseMessages(array $messages)

Explodes [class.key1 => value1, class.key2 => value2] into [class => [ key1 => value1, key2 => value2]]

protected
array|string
denormaliseValue(array|string $value)

Convert entities array format into yml-ready string / array

protected
array
getPluralForm(array|string $value)

Get array-plural form for any value

public
string
getYaml(array $messages, string $locale)

Convert messages to yml ready to write

protected
array
getClassKey(string $entity)

Determine class and key for a localisation entity

Details

protected Dumper getDumper()

No description

Return Value

Dumper

write(array $messages, string $locale, string $path)

No description

Parameters

array $messages

Map of entity names (incl. namespace) to default values. Values may be array format for pluralised values, or strings for normal localisations.

string $locale
string $path

The directory base on which the collector should create new lang folders and files. Usually the webroot set through Director::baseFolder(). Can be overwritten for testing or export purposes.

protected array denormaliseMessages(array $messages)

Explodes [class.key1 => value1, class.key2 => value2] into [class => [ key1 => value1, key2 => value2]]

Inverse of YamlReader::normaliseMessages()

Parameters

array $messages

Return Value

array

protected array|string denormaliseValue(array|string $value)

Convert entities array format into yml-ready string / array

Parameters

array|string $value

Input value

Return Value

array|string

denormalised value

protected array getPluralForm(array|string $value)

Get array-plural form for any value

Parameters

array|string $value

Return Value

array

List of plural forms, or empty array if not plural

string getYaml(array $messages, string $locale)

Convert messages to yml ready to write

Parameters

array $messages
string $locale

Return Value

string

protected array getClassKey(string $entity)

Determine class and key for a localisation entity

Parameters

string $entity

Return Value

array

Two-length array with class and key as elements