问题
I'm trying to use BazingaJsTranslationBundle for take advance of Symfony2 translations. After read docs this is what I've done:
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>Setup bundle at
config.yml:bazinga_js_translation: locale_fallback: "%locale%" default_domain: AppBundleDump translations using the bazinga supply command:
Symfony > bazinga:js-translation:dump Installing translation files in /var/www/html/sencamer.dev/web/js directoryStart 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.jsTranslator.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