CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.0 Strawberry API

  • Overview
  • Version:
    • 4.0
      • 4.0
      • 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

  • 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

Interface TranslateStrategyInterface

This interface describes the methods for translate behavior strategies.

Namespace: Cake\ORM\Behavior\Translate

Method Summary

  • afterSave() public

    Unsets the temporary _i18n property after the entity has been saved

  • beforeFind() public

    Callback method that listens to the beforeFind event in the bound table. It modifies the passed query by eager loading the translated fields and adding a formatter to copy the values into the main table records.

  • beforeSave() public

    Modifies the entity before it is saved so that translated fields are persisted in the database too.

  • 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.

  • groupTranslations() public

    Modifies the results from a table find in order to merge full translation records into each entity under the _translations key

  • setLocale() public

    Sets the locale to be used.

  • translationField() public

    Returns a fully aliased field name for translated fields.

Method Detail

afterSave() public

¶

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

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

beforeFind() public

¶

beforeFind(\Cake\Event\EventInterface $event, \Cake\ORM\Query $query, \ArrayObject $options)

Callback method that listens to the beforeFind event in the bound table. It modifies the passed query by eager loading the translated fields and adding a formatter to copy the values into the main table records.

Parameters
\Cake\Event\EventInterface $event

The beforeFind event that was fired.

\Cake\ORM\Query $query

Query

\ArrayObject $options

The options for the query

beforeSave() public

¶

beforeSave(\Cake\Event\EventInterface $event, \Cake\Datasource\EntityInterface $entity, \ArrayObject $options)

Modifies the entity before it is saved so that translated fields are persisted in the database too.

Parameters
\Cake\Event\EventInterface $event

The beforeSave event that was fired

\Cake\Datasource\EntityInterface $entity

The entity that is going to be saved

\ArrayObject $options

the options passed to the save method

buildMarshalMap() public

¶

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

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

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

A map of [property => callable] of additional properties to marshal.

getLocale() public

¶

getLocale()

Returns the current locale.

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

Returns
string

getTranslationTable() public

¶

getTranslationTable()

Return translation table instance.

Returns
\Cake\ORM\Table

groupTranslations() public

¶

groupTranslations(mixed $results)

Modifies the results from a table find in order to merge full translation records into each entity under the _translations key

Parameters
\Cake\Datasource\ResultSetInterface $results

Results to modify.

Returns
\Cake\Collection\CollectionInterface

setLocale() public

¶

setLocale(?string $locale)

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

translationField() public

¶

translationField(string $field)

Returns a fully aliased field name for translated fields.

If the requested field is configured as a translation field, field with an alias of a corresponding association is returned. Table-aliased field name is returned for all other fields.

Parameters
string $field

Field name to be aliased.

Returns
string