0

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:

enter image description here

Community
  • 1
  • 1
ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • Do `.js` files get actually loaded? – Jovan Perovic Nov 18 '14 at 10:02
  • @JovanPerovic yes, they are loaded – ReynierPM Nov 18 '14 at 13:15
  • Check out your Javascript console for error messages - put them here – sjagr Nov 18 '14 at 13:22
  • @sjagr there is no errors at all, see the image I leave on the main post – ReynierPM Nov 18 '14 at 13:32
  • Try running `Translator.trans` with those parameters in your question directly in the console. What does it return? – sjagr Nov 18 '14 at 13:44
  • @sjagr this is the output `"mensaje.msgAgregarSatisfactorio"` – ReynierPM Nov 18 '14 at 13:45
  • Is this a typo? `mensajes.msgAgregarSatisfactorio`? You're shuffling `mensaje` and `mensajes` between your `add` and `trans` functions. See: `Translator.add("mensajes.msgAgregarSatisfactorio"` and `Translator.trans('mensaje.msgAgregarSatisfactorio',` – sjagr Nov 18 '14 at 13:46
  • @sjagr yes, you're right, so simple and I was looking for a bigger error under my code, that's happen to me all the time when I'm writing code at 2AM or 3AM, thanks, if you like answer the question and I'll give your points, once again – ReynierPM Nov 18 '14 at 13:52
  • No problem! I'm actually putting a vote in to close the question since it was determined as a typo. It's not a bad thing - it's just that the question is unlikely to help anyone in the future. No need to delete the question though - there's no penalty to you. – sjagr Nov 18 '14 at 13:57

1 Answers1

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");
sjagr
  • 15,983
  • 5
  • 40
  • 67