class TranslationString extends StringBase (View source)

Defines the locale translation string object.

This class represents a translation of a source string to a given language, thus it must have at least a 'language' which is the language code and a 'translation' property which is the translated text of the source string in the specified language.

Properties

int $lid

The string identifier.

from  StringBase
string $locations

The string locations indexed by type.

from  StringBase
string $source

The source string.

from  StringBase
string $context

The string context.

from  StringBase
string $version

The string version.

from  StringBase
protected StringStorageInterface $storage

The locale storage this string comes from or is to be saved to.

from  StringBase
string $language

The language code.

string $translation

The string translation.

int $customized

Integer indicating whether this string is customized.

protected bool $isNew

Boolean indicating whether the string object is new.

Methods

__construct(object|array $values = [])

Constructs a new locale string object.

int
getId()

Gets the string unique identifier.

$this
setId($lid)

Sets the string unique identifier.

string
getVersion()

Gets the string version.

$this
setVersion(string $version)

Sets the string version.

array
getPlurals()

Splits string to work with plural values.

$this
setPlurals(array $plurals)

Sets this string using array of plural values.

getStorage()

Gets the string storage.

$this
setStorage(StringStorageInterface $storage)

Sets the string storage.

$this
setValues(array $values, bool $override = TRUE)

Sets an array of values as object properties.

array
getValues(array $fields)

Gets field values that are set for given field names.

array
getLocations(bool $check_only = FALSE)

Gets location information for this string.

$this
addLocation(string $type, string $name)

Adds a location for this string.

bool
hasLocation(string $type, string $name)

Checks whether the string has a given location.

$this
save()

Saves string object to storage.

$this
delete()

Deletes string object from storage.

$this
setCustomized(bool $customized = TRUE)

Sets the string as customized / not customized.

bool
isSource()

Checks whether the object is a source string.

bool
isTranslation()

Checks whether the object is a translation string.

string
getString()

Gets plain string contained in this object.

$this
setString(string $string)

Sets the string contained in this object.

bool
isNew()

Checks whether the object is not saved to storage yet.

Details

__construct(object|array $values = [])

Constructs a new locale string object.

Parameters

object|array $values

Object or array with initial values.

int getId()

Gets the string unique identifier.

Return Value

int

The string identifier.

$this setId($lid)

Sets the string unique identifier.

Parameters

$lid

Return Value

$this

string getVersion()

Gets the string version.

Return Value

string

Version identifier.

$this setVersion(string $version)

Sets the string version.

Parameters

string $version

Version identifier.

Return Value

$this

array getPlurals()

Splits string to work with plural values.

Return Value

array

Array of strings that are plural variants.

$this setPlurals(array $plurals)

Sets this string using array of plural values.

Serializes plural variants in one string glued by \Drupal\Component\Gettext\PoItem::DELIMITER.

Parameters

array $plurals

Array of strings with plural variants.

Return Value

$this

StringStorageInterface getStorage()

Gets the string storage.

Return Value

StringStorageInterface

The storage used for this string.

$this setStorage(StringStorageInterface $storage)

Sets the string storage.

Parameters

StringStorageInterface $storage

The storage to use for this string.

Return Value

$this

$this setValues(array $values, bool $override = TRUE)

Sets an array of values as object properties.

Parameters

array $values

Array with values indexed by property name.

bool $override

(optional) Whether to override already set fields, defaults to TRUE.

Return Value

$this

array getValues(array $fields)

Gets field values that are set for given field names.

Parameters

array $fields

Array of field names.

Return Value

array

Array of field values indexed by field name.

array getLocations(bool $check_only = FALSE)

Gets location information for this string.

Locations are arbitrary pairs of type and name strings, used to store information about the origins of the string, like the file name it was found on, the path on which it was discovered, etc.

A string can have any number of locations since the same string may be found on different places of Drupal code and configuration.

Parameters

bool $check_only

(optional) Set to TRUE to get only new locations added during the current page request and not loading all existing locations.

Return Value

array

Location ids indexed by type and name.

$this addLocation(string $type, string $name)

Adds a location for this string.

Parameters

string $type

Location type that may be any arbitrary string. Types used in Drupal core are: 'javascript', 'path', 'code', 'configuration'.

string $name

Location name. Drupal path in case of online discovered translations, file path in case of imported strings, configuration name for strings that come from configuration, etc.

Return Value

$this

bool hasLocation(string $type, string $name)

Checks whether the string has a given location.

Parameters

string $type

Location type.

string $name

Location name.

Return Value

bool

TRUE if the string has a location with this type and name.

$this save()

Saves string object to storage.

Return Value

$this

Exceptions

StringStorageException

$this delete()

Deletes string object from storage.

Return Value

$this

Exceptions

StringStorageException

$this setCustomized(bool $customized = TRUE)

Sets the string as customized / not customized.

Parameters

bool $customized

(optional) Whether the string is customized or not. Defaults to TRUE.

Return Value

$this

The called object.

bool isSource()

Checks whether the object is a source string.

Return Value

bool

TRUE if the object is a source string, FALSE otherwise.

bool isTranslation()

Checks whether the object is a translation string.

Return Value

bool

TRUE if the object is a translation string, FALSE otherwise.

string getString()

Gets plain string contained in this object.

Return Value

string

The string contained in this object.

$this setString(string $string)

Sets the string contained in this object.

Parameters

string $string

String to set as value.

Return Value

$this

bool isNew()

Checks whether the object is not saved to storage yet.

Return Value

bool

TRUE if the object exists in the storage, FALSE otherwise.