You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the deprecated ChoiceList the options are translatable, when moving the our choice lists to the new ArrayChoiceList, the options are no longer translatable.
Current code
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use JMS\TranslationBundle\Model\Message;
abstract class TranslatableArrayChoiceList extends ArrayChoiceList
{
// @todo Move to a new domain
const TRANSLATION_DOMAIN = 'messages';
public static function getTranslatableChoices()
{
throw new \RuntimeException('No translation choices found');
}
/**
* Extractable status translation labels.
*/
public static function getTranslationMessages()
{
$messages = array();
foreach (static::getTranslatableChoices() as $choice) {
$message = new Message($choice, static::TRANSLATION_DOMAIN);
$message->setMeaning('Item for a dropdown select list.'); // Extra metadata for the translator
$messages[] = $message;
}
return $messages;
}
}
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
class EmailPrivacyChoiceList extends TranslatableArrayChoiceList implements TranslationContainerInterface
{
public function __construct()
{
parent::__construct(self::getTranslatableChoices());
}
public static function getTranslatableChoices()
{
return [
'emails with this contact are not private' => false,
'emails with this contact are private' => true
];
}
Previous code
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
abstract class TranslatableChoiceList extends ChoiceList
{
const TRANSLATION_DOMAIN = 'messages';
public static function getTranslatableChoices()
{
throw new \RuntimeException('No translation choices found');
}
/**
* Extractable status translation labels.
*/
public static function getTranslationMessages()
{
$messages = array();
foreach (static::getTranslatableChoices() as $choice) {
$message = new Message($choice, static::TRANSLATION_DOMAIN);
$message->setMeaning('Item for a dropdown select list.'); // Extra metadata for the translator
$messages[] = $message;
}
return $messages;
}
}
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
class EmailPrivacyChoiceList extends TranslatableChoiceList implements TranslationContainerInterface
{
public function __construct()
{
parent::__construct([false, true], self::getTranslatableChoices());
}
public static function getTranslatableChoices()
{
return [
'emails with this contact are not private',
'emails with this contact are private'
];
}
}
The text was updated successfully, but these errors were encountered:
Had another go at this and this time I seem to got something right, no longer an issue. I used the choice_loader option by implementing ChoiceLoaderInterface on the TranslatableArrayChoiceList (with some other small code changes).
Expected behavior
Using the deprecated
ChoiceList
the options are translatable, when moving the our choice lists to the newArrayChoiceList
, the options are no longer translatable.Current code
Previous code
The text was updated successfully, but these errors were encountered: