Rails 2.3.4 中新增了 Ticket #745
的对应。虽说暂时还是open的状态,但从补丁已经完成的情况看,确实如此。
这个增加填补了Rails 2.2.2 中引入的国际化(I18n)模块的少许不足之处。
config/locals/ja.yml
中本来是这样写的。
ja:
activerecord:
attributes:
user:
name: 姓名
phone: 电话号码
这样的话就希望将表格在 ERB 模板里照这样的形式写吧。
<% form_for @user do |f| %>
<%= f.label :name %>: <%= f.text_field :name %><br />
<%= f.label :phone %>: <%= f.text_field :phone %><br />
<%= f.submit %>
<% end %>
但是,在此之前 label
方法并没有对应 I18n,所以 f.label :name
只返回到“Name”字符串。
返回到“姓名”本来就是自然而然的事情。
Rails 2.3.3 之前,label
方法只是用humanize
方法更换栏名。因为与国际化没有关联。
所以必须像下面这样写。
<% I18n.with_options :scope => [:activerecord, :attributes, :user] do |locale| %>
<% form_for @user do |f| %>
<%= f.label :name, local.t(:name) %>: <%= f.text_field :name %><br />
<%= f.label :phone, local.t(:phone) %>: <%= f.text_field :phone %><br />
<%= f.submit %>
<% end %>
<% end %>
Rails 2.3.4 的问世,大大减少了书写量啊。
要是 submit
方法能在翻译文件里指定生成按钮的话更好了,当然,这是一个贪心的想法。
【提供学习】
分享到:
相关推荐
rails-i18n, 用于收集 Ruby on Rails i18n 环境数据以及其他有趣的Rails 相关 i18n 内容的存储库 Rails 语言环境数据存储库 中心收集区域设置数据,以便在 ruby 上使用。 gem-安装添加到你的Gemfile:gem 'rails-i18n...
如果要在没有Rails的情况下使用此库,则只需将i18n添加到Gemfile : gem 'i18n' 然后使用一些翻译和默认语言环境配置I18n: I18n . load_path << Dir [ File . expand_path ( "config/locales" ) + "/*....
react-i18n 该模块与 gem集成在一起,并作为的包装器构建。 基本设定 安装模块 $ npm install --save i18n-js react-i18n 设置i18n-js 在Gemfile中 gem 'i18n-js' 您认为* .haml :javascript I18n.default...
i18n...# You *must* choose GetText or Rails-i18n style checking# If you want GetText-style checkingI18n/GetText: Enabled: trueI18n/RailsI18n: Enabled: false# If you want rails-i18n
With this fully revised new edition, take a holistic view of full-stack development to create usable, high-performing applications with Rails 5. Rails is a great tool for building web applications, ...
适用于JavaScript的Ruby on Rails i18n 该gem通过Rack中间件公开您的JSON序列化翻译,以便将它们与JavaScript结合使用。 安装 此宝石正在开发中,这些步骤可能会更改 # Gemfile gem 'rails-i18n-js', :git => '...
mail_form, 在 Rails 中使用 i18n 验证附件和请求信息,直接从表单发送电子邮件 MailForm Rails 3这个 gem 构建在 ActiveModel 之上,展示如何从 Rails 中提取验证。命名和 i18n,而不需要自己实现。本自述文件指的...
I18n:Bamboo monkey 修补 Rails I18n 模块,并将强制所有对 I18n.translate (I18n.t) 和 I18n.localize (I18n.l) 的调用返回所有可用语言环境中最长的翻译或本地化值。 出于显而易见的原因(猴子补丁 :anxious_face...
模仿Rails的i18n界面。用法const I18n = require ( '@fiverr/i18n' ) ;const translations = require ( './translations.json' ) ;const i18n = new I18n ( { translations } ) ; 选项类型描述translations 目的...
rails-2.3.5.gem redmine必须gem
Rails.Recipes.Rails.3.Edition.和源码
agile_web_development_with_rails_3rd_edition.9994652073.pdf
百济I18n 这是一个小库,可以在JavaScript上提供Rails I18n的翻译。 从借来的特征: 多元化日期/时间本地化号码本地化语言环境回退资产管道支持还有更多! :)用法安装通过NPM npm install baiji-i18n 运行npm ...
RESTful.Rails.Development.2015.10.pdf
Pragmatic.Security.on.Rails.Dec.2009.rar
Ruby.on.Rails.Enterprise.Application.Development
Pragmatic - Agile.Web.Development.with.Rails.4.Sep.2013.pdf
This concise teaches you how to use the power of Docker and Kubernetes to deploy your Rails applications easily and efficiently. Docker and Kubernetes are increasing in popularity every day, but what ...
Apress.Beginning.Rails.from.Novice.to.Professional.2007.