PseudoLocalizationTranslator
in package
implements
TranslatorInterface
This translator should only be used in a development environment.
Table of Contents
Interfaces
Constants
- EXPANSION_CHARACTER = '~'
Properties
- $accents : bool
- $brackets : bool
- $expansionFactor : float
- $localizableHTMLAttributes : array<string|int, string>
- $parseHTML : bool
- $translator : mixed
Methods
- __construct() : mixed
- Available options: * accents: type: boolean default: true description: replace ASCII characters of the translated string with accented versions or similar characters example: if true, "foo" => "ƒöö".
- getLocale() : string
- Returns the default locale.
- trans() : string
- Translates the given message.
- addAccents() : void
- addBrackets() : void
- expand() : void
- getParts() : array<string|int, mixed>
- parseNode() : array<string|int, mixed>
- strlen() : int
Constants
EXPANSION_CHARACTER
private
mixed
EXPANSION_CHARACTER
= '~'
Properties
$accents
private
bool
$accents
$brackets
private
bool
$brackets
$expansionFactor
private
float
$expansionFactor
$localizableHTMLAttributes
private
array<string|int, string>
$localizableHTMLAttributes
$parseHTML
private
bool
$parseHTML
$translator
private
mixed
$translator
Methods
__construct()
Available options: * accents: type: boolean default: true description: replace ASCII characters of the translated string with accented versions or similar characters example: if true, "foo" => "ƒöö".
public
__construct(TranslatorInterface $translator[, array<string|int, mixed> $options = [] ]) : mixed
-
expansion_factor: type: float default: 1 validation: it must be greater than or equal to 1 description: expand the translated string by the given factor with spaces and tildes example: if 2, "foo" => "~foo ~"
-
brackets: type: boolean default: true description: wrap the translated string with brackets example: if true, "foo" => "[foo]"
-
parse_html: type: boolean default: false description: parse the translated string as HTML - looking for HTML tags has a performance impact but allows to preserve them from alterations - it also allows to compute the visible translated string length which is useful to correctly expand ot when it contains HTML warning: unclosed tags are unsupported, they will be fixed (closed) by the parser - eg, "foo
bar" => "foobar"localizable_html_attributes: type: string[] default: [] description: the list of HTML attributes whose values can be altered - it is only useful when the "parse_html" option is set to true example: if ["title"], and with the "accents" option set to true, "Profile" => "Þŕöƒîļé" - if "title" was not in the "localizable_html_attributes" list, the title attribute data would be left unchanged.
Parameters
- $translator : TranslatorInterface
- $options : array<string|int, mixed> = []
getLocale()
Returns the default locale.
public getLocale() : stringReturn values
stringtrans()
Translates the given message.
public trans(string $id[, array<string|int, mixed> $parameters = [] ][, string $domain = null ][, string $locale = null ]) : stringParameters
- $id : string
-
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
stringaddAccents()
private addAccents(string &$trans, string $text) : voidParameters
- $trans : string
- $text : string
addBrackets()
private addBrackets(string &$trans) : voidParameters
- $trans : string
expand()
private expand(string &$trans, string $visibleText) : voidParameters
- $trans : string
- $visibleText : string
getParts()
private getParts(string $originalTrans) : array<string|int, mixed>Parameters
- $originalTrans : string
Return values
array<string|int, mixed>parseNode()
private parseNode(DOMNode $node) : array<string|int, mixed>Parameters
- $node : DOMNode
Return values
array<string|int, mixed>strlen()
private strlen(string $s) : intParameters
- $s : string
Return values
intSearch results