Stud.IP  5.4
I18NString Class Reference
Inheritance diagram for I18NString:
I18NStringDatafield

Public Member Functions

 __construct ($base, $lang=null, $metadata=[])
 
 __toString ()
 
 jsonSerialize ()
 
 setOriginal ($text)
 
 setTranslations ($lang)
 
 setMetadata ($metadata)
 
 original ()
 
 translation ($lang)
 
 localized ($lang)
 
 setLocalized ($text, $lang)
 
 toArray ()
 
 trim ($symbols=" \\\B")
 
 storeTranslations ()
 
 removeTranslations ()
 

Static Public Member Functions

static setContentLanguage ($language)
 
static getContentLanguage ()
 
static setDefaultLanguage ($language=null)
 
static getDefaultLanguage ()
 
static load ($object_id, $table, $field, $base=null)
 
static fetchDataForField ($object_id, $table, $field)
 
static fetchDataForRow ($object_id, $table)
 
static removeAllTranslations ($object_id, $table, $lang=null)
 

Protected Attributes

 $base
 
 $lang
 
 $metadata
 

Static Protected Attributes

static $content_language = null
 
static $default_language = null
 

Detailed Description

I18NString class

Constructor & Destructor Documentation

◆ __construct()

__construct (   $base,
  $lang = null,
  $metadata = [] 
)

Initialize a new I18NString instance.

Parameters
string$baseText in default content language.
array$langText in additional languages.
array$metadataDatabase info for id, table, field.

Member Function Documentation

◆ __toString()

__toString ( )

Return the text representation of this i18n field in selected language. The language is selected by self::content_language (with precendence) or by $_SESSION['_language'].

Returns
string

◆ fetchDataForField()

static fetchDataForField (   $object_id,
  $table,
  $field 
)
static

Retrieves all translations of one field.

Parameters
string$object_idThe id of the object with i18n fields.
string$tableThe name of the table with the original values.
string$fieldThe name of the i18n field.
Returns
array An array with language as key and translation as value.

◆ fetchDataForRow()

static fetchDataForRow (   $object_id,
  $table 
)
static

Retrieves all translations of all fields for given object (by id) and table.

Parameters
string$object_idThe id of the object with i18n fields.
string$tableThe name of the table with the original values.
Returns
array An array with all translations of all fields grouped by field.

◆ getContentLanguage()

static getContentLanguage ( )
static

Returns the language the contnet is translated into.

Returns
string The language the content is translated into.

◆ getDefaultLanguage()

static getDefaultLanguage ( )
static

Returns the language all values are translated into by default. The language ist normally defined in $GLOBALS'CONTENT_LANGUAGES'.

Returns
string The default language all values are translated into.

◆ jsonSerialize()

jsonSerialize ( )

Return the JSON representation of this i18n field in selected language.

Returns
string

◆ load()

static load (   $object_id,
  $table,
  $field,
  $base = null 
)
static

Returns an I18NString object by given object_id, table and field.

Parameters
string$object_idThe id of the object with i18n fields.
string$tableThe name of the table with the original values.
string$fieldThe name of the i18n field.
string$baseSets the original value or retrieve it from database if null.
Returns
I18NString The I18NString object.

◆ localized()

localized (   $lang)

Returns the string in the specified language (additional languages and default languages).

Parameters
string$langAdditional language or default language.
Returns
string The localized string.

◆ original()

original ( )

Return the string in the default content language.

Returns
string String in default content language.

◆ removeAllTranslations()

static removeAllTranslations (   $object_id,
  $table,
  $lang = null 
)
static

Removes all translations by given object id and table name. Accepts the language as third parameter to remove only translations to this language.

Parameters
string$object_idThe id of the sorm object.
string$tableThe table name.
string$langOptional name of language.
Returns
int The number of deleted translations.

◆ removeTranslations()

removeTranslations ( )

Removes all translations for this I18NString object.

◆ setContentLanguage()

static setContentLanguage (   $language)
static

Sets the language the content is translated into.

Parameters
string$language

◆ setDefaultLanguage()

static setDefaultLanguage (   $language = null)
static

Sets the default language the content is translated into. The default is normally defined by the first entry in $GLOBALS'CONTENT_LANGUAGES'.

Parameters
string$language

◆ setLocalized()

setLocalized (   $text,
  $lang 
)

Sets the translation for the given language. If the given language is the default language, sets the original.

Parameters
type$textThe translated or original value.
type$langThe additional or default language.
Returns
string The translated or original value.
Exceptions
InvalidArgumentException

◆ setMetadata()

setMetadata (   $metadata)

Sets the metadata (database info for id, table, field) of this i18n field.

Parameters
array$metadataDatabase info for id, table, field.

◆ setOriginal()

setOriginal (   $text)

Sets the original (untranslated) value of this i18n field.

Parameters
string$textThe original value.
Returns
string The original value.

◆ setTranslations()

setTranslations (   $lang)

Sets all translations of this i18n field.

Parameters
array$langAn array with languages as keys and translations as values.
Returns
array The array with translations.

◆ storeTranslations()

storeTranslations ( )

Stores the i18n String manually in the database

◆ toArray()

toArray ( )

Return an array containing the text in all additional languages.

Returns
array The array with translations.

◆ translation()

translation (   $lang)

Return the string in the specified additional language.

Parameters
stringThe additional language.
Returns
string The translated value.

◆ trim()

trim (   $symbols = " \t\n\r\0\x0B")

Trim all language strings

Parameters
string$symbolsAll symbols to trim.
Returns
I18NString Returns this.

Field Documentation

◆ $base

$base
protected

◆ $content_language

$content_language = null
staticprotected

◆ $default_language

$default_language = null
staticprotected

◆ $lang

$lang
protected

◆ $metadata

$metadata
protected

The documentation for this class was generated from the following file: