Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
drewchandler opened this issue Mar 13, 2013 · 2 comments

Comments

@drewchandler
Copy link

<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
Copy link
Owner

berk commented Jul 21, 2013

It should work in master.

@AfzalMasood11
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants