berk / tr8n

This repository has moved to:
https://github.com/tr8n/tr8n
MIT License
279 stars 37 forks source link

Can not use the same translation more than once using the javascript sdk. #56

Open drewchandler opened 11 years ago

drewchandler commented 11 years ago
<div id="messages">
</div>
<%= javascript_tag do %>
  $(function() {
    $('#messages').append('<div>' + tr('Hello, {name}!', '', {name: 'Drew'}) + '</div>');
    $('#messages').append('<div>' + tr('Hello, {name}!', '', {name: 'Ben'}) + '</div>');
  });
<% end %>

Results in something like:

<div id="messages">
  <div>
    <tr8n id="65a7cdb2df7d1b465201213a6f0c377e" translation_key_id="2">
      <tr8n translation_key_id="2" id="65a7cdb2df7d1b465201213a6f0c377e">
        Ciao, Drew!
      </tr8n>
    </tr8n>
  </div>
  <div>
    <tr8n id="65a7cdb2df7d1b465201213a6f0c377e">
      Hello, Ben!
    </tr8n>
  </div>
</div>

As you can see, only the first one is translated.

The md5 of the key and description is used as an id for a tr8n element. The above example will result in 2 elements with the same id. In the javascript, when the translations come back from the server, since we find elements needing translations using the id, we will only see the first element.

berk commented 11 years ago

It should work in master.

AfzalMasood11 commented 10 years ago

@berk @drewchandler How I can translate Javascript strings?

I have following one option regarding javascript in config.yml which I have already enabled. enable_client_sdk: true # allows javascript to use tr8nProxy object

When I try to translate any javascript string like: taskNames = -> d = new Date() weekday = new Array(7) weekday[0] = tr("Sunday") weekday[1] = tr("Monday") weekday[2] = tr("Tuesday") weekday[3] = tr("Wednesday") weekday[4] = tr("Thursday") weekday[5] = tr("Friday") weekday[6] = tr("Saturday") Then tr8n adds keys for all above weekdays but does not translate these days.

Any Idea?