bluerail / twitter-bootstrap-rails-confirm

Confirm dialogs using Twitter Bootstrap
https://bluerail.nl
MIT License
85 stars 34 forks source link

Not easy to translate #2

Closed gdlx closed 11 years ago

gdlx commented 11 years ago

Hi !

This gem is great but I see one single problem : it's not really easy to translate since it's necessary to set translated strings on each single link.

Would it be possible to override default values once for all confirm boxes ?

Thanks !

rvanlieshout commented 11 years ago

Thank you for your feedback.

I like your idea. Could you try the version in master and judge if it suits your needs? If so I'll release 0.5 as a gem.

gdlx commented 11 years ago

What a quick answer ! I'll try right now. I just have to find where to put the JS snippet to use Rails i18n for default strings (probably in a JS tag in a partial).

gdlx commented 11 years ago

I've just tried and it works fine, except that I think you should specify that defaults must be overrriden once DOM is loaded. My technique has been to create a _bootstrap_confirm_defaults.js.erb partial :

<%= javascript_tag do %>
  $(document).ready(function(){
    $.fn.twitter_bootstrap_confirmbox.defaults = {
      title: document.title,
      cancel: <%= t('global.cancel').to_json.html_safe %>,
      proceed: <%= t('global.confirm').to_json.html_safe %>,
      proceed_class: "btn proceed btn-primary"
    };
  });
<% end %>

And include it in my main layout header like this (after static JS inclusion):

= render partial: 'layouts/bootstrap_confirm_defaults.js'
rvanlieshout commented 11 years ago

Right on! 0.5 released. Have fun with it :)

gdlx commented 11 years ago

Great, thanks ! I don't see anything else to change in your gem : keep it simple ;o)