BazingaJsTranslationBundle 不翻译字符串 [英] BazingaJsTranslationBundle does not translate strings
问题描述
我正在尝试使用 BazingaJsTranslationBundle 来提前进行 Symfony2 翻译.阅读文档后,这就是我所做的:
I'm trying to use BazingaJsTranslationBundle for take advance of Symfony2 translations. After read docs this is what I've done:
包含需要的 JS 库
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>
config.yml
中的设置包:
bazinga_js_translation:
locale_fallback: "%locale%"
default_domain: AppBundle
使用 bazinga supply 命令转储翻译:
Dump translations using the bazinga supply command:
Symfony > bazinga:js-translation:dump
Installing translation files in /var/www/html/sencamer.dev/web/js directory
开始在 JS 文件中使用翻译:
Start using translations in JS files:
Translator.trans('mensaje.msgAgregarSatisfactorio', {"pronombre": "la", "elemento": "solicitud"}, 'AppBundle')
这是来自 AppBundle.es.yml
的原始字符串:
where this is the original string from AppBundle.es.yml
:
msgAgregarSatisfactorio: Se ha creado %pronombre% %elemento% satisfactoriamente.
这是 web\js\translations\AppBundle\es.js
Translator.add("mensajes.msgAgregarSatisfactorio", "Se ha creado %pronombre% %elemento% satisfactoriamente.", "AppBundle", "es");
执行该代码时,我得到未翻译的字符串:mensaje.msgAgregarSatisfactorio
但没有消息,为什么?怎么了?本主题与 这个不知何故,有什么建议吗?
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?
如图所示,控制台上没有 Javascript 错误,文件也已加载,我认为它的格式很好:
As this image shows, there are no Javascript errors on console and also file is loaded and I think it's well formed:
推荐答案
你的 trans
函数有一个拼写错误:
You have a typo in your trans
function:
Translator.trans('mensaje.msgAgregarSatisfactorio', {"pronombre": "la", "elemento": "solicitud"}, 'AppBundle')
因为您尝试访问的消息使用了 mensajes
参考:
since the message you're trying to access uses the mensajes
reference:
Translator.add("mensajes.msgAgregarSatisfactorio", "Se ha creado %pronombre% %elemento% satisfactoriamente.", "AppBundle", "es");
这篇关于BazingaJsTranslationBundle 不翻译字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!