Reputation: 540
I am using Twitter-Bootstrap Tooltips and I want to know if there is a way or best practice of localize them? e.g.: in config/locales
My setup is:
Gemfile
gem 'twitter-bootstrap-rails', '~> 2.1.3'
bootstrap.js.coffee
jQuery ->
$('#plugin_description').tooltip({'trigger':'hover', 'title': 'ToolTip Text'})
Tooltips work fine, but is there a way to load the strings from config/locales? That would really be awesome :)
Update: I want to use the tooltip with input fields in a form. Right now I have it like this:
= f.input :name
and call it with:
$('#application_name').tooltip({
'placement':'top',
'trigger':'hover',
'title': 'has to be unique and between 4 an 20 signs'})
but I couldn't find a way to localize the title attribute.
Upvotes: 1
Views: 1157
Reputation: 2518
The tooltip can take text from a link's title attribute, so internationalize your text there :
<%= link_to 'hover over me', '#', :id => 'plugin_description', :title => t(:tooltip_title) %>
You just supply the tooltip text with the data-title
attribute.
In your JS:
$('.form-tooltip').tooltip({
'placement':'top',
'trigger':'hover'
});
Note that there is no title
argument.
In your view :
= text_field_tag :name, '', :class => 'form-tooltip', :data => {:title => t(:'your.translation.key')}
It looks like you're using formatastic or simple_form so you'll need to adapt your view accordingly to generate the data-title
attribute.
Upvotes: 1