[英]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? 我正在使用Twitter-Bootstrap工具提示,我想知道是否有一种方法或最佳实践来对它们进行本地化? eg: in config/locales 例如:在config / locales中
My setup is: 我的设置是:
Gemfile 宝石文件
gem 'twitter-bootstrap-rails', '~> 2.1.3'
bootstrap.js.coffee 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? 工具提示可以正常工作,但是有没有办法从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. 但我找不到本地化title属性的方法。
The tooltip can take text from a link's title attribute, so internationalize your text there : 工具提示可以从链接的title属性中获取文本,因此可以在此处将文本国际化:
<%= link_to 'hover over me', '#', :id => 'plugin_description', :title => t(:tooltip_title) %>
You just supply the tooltip text with the data-title
attribute. 您只需为工具提示文本提供data-title
属性。
In your JS: 在您的JS中:
$('.form-tooltip').tooltip({
'placement':'top',
'trigger':'hover'
});
Note that there is no title
argument. 请注意,没有title
参数。
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. 看起来您正在使用formatastic或simple_form,因此您需要相应地调整视图以生成data-title
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.