PHP Class RainLab\Translate\Classes\TranslatableBehavior

Author: Alexey Bobkov, Samuel Georges
Inheritance: extends October\Rain\Extension\ExtensionBase
ファイルを表示 Open project: rainlab/translate-plugin Class Usage Examples

Protected Properties

Property Type Description
$model Reference to the extended model.
$requiredProperties {@inheritDoc}
$translatableAttributes Data store for translated attributes.
$translatableContext Active language for translations.
$translatableDefault Default system language.
$translatableOriginals Data store for original translated attributes.
$translatableUseFallback Determines if empty translations should be replaced by default values.

Public Methods

Method Description
__construct ( October\Rain\Database\Model $model ) Constructor
getAttributeTranslated ( string $key, string $locale = null ) : string Returns a translated attribute value.
getTranslatableAttributes ( ) : array Returns a collection of fields that will be hashed.
getTranslatableAttributesWithOptions ( ) : array Returns the defined options for a translatable attribute.
getTranslateAttribute ( $key, $locale = null )
getTranslateAttributes ( string $locale ) : array Returns all translated attribute values.
getTranslateDirty ( $locale = null ) : array Get the translated attributes that have been changed since last sync.
hasTransatableAttributes ( ) : true Checks if this model has transatable attributes.
hasTranslation ( string $key, string $locale ) : boolean Returns whether the attribute is translatable (has a translation) for the given locale.
initTranslatableContext ( ) : void Initializes this class, sets the default language code to use.
isTranslatable ( string $key ) : boolean Checks if an attribute should be translated or not.
isTranslateDirty ( string | null $attribute = null, $locale = null ) : boolean Determine if the model or a given translated attribute has been modified.
lang ( string $context = null ) : self Shorthand for translateContext method, and chainable.
noFallbackLocale ( ) : self Disables translation fallback locale.
setAttributeTranslated ( string $key, string $value, $locale = null ) : string Sets a translated attribute value.
setTranslateAttribute ( $key, $value, $locale = null )
syncTranslatableAttributes ( ) : void Restores the default language values on the model and stores the translated values in the attributes table.
translateContext ( string $context = null ) : void Changes the active language for this model

Protected Methods

Method Description
getAttributeFromData ( mixed $data, string $attribute ) : mixed Extracts a attribute from a model/array with nesting support.
loadTranslatableData ( string $locale = null ) : array Loads the translation data from the model.
setAttributeFromData ( mixed &$data, string $attribute, $value ) : mixed Sets an attribute from a model/array with nesting support.
storeTranslatableData ( string $locale = null ) : void Saves the translation data for the model.

Method Details

__construct() public method

Constructor
public __construct ( October\Rain\Database\Model $model )
$model October\Rain\Database\Model The extended model.

getAttributeFromData() protected method

Extracts a attribute from a model/array with nesting support.
protected getAttributeFromData ( mixed $data, string $attribute ) : mixed
$data mixed
$attribute string
return mixed

getAttributeTranslated() public method

The base value must come from 'attributes' on the model otherwise the process can possibly loop back to this event, then method triggered by __get() magic.
public getAttributeTranslated ( string $key, string $locale = null ) : string
$key string
$locale string
return string

getTranslatableAttributes() public method

Returns a collection of fields that will be hashed.
public getTranslatableAttributes ( ) : array
return array

getTranslatableAttributesWithOptions() public method

Returns the defined options for a translatable attribute.

getTranslateAttribute() public method

Deprecation: getTranslateAttribute is deprecated, use getAttributeTranslated instead.
public getTranslateAttribute ( $key, $locale = null )

getTranslateAttributes() public method

Returns all translated attribute values.
public getTranslateAttributes ( string $locale ) : array
$locale string
return array

getTranslateDirty() public method

Get the translated attributes that have been changed since last sync.
public getTranslateDirty ( $locale = null ) : array
return array

hasTransatableAttributes() public method

Checks if this model has transatable attributes.
public hasTransatableAttributes ( ) : true
return true

hasTranslation() public method

Returns whether the attribute is translatable (has a translation) for the given locale.
public hasTranslation ( string $key, string $locale ) : boolean
$key string
$locale string
return boolean

initTranslatableContext() public method

Initializes this class, sets the default language code to use.
public initTranslatableContext ( ) : void
return void

isTranslatable() public method

Checks if an attribute should be translated or not.
public isTranslatable ( string $key ) : boolean
$key string
return boolean

isTranslateDirty() public method

Determine if the model or a given translated attribute has been modified.
public isTranslateDirty ( string | null $attribute = null, $locale = null ) : boolean
$attribute string | null
return boolean

lang() public method

Shorthand for translateContext method, and chainable.
public lang ( string $context = null ) : self
$context string
return self

loadTranslatableData() abstract protected method

Loads the translation data from the model.
abstract protected loadTranslatableData ( string $locale = null ) : array
$locale string
return array

noFallbackLocale() public method

Disables translation fallback locale.
public noFallbackLocale ( ) : self
return self

setAttributeFromData() protected method

Sets an attribute from a model/array with nesting support.
protected setAttributeFromData ( mixed &$data, string $attribute, $value ) : mixed
$data mixed
$attribute string
return mixed

setAttributeTranslated() public method

Sets a translated attribute value.
public setAttributeTranslated ( string $key, string $value, $locale = null ) : string
$key string Attribute
$value string Value to translate
return string Translated value

setTranslateAttribute() public method

Deprecation: setTranslateAttribute is deprecated, use setAttributeTranslated instead.
public setTranslateAttribute ( $key, $value, $locale = null )

storeTranslatableData() abstract protected method

Saves the translation data for the model.
abstract protected storeTranslatableData ( string $locale = null ) : void
$locale string
return void

syncTranslatableAttributes() public method

Restores the default language values on the model and stores the translated values in the attributes table.
public syncTranslatableAttributes ( ) : void
return void

translateContext() public method

Changes the active language for this model
public translateContext ( string $context = null ) : void
$context string
return void

Property Details

$model protected_oe property

Reference to the extended model.
protected $model

$requiredProperties protected_oe property

{@inheritDoc}
protected $requiredProperties

$translatableAttributes protected_oe property

Data store for translated attributes.
protected $translatableAttributes

$translatableContext protected_oe property

Active language for translations.
protected $translatableContext

$translatableDefault protected_oe property

Default system language.
protected $translatableDefault

$translatableOriginals protected_oe property

Data store for original translated attributes.
protected $translatableOriginals

$translatableUseFallback protected_oe property

Determines if empty translations should be replaced by default values.
protected $translatableUseFallback