Download the PHP package schachbulle/translation-fields-bundle without Composer
On this page you can find all versions of the php package schachbulle/translation-fields-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schachbulle/translation-fields-bundle
More information about schachbulle/translation-fields-bundle
Files in schachbulle/translation-fields-bundle
Package translation-fields-bundle
Short Description Übersetzungsfelder für Contao OpenSource CMS
License MIT
Homepage https://craffft.de
Informations about the package translation-fields-bundle
Contao 4 Translation Fields Bundle
Translation Fields is a library for Contao developers to get nice translation fields in the Contao Open Source CMS. Every translation field gets a language flag and can be translated by changing the flag to another language. The translations will be saved in the table tl_translation_fields and a key from this table will be stored in the field self.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
Documentation
Input types
There are three input types that you can use in the back end.
- TranslationTextField (the same as input type text)
- TranslationTextArea (the same as input type textarea)
- TranslationInputType (the same as input type inputType)
How to define a field in the DCA
To use the translation fields, you have to do the following changes in your DCA code.
- Add an index to your field
- Change the input type
- Change the sql to int(10)
- Add a relation to your field
Each field uses different settings. You can see this in the following codes.
Examples
Text Field
The original field:
`
The field after the changes:
Textarea Field
The original field:
The field after the changes:
Input Unit Field
The original field:
The field after the changes:
How to translate the field values
To translate the key from your current field, you can use the following methods
Translate value
Translates the field key to the translation value in the current language.
Optional you can add a force language to the translateValue method.
Translate DataContainer object
Translates all translation field values in the data container object to a translated value.
Translate DCA
Translates all translation field values in the data container array to a translated value.
Runonce
If you already have content in your application fields, you have to ensure that translation fields doesn't remove your content data. Therefore you have to create a runonce which inserts the current values into the tl_translation_fields table and associate the key with the field.
You can do this like in the following code:
E.g. you can have a look at the runconce.php from my extension Photoalbums2: https://github.com/Craffft/contao-photoalbums2/blob/master/config/runonce.php