Trait TranslateStrategyTrait
Contains common code needed by TranslateBehavior strategy classes.
Property Summary
- 
        $locale protectedstring|nullThe locale name that will be used to override fields in the bound table from the translations table 
- 
        $table protectedCake\ORM\TableTable instance 
- 
        $translationTable protectedCake\ORM\TableInstance of Table responsible for translating 
Method Summary
- 
          afterSave() publicUnsets the temporary _i18nproperty after the entity has been saved
- 
          buildMarshalMap() publicBuild a set of properties that should be included in the marshalling process. 
- 
          getLocale() publicReturns the current locale. 
- 
          getTranslationTable() publicReturn translation table instance. 
- 
          setLocale() publicSets the locale to be used. 
- 
          unsetEmptyFields() protectedUnset empty translations to avoid persistence. 
Method Detail
afterSave() ¶ public
afterSave(Cake\Event\EventInterface $event, Cake\Datasource\EntityInterface $entity): voidUnsets the temporary _i18n property after the entity has been saved
Parameters
- 
                Cake\Event\EventInterface$event
- The beforeSave event that was fired 
- 
                Cake\Datasource\EntityInterface$entity
- The entity that is going to be saved 
Returns
voidbuildMarshalMap() ¶ public
buildMarshalMap(Cake\ORM\Marshaller $marshaller, array $map, array $options): arrayBuild a set of properties that should be included in the marshalling process.
Add in _translations marshalling handlers. You can disable marshalling
of translations by setting 'translations' => false in the options
provided to Table::newEntity() or Table::patchEntity().
Parameters
- 
                Cake\ORM\Marshaller$marshaller
- The marhshaller of the table the behavior is attached to. 
- 
                array$map
- The property map being built. 
- 
                array$options
- The options array used in the marshalling call. 
Returns
arrayA map of [property => callable] of additional properties to marshal.
getLocale() ¶ public
getLocale(): stringReturns the current locale.
If no locale has been explicitly set via setLocale(), this method will return
the currently configured global locale.
Returns
stringSee Also
\Cake\ORM\Behavior\TranslateBehavior::setLocale()
getTranslationTable() ¶ public
getTranslationTable(): Cake\ORM\TableReturn translation table instance.
Returns
Cake\ORM\TablesetLocale() ¶ public
setLocale(string|null $locale): $thisSets the locale to be used.
When fetching records, the content for the locale set via this method, and likewise when saving data, it will save the data in that locale.
Note that in case an entity has a _locale property set, that locale
will win over the locale set via this method (and over the globally
configured one for that matter)!
Parameters
- 
                string|null$locale
- The locale to use for fetching and saving records. Pass - nullin order to unset the current locale, and to make the behavior fall back to using the globally configured locale.
Returns
$thisunsetEmptyFields() ¶ protected
unsetEmptyFields(Cake\Datasource\EntityInterface $entity): voidUnset empty translations to avoid persistence.
Should only be called if $this->_config['allowEmptyTranslations'] is false.
Parameters
- 
                Cake\Datasource\EntityInterface$entity
- The entity to check for empty translations fields inside. 
Returns
voidProperty Detail
$locale ¶ protected
The locale name that will be used to override fields in the bound table from the translations table
Type
string|null