<commit_before>Usage
=====

## Using translations

If you followed the [exmaple](getting-started.md) then translations will be automatically
loaded from the database for the current locale configured in the listener.

```php

$translatableListener->setCurrentLocale('en');

$post = $em->find('BlogPost', 1);
$post->getTitle(); // Title in English
```

To access translations in different locales, simply get them from the relation.
Translations are indexed by locale.

```php
// Direct access
$post->getTranslations()->get('de')->getTitle(); // Title in German

// Via the translate() helper from the example
$post->translate('fr')->getTitle(); // Title in French
```

## Querying translations

Translations are plain related entities. You can query them directly.

```php
// Search posts by title
$qb = $em->createQueryBuilder();
$qb->select('p')
   ->from('BlogPost', p)
   ->join('p.translations', 'pt', 'pt.locale = :locale')<commit_msg>Fix spelling<commit_after>Usage
=====

## Using translations

If you followed the [example](getting-started.md) then translations will be automatically
loaded from the database for the current locale configured in the listener.

```php

$translatableListener->setCurrentLocale('en');

$post = $em->find('BlogPost', 1);
$post->getTitle(); // Title in English
```

To access translations in different locales, simply get them from the relation.
Translations are indexed by locale.

```php
// Direct access
$post->getTranslations()->get('de')->getTitle(); // Title in German

// Via the translate() helper from the example
$post->translate('fr')->getTitle(); // Title in French
```

## Querying translations

Translations are plain related entities. You can query them directly.

```php
// Search posts by title
$qb = $em->createQueryBuilder();
$qb->select('p')
   ->from('BlogPost', p)
   ->join('p.translations', 'pt', 'pt.locale = :locale')
{'fraction_non_alphanumeric': 0.15311004784688995, 'fraction_numerical': 0.001063264221158958, 'mean_word_length': 4.918238993710692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6760078', 'n_tokens_mistral': 563, 'n_tokens_neox': 527, 'n_words': 190}