Download the PHP package elao/form-translation-bundle without Composer
On this page you can find all versions of the php package elao/form-translation-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elao/form-translation-bundle
More information about elao/form-translation-bundle
Files in elao/form-translation-bundle
Package form-translation-bundle
Short Description Generate translation key for forms
License MIT
Homepage https://github.com/Elao/ElaoFormTranslationBundle
Informations about the package form-translation-bundle
ElaoFormTranslationBundle
Description:
This bundle provides a nice way of generating translation keys for form fields in a "logic" way. It is used mainly to generate automatic labels on fields but can be use to build any key.
For example, in a form RegisterType
named "register" the key for its field "name" would be form.register.children.name.label
.
Another more advanced example would be a field "emails" which is a collection
of text
inputs, it'll generate:
form.register.children.emails.label
form.register.children.emails.label_add
form.register.children.emails.label_delete
form.register.children.emails.children.prototype.label
Or in yml
:
Note: The keys will only be generated at runtime and won't be dumped when you use translation:update
yet (we're working on it).
Installation:
Add ElaoFormTranslationBundle to your composer.json:
Now download the bundle by running the command:
Register the bundle in the kernel:
How to use it:
In order to generate translation keys automatically, you have 2 options:
Per field generation:
If you set the the "label" option of a form field to true, a key will be generated and set as the field label. Otherwise we won't generate your labels !
Global configuration key:
If you want to generate keys for all your labels you can set the option auto_generate
to true
:
elao_form_translation:
auto_generate: true
This will set default label value to true
so keys will be generated for every label.
If you need to override this behavior, you can still provide a label
key for your field in order to use your translation key. In this case, no keys will be generated.
Customization and configuration:
Customize the keys:
Keys are built following this pattern:
[root][separator](parent_field_name)[separator][children][separator](field_name)[key]
You can customize (and remove) any of these tokens to change the way keys are built:
For example, if you just need simple keys you could do with the following configuration:
Which would generate that kind of keys:
# (parent_field_name)[separator](field_name)[separator][key]
register_name_label
Set default translation domain for all forms
You can set a default translation domain for all forms and choice with the following configuration:
This will set the default options translation_domain
and choice_translation_domain
to all forms and choices off your application.
You still can override these options in each configureOptions
method of your form types.
You can also disable translation on all form by setting the option to false
:
Default configuration:
All versions of form-translation-bundle with dependencies
symfony/framework-bundle Version ^5.4|^6.0|^7.0
symfony/form Version ^5.4|^6.0|^7.0
symfony/property-access Version ^5.4|^6.0|^7.0