14

I have started new with the sonata admin bundle. its very handy and easy to setup and use , but i can't seem to get the translation fixed for the default labels

e.g link_add, link_list are coming instead of proper english labels.

#SonataAdmin
    sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts: [admin]
        sonata.block.service.text:
        sonata.block.service.rss:

sonata_admin:
    title:      Sonata Project
    title_logo: /bundles/sonataadmin/logo_title.png
    templates:
        # default global templates
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig

        # default actions templates, should extend a global templates
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    SonataAdminBundle:CRUD:edit.html.twig

    dashboard:
        blocks:
            # display a dashboard block
            - { position: left, type: sonata.admin.block.admin_list }

This is my config file and these are the basic default settings provided by the documentation. what am i missing here to enable labels for the default view params ? can anybody help

2 Answers 2

25

for translate menu and forms override file: SonataAdminBundle.[your_language].xliff(with content from: vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Resources/translations/SonataAdminBundle.[your_language].xliff), put file in:

app/Resource/SonataAdminBundle/translations/

full path:

app/Resource/SonataAdminBundle/translations/SonataAdminBundle.[your_language].xliff

If you want to translate your labels for field, you must create translate file in your bundle, for example:

src/YourAlias/YourNameOfBundle/Resources/translations/YourAliasYourNameOfBundle.[your_language].xliff

if your Admin class is in

src/YourAlias/YourNameOfBundle/Admin/YourClassAdmin.php

Sonata use FOSUserBundle and if you want change translation for users module, you must ovverride file: FOSUserBundle.[your_language].yml in:

app/Resource/FOSUSerBundle/translations/FOSUserBundle.[your_language].yml

and analogously for SonataUserBundle

I use that configuration and everything works!

7
  • but how to enable the default translation from the translation files sonata admin bundle already has with it . the labels generated by sonata bundle are not working . they are showing the default twig parameters. any suggestions about that ?
    – satin
    Mar 19, 2013 at 6:31
  • 27
    in config.yml: framework: # ... translator: { fallback: %locale% } and paramaters: locale: [your_laguage] in parameters.yml.
    – mkjasinski
    Mar 19, 2013 at 9:28
  • Hello @mkjasinski, I override app/Resource/SonataAdminBundle/translations/SonataAdminBundle.es.xliff and new translation, about breadcrumb. This is my code, but no working: <trans-unit id="breadcrumb.link_categorias_list"> <source>breadcrumb.link_categorias_list</source> <target>Listado Categorias</target> </trans-unit> Can you please help me?
    – jcarlosweb
    Oct 7, 2014 at 21:05
  • thanks @mkjasinski , I did, but I still appears Categories List, when should appear "Listado Categorias"
    – jcarlosweb
    Oct 7, 2014 at 21:12
  • Please read this sonata-project.org/bundles/admin/master/doc/reference/….
    – mkjasinski
    Oct 7, 2014 at 21:16
10

Expanding on @mkjasinski's comment above, the Symfony Translation component expects to find a _locale property on the request. If this is missing, or no translation can be found for the specified locale, it uses a fallback value. However this fallback value is also blank by default hence seeing the translation labels instead of text.

To fix this, set the default translation locale by adding the following to config.yml:

framework:
  #...
  translator:
    fallback: %locale%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.