2lenet / crudit-translation-provider
Symfony Translation Provider backed by crudit-studio (crudit:// DSN).
Package info
github.com/2lenet/CruditTranslationProvider
Type:symfony-bundle
pkg:composer/2lenet/crudit-translation-provider
Requires
- php: ^8.2
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/http-client: ^6.4 || ^7.0 || ^8.0
- symfony/translation: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0
- slevomat/coding-standard: ^8.13
- squizlabs/php_codesniffer: ^3.7
README
Symfony Translation Provider backed by crudit-studio:
your project's translations are centrally managed in crudit-studio, and synchronized with the
standard translation:pull / translation:push commands — exactly like the official Loco,
Crowdin or Lokalise providers, through a crudit:// DSN.
Installation
composer require 2lenet/crudit-translation-provider
If your app doesn't use Symfony Flex, register the bundle in config/bundles.php:
Lle\CruditTranslationProvider\LleCruditTranslationProviderBundle::class => ['all' => true],
Configuration
Declare the provider in config/packages/translation.yaml:
framework: translator: providers: crudit: dsn: '%env(CRUDIT_TRANSLATION_DSN)%' domains: [] # empty = all domains locales: [] # empty = your app's enabled_locales
And set the DSN in your .env.local:
CRUDIT_TRANSLATION_DSN=crudit://PROJECT_CODE:TOKEN@crudit-studio.example.com
PROJECT_CODE— your project'scodein crudit-studio,TOKEN— the project's API token,- host (and optional port) of your crudit-studio instance, reached over HTTPS.
For a local crudit-studio over plain HTTP, add ?scheme=http:
CRUDIT_TRANSLATION_DSN=crudit://PROJECT_CODE:TOKEN@localhost:8328?scheme=http
Usage
# Send local translations to crudit-studio. # crudit-studio NEVER overwrites a key it already knows (it may have been edited # by a translator through its UI), so pushing is always safe. bin/console translation:push crudit # Fetch translations from crudit-studio into your local files bin/console translation:pull crudit --force
Initial migration
There is no dedicated init command: the very first translation:push crudit against an empty
crudit-studio project uploads your whole local catalogue (every key, locale and domain) and
becomes the starting point managed in crudit-studio.
Translation file formats
The provider itself never reads or writes files — it exchanges message catalogues with the standard Symfony commands, which handle the local files:
translation:pushloads your local files through Symfony's registered loaders, so every format supported by the Translation component works out of the box: YAML, XLIFF, JSON, PHP, CSV, INI, gettext (.po/.mo), Qt XML (.ts), ResourceBundle...translation:pullwrites local files in the format you ask for with--format(XLIFF 1.2 by default):
bin/console translation:pull crudit --force --format=yaml
Not supported
translation:push --delete-missing (the provider delete() operation) is not supported yet:
for now, crudit-studio is the authority and keys are removed through its UI. We are looking
into supporting this option in the near future.
Development
composer install vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpstan analyse