# Static Translation

---

## TLDR

```twig
{# aa_trans tag in twig templates #}
{{ 'key'|aa_trans }} {{ 'template.footer_intro'|aa_trans }} {{ 'blipblop'|aa_trans({'%var%': 'bonk'}) }}
```

Then, use `php bin/console aa:static-translation:generate` and run doctrine migrations using `php bin/console do:mi:mi`

---

## Introduction

Permit to translate & administrate strings integrated in templates.
Usefull even if site is not multilingual, to permit to non-technical people to administrate template/email static
strings.

## Principle

Use default Symfony translation concepts, but with a custom loader trying first to find key in database then a fallback
behavior passing the asked key to standard symfony translation systems.

Existing keys are maintained using doctrine migrations.

## Usage in twig

Tags will be parsed in templates, so try to respect this syntax regarding spaces.

Signature respects Symfony Translation "|trans" twig signature.

First arg is translation parameters
Second arg is domain (default is 'messages')

```twig

<p>{{ 'template.my_footer_header_1'|aa_trans }}</p>

<p>{{ 'template.my_footer_header_2'|aa_trans({'%myparam%': 'My Param Value'}, 'footer') }}</p>

<p>{{ 'email.subject'|aa_trans({}, 'email') }}</p>

```

## Usage in PHP

Service used to translate static
texts: [AutoAdmin\Bundle\Content\Provider\TranslationProvider](../../src/Content/Provider/TranslationProvider.php)

```php

use AutoAdmin\Bundle\Content\Provider\TranslationProvider

// [...]

protected TranslationProvider $translator;

// [...]

```

## Usage regarding migrations

Static text keys evolution must be set using migrations.
The following command handle migration file creation. File must be committed with project.

```bash
# first generate migration file

php bin/console aa:static-translation:generate

# then migrate

php bin/console doctrine:migrations:migrate

```

## Programatically created keys

Warning: Keys created and used only using a php file won't be resolved using the command above.

In order to handle those keys, a dummy template is existing in /templates/static_texts.html.twig

Here we can write programmatically-created keys that will be handled by the migration system
(that is only reading templates).


## Lock locale

Locale can be locked to force translating for one given locale when context is setup for another one.

For example when sending a mail using FR but triggered on EN locale.

cf. AutoAdmin\Bundle\Content\Provider\TranslationProvider