PHP code example of schachbulle / translation-fields-bundle
1. Go to this page and download the library: Download schachbulle/translation-fields-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
schachbulle / translation-fields-bundle example snippets
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Craffft\TranslationFieldsBundle\CraffftTranslationFieldsBundle(),
);
// ...
}
// ...
}
$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 ''"
);
$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')
);
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'textarea',
'eval' => array('rte'=>'tinyFlash', 'tl_class'=>'long'),
'sql' => "text NULL"
);
$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'=>'tinyFlash', 'tl_class'=>'long'),
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
);
$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"
);
$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')
);
$intId = '1485'; // Example value
/* @var $objTranslator Translator */
$objTranslator = \System::getContainer()->get('craffft.translation_fields.service.translator');
$strTranslated = $objTranslator->translateValue($intId);
echo $strTranslated; // Returns e.g. "Hi there!"
$intId = '1485'; // Example value
$strForceLanguage = 'de';
/* @var $objTranslator Translator */
$objTranslator = \System::getContainer()->get('craffft.translation_fields.service.translator');
$strTranslated = $objTranslator->translateValue($intId, $strForceLanguage);
echo $strTranslated; // Returns e.g. "Hallo zusammen!"
$objDC->exampleValue = '1485'; // Example value
/* @var $objTranslator Translator */
$objTranslator = \System::getContainer()->get('craffft.translation_fields.service.translator');
$objDC = $objTranslator->translateDCObject($objDC);
echo $objDC->exampleValue; // Returns e.g. "Hi there!"
$arrDC['exampleValue'] = '1485'; // Example value
/* @var $objTranslator Translator */
$objTranslator = \System::getContainer()->get('craffft.translation_fields.service.translator');
$arrDC = $objTranslator->translateDCArray($arrDC, $strTable);
echo $arrDC['exampleValue']; // Returns e.g. "Hi there!"
class MyApplicationRunconce extends \Controller
{
public function run()
{
// Code ...
\Craffft\TranslationFieldsBundle\Util\Updater::convertTranslationField('tl_my_table_name', 'my_field_name');
// Code ...
}
// Code ...
}