StringVisitor
in package
Utility to walk through an Afform document and perform some action on every localizable string.
Table of Contents
Methods
- extractStrings() : $this
- Search a form for any translatable strings.
- visit() : void
- Search an afform for translateable strings. These may appear in many places, such as the metadata ('title'), HTML body ('p.af-text'), attributes ('af-title'), and field-definitions ('af-field[defn]')
- defnLookupTranslate() : mixed
- Helper to translate defn data recursively
- isWorthy() : bool
- translateAttribute() : mixed
- Helper to translate attributes.
Methods
extractStrings()
Search a form for any translatable strings.
public
static extractStrings(array<string|int, mixed> $form, string $html) : $this
Parameters
- $form : array<string|int, mixed>
-
Metadata describing form. Ex: ['title' => 'Hello world']
- $html : string
-
Form layout (encoded as an HTML string).
Return values
$thisvisit()
Search an afform for translateable strings. These may appear in many places, such as the metadata ('title'), HTML body ('p.af-text'), attributes ('af-title'), and field-definitions ('af-field[defn]')
public
visit(array<string|int, mixed> &$form, phpQueryObject|null $doc, callable $callback) : void
Whenever we find a string, apply a filter.
Parameters
- $form : array<string|int, mixed>
-
Metadata describing the form. Ex: ['title' => 'Hello world']
- $doc : phpQueryObject|null
-
Parsed layout for the form.
- $callback : callable
-
Filter the value of a string. This should return the new value. Function(string $value, string $context): string
Tags
defnLookupTranslate()
Helper to translate defn data recursively
protected
defnLookupTranslate(mixed &$defn, mixed $selector, mixed $callback) : mixed
Parameters
- $defn : mixed
- $selector : mixed
- $callback : mixed
isWorthy()
protected
isWorthy(mixed $value) : bool
Parameters
- $value : mixed
Return values
booltranslateAttribute()
Helper to translate attributes.
protected
translateAttribute(mixed &$item, mixed $attribute, mixed $callback) : mixed
Parameters
- $item : mixed
- $attribute : mixed
- $callback : mixed