[英]How to properly translate strings in SonataAdminBundle
I am trying to translate some Sonata Admin - list page - strings using .xliff
file inside my bundle. 我正在尝试使用捆绑包内的
.xliff
文件来翻译一些Sonata管理员列表页面字符串。 Those strings belongs to my bundle and not to Sonata so this are the steps I have follow: 这些字符串属于我的捆绑包,而不属于Sonata,所以这是我遵循的步骤:
Create a .xliff
file under: src/Clanmovil/PlatformBundle/Resources/translations/PlatformBundle.es.xliff
as follow: 在
src/Clanmovil/PlatformBundle/Resources/translations/PlatformBundle.es.xliff
下创建一个.xliff
文件,如下所示:
<?xml version="1.0"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="PlatformBundle.en.xliff" > <body> <trans-unit id="name"> <source>name</source> <target>Nombre</target> </trans-unit> <trans-unit id="description"> <source>description</source> <target>Descripción</target> </trans-unit> <trans-unit id="active"> <source>active</source> <target>Activo?</target> </trans-unit> </body> </file> </xliff>
Setup label
property under src/Clanmovil/PlatformBundle/Controller/Admin/CategoryAdmin.php
as follow: 在
src/Clanmovil/PlatformBundle/Controller/Admin/CategoryAdmin.php
下设置label
属性,如下所示:
class CategoryAdmin extends Admin { ... // Fields to be shown on lists protected function configureListFields(ListMapper $listMapper) { $listMapper ->add('name', null, array( 'label' => 'name' )) ->add('active', null, array( 'label' => 'active' )); ... } ... }
Setup app/config/config.yml
as follow: 设置
app/config/config.yml
如下:
parameters: locale: es framework: #esi: ~ translator: { fallbacks: ["%locale%"] } default_locale: "%locale%" ....
And is not working I am still seeing name
and active
strings on list page and I don't know what I am missing. 而且不起作用,我仍然在列表页面上看到
name
和active
字符串,并且我不知道自己缺少什么。 I have read several posts as this , this and many more. 我已经阅读了几篇有关this , this和更多内容的文章。 Can any give me some advice?
能给我一些建议吗?
Since the previous issue was fixed with the answer provided but this is almost the same I decide to edit the OP than create a new one so here we go. 由于上一期的内容已通过提供的答案解决,但几乎相同,因此我决定编辑OP而不是创建一个新的OP,因此我们继续。 Take a look to the following setup for SonataAdmin:
看一下SonataAdmin的以下设置:
sonata_admin:
dashboard:
groups:
configuration:
icon: <i class="fa fa-lg fa-fw fa fa-folder"></i>
label: configuration
items:
- sonata.admin.category
- sonata.admin.command
- sonata.admin.alias
And this is the definition of those services at Clanmovil/PlatformBundle/Resources/config/services.yml
: 这是
Clanmovil/PlatformBundle/Resources/config/services.yml
中这些服务的定义:
services:
sonata.admin.alias:
class: Clanmovil\PlatformBundle\Controller\Admin\AliasAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Configuration", label: "alias" }
arguments:
- ~
- Clanmovil\PlatformBundle\Entity\Alias
- ~
sonata.admin.category:
class: Clanmovil\PlatformBundle\Controller\Admin\CategoryAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Configuration", label: "category" }
arguments:
- ~
- Clanmovil\PlatformBundle\Entity\Category
- ~
sonata.admin.command:
class: Clanmovil\PlatformBundle\Controller\Admin\CommandAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Configuration", label: "command" }
arguments:
- ~
- Clanmovil\PlatformBundle\Entity\Command
- ~
But strings configuration
, command
and category
(for now) aren't translated, see pic below: 但是字符串
configuration
, command
和category
(目前)尚未翻译,请参见下图:
Why? 为什么? Those translations are on the same file as the
alias
one. 这些翻译与
alias
一个在同一个文件中。 What could be happening here? 这里会发生什么?
You have to specify translation domain explicitly, if you create your translations files different than messages
. 如果您创建的翻译文件不同于
messages
,则必须明确指定翻译域。 messages
is the default translation domain. messages
是默认的翻译域。 You have two options, rename your PlatformBundle.es.xliff
to messages.es.xliff
or specify tranlation domain. 您有两个选择,可以将
PlatformBundle.es.xliff
重命名为messages.es.xliff
或指定翻译域。 example: 例:
In form types: 在表单类型中:
...
$builder->add('name', 'text', ['translation_domain' => 'PlatformBundle']);
...
in twig trmplates: 在树枝上mpl:
{{ 'name'|trans({}, 'PlatformBundle') }}
I don't know what is the ListMapper
class, but there should be support (I guess) for translation domains also. 我不知道
ListMapper
类是什么,但是翻译域也应该有支持(我想)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.