DatatablesBundle icon indicating copy to clipboard operation
DatatablesBundle copied to clipboard

Field title and value translations, data transformers

Open speto opened this issue 8 years ago • 3 comments

I'm lacking the way how to translate title and value of specific column more automatically. Is there any way how to achieve this? Currently the value part I'm doing via line formatter, but I think it's not optimal way, mainly when you have more columns and at all translating is not formatting of output.

Let's consider I have field which can or have to contains one value from array of string values (tuple) you can imagine it like

['new', 'accepted', 'rejected', 'ordered']

or

$choices = [
    "skill.beginner",
    "skill.elementary",
    "skill.intermediate",
    "skill.upper_intermediate",
    "skill.advanced",
    "skill.proficiency",
]

This tuples can be stored in some config rather than in DB. Input for this values can be ChoiceType.

And after all I have specific translations for this values and would like to see at the end translated values. Solution could be to add new translatable option in column definition and when it is true translate it's value:

$this->columnBuilder
    ->add('status', 'column', array(
        'title' => 'status',
        'searchable' => true,
        'orderable' => true,
        'default' => 'default status value',
        'translatable' => true,
    ))
;

to avoid formatter like:

public function getLineFormatter()
    {
        return function($item){
            $item['status'] = $this->translator->trans($item['status']);
            return $item;
        };
    }

Or possibly it could be achieved by new column type as well.

I also saw use cases like this, when translating is repeating in all field titles:

->add('date', 'datetime', array(
    'title' => $this->translator->trans('Date'),
))

It will be nicer to have option on whole datatable like:

public function buildDatatable(array $options = array())
    {
        $this->options->setOption('translate_titles', true);

or translate titles automatically like it is done in symfony forms:

there are 2 Twig filters (trans and transChoice) that are used for translating form labels, errors, option text and other strings

But this idea also brings some complications which include ordering and filtering of translated values (maybe searching too). Any suggestions how to move on with this? What do you think about the option to add data transformers for column values.

speto avatar Oct 28 '16 20:10 speto

Thanks, I look at this when I implement the translation for 1.0.

stwe avatar Oct 30 '16 09:10 stwe

These are great suggestions, have they been implemented?

mshd avatar Sep 30 '19 14:09 mshd

No, yesterday I found some old pottery fragments from the Stone Age in the garden. Now I have to put them together first.

stwe avatar Oct 04 '19 13:10 stwe