Closed peter-gribanov closed 7 years ago
@peter-gribanov
You have a problem with encoding your php files.
I've pasted your texts to my configureListFields
and everything is fine.
config:
->add('user', null, array(
'route' => array('name' => 'show'),
'label' => 'Включена',
))
@axzx the problem not in a encoding.
SonataAdminBundle
.This code worked for 2 years until your update came out.
If i change labels
class BroadcastAdmin extends BaseAdmin
{
// ...
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('type', null, ['label' => 'Что-то'])
->add('enabled', null, ['label' => 'Еще что-то', 'editable' => true])
;
}
}
then i see this
If i move labels to translation file
class BroadcastAdmin extends BaseAdmin
{
// ...
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('type', null, ['label' => 'something'])
->add('enabled', null, ['label' => 'something_else', 'editable' => true])
;
}
}
# messages.ru.yml
something: 'Что-то'
something_else: 'Еще что-то'
# config.yml
framework:
translator: { fallbacks: [ 'ru' ] }
I see this:
This problem not in my code.
I have tested your configuration and it works fine for me.
In messages.ru.yml
should be:
# messages.ru.yml
Something: 'Что-то'
Something Else: 'Еще что-то'
No. In messages.ru.yml
should be:
# messages.ru.yml
app:
broadcast:
fields:
something: 'Что-то'
something_else: 'Еще что-то'
@peter-gribanov Could you please check if this PR https://github.com/sonata-project/SonataAdminBundle/pull/4617 fixes your issue?
@jlamur Unfortunately this did not fix the problem. Label breaks somewhere before.
@peter-gribanov do you use a different naming strategy than the default one?
can you check if it works fine with the default naming strategy?
The problem in LabelTranslatorStrategy
:
var_dump($fieldDescription->getLabel());
var_dump($this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getLabel(), 'list', 'label'));
@OskarStark I did not change the naming strategy.
@OskarStark
$this->admin->getLabelTranslatorStrategy() instanceof \Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy // true
@OskarStark It looks like it's still something on my side
public function getLabel($label, $context = '', $type = '')
{
ob_clean();
var_dump($label);
$label = str_replace(array('_', '.'), ' ', $label);
$label = preg_replace('/(?<=\\w)([A-Z])/', '_$1', $label);
var_dump($label);
var_dump(strtolower($label));
var_dump(mb_strtolower($label));
return trim(ucwords(str_replace('_', ' ', $label)));
}
Sounds interesting 🤔
I think that the problem with the locale.
var_dump(setlocale(LC_ALL, 0));
mb_detect_order('UTF8,CP1251,ASCII');
var_dump(mb_detect_encoding($label));
var_dump(mb_detect_encoding(strtolower($label)));
string(78) "LC_COLLATE=C;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C"
string(5) "UTF-8"
string(12) "Windows-1251"
But it's strange, because in sonata-project/admin-bundle 3.20.0
everything is fine.
@OskarStark did you change the default naming strategy?
No we didn't change anything related to the naming strategy.
We name everything here: https://github.com/sonata-project/SonataAdminBundle/releases
I see this change https://github.com/sonata-project/SonataAdminBundle/commit/1b1d4b47d95daec7b4ebe8675cf6befce1d496ac If you specify a label, it is always transformed.
It broke BC. And now i'm forced to redefine the default transformer to NoopLabelTranslatorStrategy
to be sure that everything works as before.
Could you add a failing test here with your configuration, so that we can fix it?
@peter-gribanov https://github.com/sonata-project/SonataAdminBundle/pull/4621 could you check it?
@axzx Yes. But your change does not make sense in this way.
I do not really understand that you tried to achieve changes like this #4602. Perhaps this is the right change. Just need to warn users that you are breaking BC.
By the way, what am I doing wrong?
I change configuration:
sonata_admin:
admin_services:
label_translator_strategy: 'sonata.admin.label.strategy.native'
and cache error
Invalid type for path "sonata_admin.admin_services.label_translator_strategy". Expected array, but got string
If i change it to array
sonata_admin:
admin_services:
label_translator_strategy: [ 'sonata.admin.label.strategy.native' ]
I see this:
Unrecognized option "0" under "sonata_admin.admin_services.label_translator_strategy"
Why do you set it?
'sonata.admin.label.strategy.native'
is a default value
Excuse me. Of course, sonata.admin.label.strategy.noop
sonata_admin:
admin_services:
label_translator_strategy: [ 'sonata.admin.label.strategy.noop' ]
sonata_admin:
admin_services:
<service id>:
label_translator_strategy: 'sonata.admin.label.strategy.noop'
@axzx that is, is it the same that i will specify the service tag attribute?
admin.broadcast:
class: BroadcastAdmin
arguments: [ ~, Broadcast, ~ ]
tags:
- { name: sonata.admin, manager_type: orm, label: 'admin.menu.broadcast.broadcast', label_translator_strategy: 'sonata.admin.label.strategy.noop'}
Apparently the documentation lagged behind reality. https://sonata-project.org/bundles/admin/3-x/doc/reference/configuration.html
yes, the same solution
the problem is in the last two updated versions.
The field 'label' in list not should have translator strategy, because the user must put what he wants, for example
with this implementation the spanish accents no works.
The code is in the file listmapper.php on line 120:
if ($fieldDescription->getLabel() === null) {
$fieldDescription->setOption(
'label',
$this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label')
);
} elseif ($fieldDescription->getLabel() !== false) {
$fieldDescription->setOption(
'label',
$this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getLabel(), 'list', 'label')
);
}
i propose change the code before for the next solution:
if (($label = $fieldDescription->getLabel()) !== false && !$label) {
$fieldDescription->setOption(
'label',
$this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label')
);
}
regards
@peter-gribanov @jxamorro
https://github.com/sonata-project/SonataAdminBundle/pull/4621/files could you check it now?
@axzx yes. that's better
I asked for a release, stay tuned 👍
Environment
Sonata packages
Symfony packages
PHP version
Subject
After updating to the latest version i found that the field labels in list are broken.
Steps to reproduce
Example admin class
Expected results
In
sonata-project/admin-bundle 3.20.0
Actual results
What i saw after the update:
In
sonata-project/admin-bundle 3.21.0
In
sonata-project/admin-bundle 3.22.0