ems-project / elasticms

ElasticMS's monorepo
MIT License
3 stars 8 forks source link

refactor(core): extract translations #916

Closed Davidmattei closed 3 months ago

Davidmattei commented 3 months ago
Q A
Bug fix? n
New feature? n
BC breaks? n
Deprecations? n
Fixed tickets? n
Documentation? n

We can now correctly extract all keys from or code and start using translatable object or method in php files. We should not use dynamic keys in twig or php (see toasts.html.twig), we can also use a select inside the translation.

The extracted translations are in the icu format (https://symfony.com/doc/5.x/reference/formats/message_format.html) For the core only the domain 'emsco-core' is now in this format because:

In the previous translation format, placeholders were often wrapped in % (e.g. %name%). This % character is no longer valid with the ICU MessageFormat syntax, so you must rename your parameters if you are upgrading from the previous format.

In next pr's we will slowly migrate the core translations to new domains that are build with the script.

Anywhere in the code we can now use, and it will be extracted.

<?php
use Symfony\Component\Translation\TranslatableMessage;
use function Symfony\Component\Translation\t;

t('example', [], 'emsco-core');

// or

$label = new TranslatableMessage('example', [], 'emsco-core');

Important we can not use constants for defining the domain, the extractor will not find this key.

Also with the build script we can easly change the format from yml to xliff or reverse