CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.2 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Trait TranslateStrategyTrait

Contains common code needed by TranslateBehavior strategy classes.

Namespace: Cake\ORM\Behavior\Translate

Property Summary

  • $locale protected
    string|null

    The locale name that will be used to override fields in the bound table from the translations table

  • $table protected
    Cake\ORM\Table

    Table instance

  • $translationTable protected
    Cake\ORM\Table

    Instance of Table responsible for translating

Method Summary

  • afterSave() public

    Unsets the temporary _i18n property after the entity has been saved

  • buildMarshalMap() public

    Build a set of properties that should be included in the marshalling process.

  • getLocale() public

    Returns the current locale.

  • getTranslationTable() public

    Return translation table instance.

  • setLocale() public

    Sets the locale to be used.

  • unsetEmptyFields() protected

    Unset empty translations to avoid persistence.

Method Detail

afterSave() ¶ public

afterSave(Cake\Event\EventInterface $event, Cake\Datasource\EntityInterface $entity): void

Unsets 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
void

buildMarshalMap() ¶ public

buildMarshalMap(Cake\ORM\Marshaller $marshaller, array $map, array $options): array

Build 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
array

getLocale() ¶ public

getLocale(): string

Returns the current locale.

If no locale has been explicitly set via setLocale(), this method will return the currently configured global locale.

Returns
string
See Also
\Cake\I18n\I18n::getLocale()
\Cake\ORM\Behavior\TranslateBehavior::setLocale()

getTranslationTable() ¶ public

getTranslationTable(): Cake\ORM\Table

Return translation table instance.

Returns
Cake\ORM\Table

setLocale() ¶ public

setLocale(string|null $locale): $this

Sets 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 null in order to unset the current locale, and to make the behavior fall back to using the globally configured locale.

Returns
$this

unsetEmptyFields() ¶ protected

unsetEmptyFields(Cake\Datasource\EntityInterface $entity): void

Unset 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
void

Property Detail

$locale ¶ protected

The locale name that will be used to override fields in the bound table from the translations table

Type
string|null

$table ¶ protected

Table instance

Type
Cake\ORM\Table

$translationTable ¶ protected

Instance of Table responsible for translating

Type
Cake\ORM\Table
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs