實現你想要的最簡單的方法是更改翻譯消息。
如果您確實想更改標籤,您可以實施自己的標籤生成策略。
namespace Blast\CoreBundle\Translator;
use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
/**
* Class LibrinfoLabelTranslatorStrategy.
*
* Provides a specific label translation strategy for Librinfo.
* It is based on UnderscoreLabelTranslatorStrategy, but without the context,
* and labels are prefixed by "librinfo.label."
*
* i.e. isValid => librinfo.label.is_valid
*/
class LibrinfoLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
{
/**
* {@inheritdoc}
*/
public function getLabel($label, $context = '', $type = '')
{
$label = str_replace('.', '_', $label);
return sprintf('%s.%s.%s', "librinfo", $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
}
}
把它定義爲一個服務
blast_core.label.strategy.librinfo:
class: Blast\CoreBundle\Translator\LibrinfoLabelTranslatorStrategy
然後將它傳遞給你的管理服務的定義,像這樣:
你將擁有管理員的完全控制標籤
另請參閱:SonataAdmin: replace ID in breadcrumbs
如果只是想修改標籤的翻譯,而不是它們的結構,就可以了'SonataAdminBundle :: standard_layout.html內覆蓋'sonata_breadcrumb'塊.twig'模板。爲'label' var放置正確的翻譯域,並在其中翻譯標籤。 –
嗯,我是奏鳴曲的新手,你有沒有例子? –
ps。我不想翻譯「名單」,但「測試產品」 正確breacrumb是 儀表板/產品/產品列表 或 儀表板/產品列表/產品列表 –