Chapters
36 Chapters
|
2:42:17
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3.10.0", // 3.10.0
"doctrine/doctrine-bundle": "^2.15", // 2.15.0
"doctrine/doctrine-migrations-bundle": "^3.4.2", // 3.4.2
"doctrine/orm": "^3.5.0", // 3.5.0
"league/commonmark": "^2.7.1", // 2.7.1
"symfony/asset": "7.3.*", // v7.3.0
"symfony/asset-mapper": "7.3.*", // v7.3.0
"symfony/console": "7.3.*", // v7.3.1
"symfony/crowdin-translation-provider": "7.3.*", // v7.3.0
"symfony/dotenv": "7.3.*", // v7.3.0
"symfony/flex": "^2.8.1", // v2.8.1
"symfony/framework-bundle": "7.3.*", // v7.3.1
"symfony/runtime": "7.3.*", // v7.3.1
"symfony/stimulus-bundle": "^2.28", // v2.28.0
"symfony/translation": "7.3.*", // v7.3.1
"symfony/twig-bundle": "7.3.*", // v7.3.1
"symfony/yaml": "7.3.*", // v7.3.1
"symfonycasts/object-translation-bundle": "@dev", // dev-_tuts/bundle/3-install-our-bundle
"symfonycasts/tailwind-bundle": "^0.10.1", // v0.10.1
"twig/extra-bundle": "^2.12|^3.21", // v3.21.0
"twig/markdown-extra": "^3.21", // v3.21.0
"twig/string-extra": "^3.21", // v3.21.0
"twig/twig": "^2.12|^3.21.1" // v3.21.1
},
"require-dev": {
"phpunit/phpunit": "^9.6.23", // 9.6.23
"symfony/browser-kit": "7.3.*", // v7.3.0
"symfony/css-selector": "7.3.*", // v7.3.0
"symfony/debug-bundle": "7.3.*", // v7.3.0
"symfony/maker-bundle": "^1.64", // v1.64.0
"symfony/monolog-bundle": "^3.10", // v3.10.0
"symfony/phpunit-bridge": "^7.3.1", // v7.3.1
"symfony/stopwatch": "7.3.*", // v7.3.0
"symfony/web-profiler-bundle": "7.3.*", // v7.3.1
"zenstruck/browser": "^1.9.1", // v1.9.1
"zenstruck/foundry": "^2.6.1" // v2.6.1
}
}
5 Comments
Hi Kevin,
Could you please explain how to implement a FormType that can be used in an admin interface (for example, EasyAdmin)?
I can create a form for editing existing translations, but how should I handle creating a new translation for a given object? I need a way to retrieve the type and ID of the passed object - which TranslatableMappingManager handles - but this class isn't autowirable and is marked as internal.
I'm a bit confused.... Maybe I'm missing something?
Thanks
Davide
Davide,
I've created a PR to add a FormType to the bundle and some docs on integrating with EasyAdmin.
Hi Davide,
You're not missing anything.
TranslatableMappingManageris internal on purpose, and until now there wasn't a public way to do this. I just released v1.2.0, which adds aTranslationManagerservice for exactly this case. It's autowirable and works with the object directly, so you never deal with the type/id yourself.Creating and editing work the same way. The form below always has every translatable field for the given locale, prefilled where a translation already exists and empty where it doesn't. Filling in an empty field creates the translation, because
saveTranslationsFor()upserts. To add a whole new language, open the same form with a new$locale.A rough sketch: an unmapped form with one field per translatable property, prefilled with the existing values:
In EasyAdmin you could wire this up as a custom action on your CRUD controller.
translatableTypes()lists all your translatable classes if you want something generic, andtranslationStatusFor()is handy for showing which fields still need translating.Let me know how it goes!
Kevin
Version 1.2.0 is not yet available on https://packagist.org/packages/symfonycasts/object-translation-bundle
Could you please check this?
Thanks for reporting. Fixed now.
"Houston: no signs of life"
Start the conversation!