简体   繁体   中英

Rails Twitter Bootstrap Tooltip localization

I am using Twitter-Bootstrap Tooltips and I want to know if there is a way or best practice of localize them? eg: 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.

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) %>

UPDATE

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM