2

I have a DOM element that is created via ajax something like this:

$('.inner').append('<p>Salva Foto</p>');

my Twig is composed

{% javascripts
***my js***
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

<script type="text/javascript" src="{{ asset('bundles/bazingaexposetranslation/js/translator.min.js') }}"></script>
<script type="text/javascript" src="{{ url('bazinga_exposetranslation_js') }}"></script>

my locale is it, and in my bundle i have messages.en.yml (I tried with .xlf) with:

Salva Foto: Save Photo

Of the Default Locale is it, now I'm trying the translation for the English language

if I look at the files uploaded from my browser, I see a javascript file: en and contains

Translator.locale = 'en';
Translator.defaultDomains = ["messages"];
Translator.add("messages:Salva Foto", "Save Photo");

but the paragraph created via javascript is not translated

Barno
  • 3,271
  • 5
  • 28
  • 58

1 Answers1

1

In your JS you must use the Object Translator created with Bazinga. If you try

<script type="text/javascript">
    alert(Translator.get("messages:Salva Foto"));
</script>

on your dialog box you see

Save Photo
Ephraim
  • 260
  • 1
  • 6
  • 15
  • 1
    Note that the bundle has been refactored, and the JS Translator now implements the same interface as in PHP. Read this for more information: https://github.com/willdurand/BazingaJsTranslationBundle/blob/master/UPGRADE.md#from-1x-to-20. – William Durand Jan 12 '14 at 00:26