MultilingualString
in package
implements
Translatable
Multilingual string.
Tags
Table of Contents
Interfaces
- Translatable
- Base interface of multilingual strings.
Properties
- $isEmpty : bool
- Indicates whether this string is considered empty.
- $variants : array<string, string>
- Language variants.
Methods
- __construct() : mixed
- Multilingual string constructor.
- __serialize() : array<string|int, mixed>
- Returns a serializable representation of this multilingual string.
- __toString() : string
- Returns a plain string representation of this multilingual string.
- __unserialize() : void
- Restores the object from serialized state.
- equals() : bool
- Indicates whether some other multilingual string is equal to this one.
- get() : string|null
- Returns variant of this multilingual string in the given language.
- getLanguages() : array<string|int, string>
- Lists identifiers of all language variants defined by this multilingual string.
- has() : bool
- Indicates whether this multilingual string contains the given language variant.
- isEmpty() : bool
- Indicates whether this string does not contain any language variants or all of them are an empty string.
- toArray() : array<string, string>
- Returns all language variants contained in this object as an array.
- setVariants() : $this
- Populates the language variants of this string.
Properties
$isEmpty
Indicates whether this string is considered empty.
private
bool
$isEmpty
= true
Tags
$variants
Language variants.
private
array<string, string>
$variants
= []
Methods
__construct()
Multilingual string constructor.
public
__construct(array<string, string> $variants) : mixed
The constructor parameter is an array where keys are language identifiers and values plain strings that represent the particular language variant.
Parameters
- $variants : array<string, string>
-
language variants
Tags
__serialize()
Returns a serializable representation of this multilingual string.
public
__serialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —serializable array
__toString()
Returns a plain string representation of this multilingual string.
public
__toString() : string
Tags
Return values
string —plain string
__unserialize()
Restores the object from serialized state.
public
__unserialize(array<string|int, mixed> $serialized) : void
Parameters
- $serialized : array<string|int, mixed>
-
serialized array
Tags
equals()
Indicates whether some other multilingual string is equal to this one.
public
equals(Translatable $other) : bool
Parameters
- $other : Translatable
-
the multilingual string with which to compare
Tags
Return values
bool —true
if the strings are equal, false
if not
get()
Returns variant of this multilingual string in the given language.
public
get(string $language) : string|null
Parameters
- $language : string
-
language variant to return
Tags
Return values
string|null —plain string in the given language or null
if the requested variant is not defined
getLanguages()
Lists identifiers of all language variants defined by this multilingual string.
public
getLanguages() : array<string|int, string>
Tags
Return values
array<string|int, string> —language variant identifiers
has()
Indicates whether this multilingual string contains the given language variant.
public
has(string $language) : bool
Parameters
- $language : string
-
language variant to check
Tags
Return values
bool —true
if the given language variant is defined, false
if not
isEmpty()
Indicates whether this string does not contain any language variants or all of them are an empty string.
public
isEmpty() : bool
Tags
Return values
bool —true
if no language variants are defined or all are empty string, false
otherwise
toArray()
Returns all language variants contained in this object as an array.
public
toArray() : array<string, string>
Tags
Return values
array<string, string> —language variants
setVariants()
Populates the language variants of this string.
private
setVariants(array<string, string> $variants) : $this
Parameters
- $variants : array<string, string>
-
language variants