PHPackages                             craffft/contao-translation-fields - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. craffft/contao-translation-fields

AbandonedArchivedContao-module[Localization &amp; i18n](/categories/localization)

craffft/contao-translation-fields
=================================

Translation fields for Contao OpenSource CMS

2.0.0(6y ago)42.7k[1 issues](https://github.com/Craffft/contao-translation-fields/issues)4LGPL-3.0+PHPPHP &gt;=5.6

Since Feb 16Pushed 6y ago2 watchersCompare

[ Source](https://github.com/Craffft/contao-translation-fields)[ Packagist](https://packagist.org/packages/craffft/contao-translation-fields)[ Docs](http://craffft.de)[ RSS](/packages/craffft-contao-translation-fields/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (12)Used By (4)

Contao extension Translation Fields
===================================

[](#contao-extension-translation-fields)

What is 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.

Dependencies
------------

[](#dependencies)

- none

Troubleshooting
---------------

[](#troubleshooting)

Directly on github! See

Documentation
=============

[](#documentation)

Input types
-----------

[](#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
--------------------------------

[](#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

[](#examples)

#### Text Field

[](#text-field)

The original field:

```
$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:

```
$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

[](#textarea-field)

The original field:

```
$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:

```
$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

[](#input-unit-field)

The original field:

```
$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:

```
$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
---------------------------------

[](#how-to-translate-the-field-values)

To translate the key from your current field, you can use the following methods

### Translate value

[](#translate-value)

Translates the field key to the translation value in the current language.

```
$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.

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

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

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

### Translate DataContainer object

[](#translate-datacontainer-object)

Translates all translation field values in the data container object to a translated value.

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

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

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

### Translate DCA

[](#translate-dca)

Translates all translation field values in the data container array to a translated value.

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

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

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

Runonce
-------

[](#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:

```
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:

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~219 days

Recently: every ~377 days

Total

10

Last Release

2493d ago

Major Versions

1.7.0 → 2.0.02019-07-12

PHP version history (2 changes)1.3.0PHP &gt;=5.3.2

1.7.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/7bb19a9412cab30e88d3c7c95b054d0b05c4497ac759d2bd4a3f137139437a13?d=identicon)[Craffft](/maintainers/Craffft)

---

Tags

translatetranslationfields

### Embed Badge

![Health badge](/badges/craffft-contao-translation-fields/health.svg)

```
[![Health](https://phpackages.com/badges/craffft-contao-translation-fields/health.svg)](https://phpackages.com/packages/craffft-contao-translation-fields)
```

###  Alternatives

[whitecube/lingua

A PHP language codes converter, from and to the most common formats (ISO, W3C, PHP and human-readable names).

441.2M15](/packages/whitecube-lingua)[skillshare/formatphp

Internationalize PHP apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.

8029.6k](/packages/skillshare-formatphp)[om/potrans

Command line tool for translate Gettext with Google Translator API or DeepL API

10515.0k4](/packages/om-potrans)[fisharebest/localization

A lightweight localization database and translation tools, with data from the CLDR, IANA, ISO, etc.

3191.1k2](/packages/fisharebest-localization)[diversen/simple-php-translation

simple solution for doing translation, extracting translations, and doing auto translation through google

227.8k1](/packages/diversen-simple-php-translation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
