This package provides a Sulu admin panel for managing your website translations.
The package includes a custom Symfony translation provider which stores your translations in a database.
sulu-translations-bundle-demo.mov
composer require phpro/sulu-translations-bundleMake sure the bundle is activated in config/bundles.php:
Phpro\SuluTranslationsBundle\SuluTranslationsBundle::class => ['all' => true]You need to manually register the failed queue admin controller routes in the file config/routes_admin.yaml.
# config/routes_admin.yaml
phpro_translations:
resource: '@SuluTranslationsBundle/Presentation/Controller/Admin'
type: attribute
prefix: /admin/apiRegister an additional module in your admin's node dependencies via assets/admin/package.json:
{
"dependencies": {
"sulu-translations-bundle": "file:../../vendor/phpro/sulu-translations-bundle/assets/admin"
}
}Make sure to load the additional node module in your admin's assets/admin/index.js or assets/admin/app.js file:
import 'sulu-translations-bundle';cd /app/assets/admin
npm install
npm run watchYou have to add the database provider to the Symfony translator configuration. This is an example configuration for the config/packages/translation.yaml file.
# config/packages/translation.yaml
framework:
translator:
providers:
phpro_database:
dsn: 'database://default'
domains: [ 'messages' ]
locales: [ 'en', 'fr', 'nl' ]The hostname in the DSN is actually your Doctrine DBAL connection name: database://<dbal_connection_name>.
If you want to store your translations in a separate database (preferred), you could configure a new DBAL connection and use the connection name in the DSN of the database translation provider.
If you are using your default DBAL connection you probably want to configure doctrine.dbal.schema_filter so your migrations doesn't try to drop the phpro_translations table.
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
schema_filter: '/^(?!(other_prefix_|phpro_translations))/'If you want to export your translations via the administrator panel, you should define the format or extension which is used for your translation files.
# config/packages/sulu_translations.yaml
sulu_translations:
export_format: 'csv'Make sure you've set the correct permissions in the Sulu admin for this package. Go to Settings > User Roles and enable the permissions (phpro_translations) you need. Afterwards you could find the translations view/panel via Settings > Manage translations.
First make sure the database table phpro_translations is created by running the command below.
bin/console phpro:sulu-translations:setupIf you don't have local translations files (e.g. CSV) you can generate them by using the command below.
bin/console translation:extract --force --domain=messages --format=csv <locale>Once you have local translation files, you can export them to the database by using command below.
bin/console translation:push phpro_database Next you can update the translations via the Sulu admin panel.
Once you are done, you can export the translations back to the translations files by using the command below or clicking the Export translations button via the Sulu admin panel.
bin/console translation:pull phpro_database --force --format csvAfter pulling the translations, you may need to clear the cache(s).
bin/console cache:clear
bin/websiteconsole cache:clearUsing AI to autocomplete missing translations is a real time-saver and can help you to quickly fill in the gaps in your translations.
If you are using the Sulu AI bundle or platform, you can use the AI translation feature to automatically translate your content. This feature is automatically enabled if you have the Sulu AI bundle installed and configured.
Only tested and used with CSV and YAML format.