2017 © Pedro Peláez
 

contao-module contao-translation-fields

Translation fields for Contao OpenSource CMS

image

icodr8/contao-translation-fields

Translation fields for Contao OpenSource CMS

  • Monday, June 19, 2017
  • by Craffft
  • Repository
  • 2 Watchers
  • 4 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 11 Versions
  • 3 % Grown

The README.md

Contao extension Translation Fields

What is Translation Fields?

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., (*1)

Dependencies

  • none

Troubleshooting

Directly on github! See https://github.com/Craffft/contao-translation-fields/issues, (*2)

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), (*3)

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, (*4)

Each field uses different settings. You can see this in the following codes., (*5)

Examples

Text Field

The original field:, (*6)

$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'text',
    'eval'                    => array('maxlength'=>255),
    'sql'                     => "varchar(255) NOT NULL default ''"
);
````

The field after the changes:

```php
$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'TranslationTextField',
    'eval'                    => array('maxlength'=>255),
    'sql'                     => "int(10) unsigned NOT NULL default '0'",
    'relation'                => array('type'=>'hasOne', 'load'=>'lazy')
);

Textarea Field

The original field:, (*7)

$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'textarea',
    'eval'                    => array('rte'=>'tinyMCE', 'tl_class'=>'long'),
    'sql'                     => "text NULL"
);

The field after the changes:, (*8)

$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'TranslationTextArea',
    'eval'                    => array('rte'=>'tinyMCE', 'tl_class'=>'long'),
    'sql'                     => "int(10) unsigned NOT NULL default '0'",
    'relation'                => array('type'=>'hasOne', 'load'=>'lazy')
);

Input Unit Field

The original field:, (*9)

$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'inputUnit',
    'options'                 => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
    'eval'                    => array('maxlength'=>200, 'tl_class'=>'w50'),
    'sql'                     => "blob NULL"
);

The field after the changes:, (*10)

$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
    'label'                   => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
    'exclude'                 => true,
    'inputType'               => 'TranslationInputUnit',
    'options'                 => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
    'eval'                    => array('maxlength'=>200, 'tl_class'=>'w50'),
    'sql'                     => "blob NULL",
    'relation'                => array('type'=>'hasOne', 'load'=>'lazy')
);

How to translate the field values

To translate the key from your current field, you can use the following methods, (*11)

Translate value

Translates the field key to the translation value in the current language., (*12)

$intId = '1485'; // Example value

$strTranslated = \TranslationFields::translateValue($intId);

echo $strTranslated; // Returns e.g. "Hi there!"

Optional you can add a force language to the translateValue method., (*13)

$intId = '1485'; // Example value
$strForceLanguage = 'de';

$strTranslated = \TranslationFields::translateValue($intId, $strForceLanguage);

echo $strTranslated; // Returns e.g. "Hallo zusammen!"

Translate DataContainer object

Translates all translation field values in the data container object to a translated value., (*14)

$objDC->exampleValue = '1485'; // Example value

$objDC = \TranslationFields::translateDCObject($objDC);

echo $objDC->exampleValue; // Returns e.g. "Hi there!"

Translate DCA

Translates all translation field values in the data container array to a translated value., (*15)

$arrDC['exampleValue'] = '1485'; // Example value

$arrDC = \TranslationFields::translateDCArray($arrDC, $strTable);

echo $arrDC['exampleValue']; // Returns e.g. "Hi there!"

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., (*16)

You can do this like in the following code:, (*17)

class MyApplicationRunconce extends \Controller
{
    // Code ...

    public function __construct()
    {
        parent::__construct();

        // Code ...

        // Load required translation-fields classes
        \ClassLoader::addNamespace('TranslationFields');
        \ClassLoader::addClass('TranslationFields\Updater', 'system/modules/translation-fields/classes/Updater.php');
        \ClassLoader::addClass('TranslationFields\TranslationFieldsWidgetHelper', 'system/modules/translation-fields/classes/TranslationFieldsWidgetHelper.php');
        \ClassLoader::addClass('TranslationFields\TranslationFieldsModel', 'system/modules/translation-fields/models/TranslationFieldsModel.php');
        \ClassLoader::register();
    }


    public function run()
    {
        // Code ...

        \TranslationFields\Updater::convertTranslationField('tl_my_table_name', 'my_field_name');

        // Code ...
    }

    // 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, (*18)

The Versions

19/06 2017

dev-master

9999999-dev http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

19/06 2017

1.7.0

1.7.0.0 http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

19/06 2017

dev-develop

dev-develop http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

11/06 2017

1.6.1

1.6.1.0 http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

29/01 2016

1.6.0

1.6.0.0 http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

24/05 2015

1.5.0

1.5.0.0 http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

20/02 2015

1.4.0

1.4.0.0 http://craffft.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

13/03 2014

1.3.3

1.3.3.0 http://daniel-kiesel.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

24/02 2014

1.3.2

1.3.2.0 http://daniel-kiesel.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

17/02 2014

1.3.1

1.3.1.0 http://daniel-kiesel.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields

16/02 2014

1.3.0

1.3.0.0 http://daniel-kiesel.de

Translation fields for Contao OpenSource CMS

  Sources   Download

LGPL-3.0+

The Requires

 

translation translate fields