PHPackages                             barthy-koeln/cached-prezent-translation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. barthy-koeln/cached-prezent-translation

AbandonedArchivedLibrary[Localization &amp; i18n](/categories/localization)

barthy-koeln/cached-prezent-translation
=======================================

Provides a trait to be used with prezent/translatable-bundle

1.0.1(3y ago)390MITPHPPHP ^7.4|^8.1CI failing

Since Nov 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/barthy-koeln/cached-prezent-translation)[ Packagist](https://packagist.org/packages/barthy-koeln/cached-prezent-translation)[ Docs](https://github.com/BarthyB/cached-prezent-translation)[ GitHub Sponsors](https://github.com/barthy-koeln)[ RSS](/packages/barthy-koeln-cached-prezent-translation/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Cached Translation
==================

[](#cached-translation)

[![CircleCI](https://camo.githubusercontent.com/ad1d72e782d10dd65eea8bfd973c1fb34b7715d26a6db42baa92b1598b968efd/68747470733a2f2f636972636c6563692e636f6d2f67682f6261727468792d6b6f656c6e2f6361636865642d7072657a656e742d7472616e736c6174696f6e2e7376673f7374796c653d73766726636972636c652d746f6b656e3d35356461333766363839356539393764353435623935343861626463323266353461646563626235)](https://circleci.com/gh/barthy-koeln/cached-prezent-translation)[![Coverage](https://camo.githubusercontent.com/32d5e20a43bfca70c1557686ca38f08f81a07269066e1dffaec7ac6d34b0692f/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d68747470732533412532462532466261646765732e6261727468792e6b6f656c6e25324662616467652532466361636865642d7072657a656e742d7472616e736c6174696f6e253246636f766572616765)](https://circleci.com/gh/barthy-koeln/cached-prezent-translation/tree/master)

This library provides a simple trait that can be used with the [`prezent/doctrine-translatable-bundle`](https://github.com/Prezent/doctrine-translatable-bundle).

This is mostly a copy-pasted php trait from the [`prezent/doctrine-translatable` docs about proxy getters and setters](https://github.com/Prezent/doctrine-translatable/blob/master/doc/getting-started.md#proxy-getters-and-setters), adapted for php &gt;= 7.4 and opinionated code styles.

The trait stores the current locale, fallback locale, and caches the last fetched translation.

Usually, only one translation is necessary for an app: the current locale's translation or the fallback translation. Since `prezent/translatable-bundle` uses [`FETCH_EXTRA_LAZY`](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/extra-lazy-associations.html), the cached translation does not trigger any additional straight SELECT statements if queried from the object multiple times.

In a situation where more than one translation is needed (i.e. multiple translations must be loaded for the application, it is best to either manually fully initialise the collection or to handle caching yourself.

Installation
------------

[](#installation)

```
composer require barthy-koeln/cached-prezent-translation
```

Usage
-----

[](#usage)

### Entity

[](#entity)

```
