Download the PHP package liip/formtranslationchoice-bundle without Composer
On this page you can find all versions of the php package liip/formtranslationchoice-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download liip/formtranslationchoice-bundle
More information about liip/formtranslationchoice-bundle
Files in liip/formtranslationchoice-bundle
Package formtranslationchoice-bundle
Short Description A Symfony2 bundle that provides a form choice and a validation constraint that work with translation domains.
License MIT
Informations about the package formtranslationchoice-bundle
FormTranslationChoiceBundle
UNMAINTAINED
This bundle is no longer maintained. Feel free to fork it if needed.
This Symfony2 bundle provides a form choice field type and a validation constraint that work with translation domains. You can use all strings of a translation domain as values for a field of your entity. The form stores the translation key in the field.
For example, we use it with an entity Person
that has a field title
. We use
a translation domain person_title
and maintain all possible titles a person
can have (Mr, Ms, Prof, Dr, and so on) in the translation file. The entity
stores the translation key and the title can thus be translated as needed. We
could even change Mr to Mister without need to change the database.
This does not replace a choice field that links to another entity. But for simple cases like the above example, you might not want to build an admin interface and store such options in the database.
Installation
Composer will ask you for the version of the bundle you want to install.
Chose 1.0.*
unless you want to lock on a more specific version.
Enable the bundle
Load the bundle in your kernel:
Due to the Symfony2 translator not exposing the translation domains, you need to use the extended translator provided by this bundle. Add the following to your project configuration file:
Usage
This bundle provides a form widget translation_choice
and a validation
constraint TranslationDomainKey
that operate on a whole translation domain.
Warning: When using this, you want to make sure you have complete translation for the used domain, or none at all. This bundle does not merge different languages, but does fall back to the default language if the requested language does not exist.
translation_choice Form Field Type
The translation_choice
field type is based on the core choice
and provides
all translations of the specified domain as choices. You can use the options of
the standard Symfony2 choice field type.
It makes no sense to specify the choice or choice_list argument though, as they
come from the translation domain.
To select the translation domain to use, the translation_domain
option is
required.
By default, the request locale is used, but you can set the locale
option if
you need to override this.
By default the values are sorted alphabetically. If you don't want them to be sorted use the `sorted' option set to false.
Validation constraint
This bundle provides a validation constraint that ensures that a field has a value that is a key in the specified translation domain. As with all validators, this validator accepts null and empty string as well, so you additionally want a NotBlank validation if empty values should not be allowed.
License
This bundle is licensed under the MIT license. Please see the file LICENSE for more.