Ruby Rails上的Java CMS:翻译/本地化博客模块中的字符串
在炼油厂CMS的博客模块中,我想翻译源代码中的一些字符串。当我覆盖blog模块的_post.html.erb视图时,内部有如下代码:Ruby Rails上的Java CMS:翻译/本地化博客模块中的字符串,ruby,ruby-on-rails-3,localization,internationalization,refinerycms,Ruby,Ruby On Rails 3,Localization,Internationalization,Refinerycms,在炼油厂CMS的博客模块中,我想翻译源代码中的一些字符串。当我覆盖blog模块的_post.html.erb视图时,内部有如下代码: <%= content_tag(:span, "#{t('by', :scope => 'refinery.blog.posts.show')} #{@post.author.username}", :class => "blog_author") if @post.author.present? %> 在applicat
<%= content_tag(:span,
"#{t('by', :scope => 'refinery.blog.posts.show')} #{@post.author.username}",
:class => "blog_author") if @post.author.present? %>
在application.rb中
在rails控制台中,我得到:
*I18n.locale* => :hr,
I18n.translate('hello') => "Pozdrav svima"
但是,当我启动应用程序时,rails服务器消息中有:
*Parameters: {"locale"=>:en}*
没有翻译工作。。。为什么?根据
可以根据url设置应用程序区域设置。对于localhost,区域设置为英语。为了改变这一点,可以修改应用程序_controller.rb
class ApplicationController
*Parameters: {"locale"=>:en}*
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :set_locale
def set_locale
I18n.locale = I18n.default_locale
end
end