BazingaJsTranslationBundle does not translate strings

北城余情 提交于 2019-12-11 14:55:32

问题


I'm trying to use BazingaJsTranslationBundle for take advance of Symfony2 translations. After read docs this is what I've done:

  1. Include needed JS libraries

    <script src="{{ asset('bundles/bazingajstranslation/js/translator.min.js') }}"></script>
    // Tried this way
    <script src="{{ url('bazinga_jstranslation_js', { 'domain': 'AppBundle' }) }}"></script>
    
    // Also tried this one
    <script src="{{ url('bazinga_jstranslation_js') }}"></script>
    
  2. Setup bundle at config.yml:

    bazinga_js_translation:
        locale_fallback:      "%locale%"
        default_domain:       AppBundle
    
  3. Dump translations using the bazinga supply command:

    Symfony > bazinga:js-translation:dump
    Installing translation files in /var/www/html/sencamer.dev/web/js directory
    
  4. Start using translations in JS files:

    Translator.trans('mensaje.msgAgregarSatisfactorio', {"pronombre": "la", "elemento": "solicitud"}, 'AppBundle')
    

    where this is the original string from AppBundle.es.yml:

    msgAgregarSatisfactorio: Se ha creado %pronombre% %elemento% satisfactoriamente.
    

    and this is the dump translation at web\js\translations\AppBundle\es.js

    Translator.add("mensajes.msgAgregarSatisfactorio", "Se ha creado %pronombre% %elemento% satisfactoriamente.", "AppBundle", "es");
    

When that code is executed I get the untranslated string: mensaje.msgAgregarSatisfactorio but not the message, why? What's wrong? This topic is related to this one in somehow, any advice?

As this image shows, there are no Javascript errors on console and also file is loaded and I think it's well formed:


回答1:


You have a typo in your trans function:

Translator.trans('mensaje.msgAgregarSatisfactorio', {"pronombre": "la", "elemento": "solicitud"}, 'AppBundle')

since the message you're trying to access uses the mensajes reference:

Translator.add("mensajes.msgAgregarSatisfactorio", "Se ha creado %pronombre% %elemento% satisfactoriamente.", "AppBundle", "es");


来源:https://stackoverflow.com/questions/26987149/bazingajstranslationbundle-does-not-translate-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!