楼主是哪的?大四的路过。。。
#1 楼 @hxh1246996371 噢,谢谢...一下没反应过来该用 session....
#7 楼 @msg7086 好的。 #9 楼 @xiaoronglv 谢谢鼓励!
#4 楼 @rei 谢谢,这碗鸡汤很适合现在的自己... #3 楼 @hging 我在 config/locale下有zh.yml和en.yml。 en.yml 的是
en:
activerecord:
models:
user: "账号"
attributes:
user:
name: "用户名"
email: "邮箱"
password: "密码"
password_confirmation: "密码确认"
这个可以正常显示翻译过去的词。我尝试直接在 en.yml 里写 error:,改为
activerecord:
models:
user: "账号"
attributes:
user:
name: "用户名"
email: "邮箱"
password: "密码"
password_confirmation: "密码确认"
errors:
models:
user: 用户
messages:
inclusion: "不包含于列表中"
exclusion: "是保留关键字"
invalid: "是无效的"
confirmation: "与确认值不匹配"
accepted: "必须是可被接受的"
empty: "不能留空"
blank: "不能为空字符"
too_long: "过长(最长为 %{count} 个字符)"
too_short: "过短(最短为 %{count} 个字符)"
wrong_length: "长度非法(必须为 %{count} 个字符)"
taken: "已经被使用"
not_a_number: "不是数字"
#
就直接报错了,如果我把这段 errors:下面的内容写到 zh.yml 里(我在 ApplicationController.rb 里写了
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
并且 config/application 里设置了默认语言用 en
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :en
config.encoding = 'utf-8'
但 has_secure_password 里的 3 个验证消息还是没有被翻译过来...
还有就是比如自己搜索过,文档查看过,然后自己也试着折腾过,还是弄不出来的话发贴在社区里询问,不会因为是个简单的问题被排斥吧..只是真不知道自己这个学习过程是正确的还是缺少了....感觉自己好菜啊......
只是说下现在这个问题吧,我在 layout 的 application.rb 里加上了对国际化方法的引用。是参考这个弄的http://www.tuicool.com/articles/NZBBNbz 然后我在消息调用的 each 里的每一个 key 和 value 都加上了 t 在前面。单独也试过,如果有字典可用,是可以翻译出来的。但似乎对于 has_secure_password 里自带的验证的消息似乎没用啊..
我的 pdf 买的时候买错了。买的是第 2 版,能否留个联系方式?想参考一下第 3 版的内容