方法
实例公共方法
localize(object, **options) 链接
委托给 I18n.localize。
也别名为: l
来源: 显示 | 在 GitHub 上
# File actionpack/lib/abstract_controller/translation.rb, line 37 def localize(object, **options) I18n.localize(object, **options) end
translate(key, **options) 链接
委托给 I18n.translate。
当给定的键以句点开头时,它将被当前控制器和操作作用域。因此,如果您从 PeopleController#index 调用 translate(".foo"),它将把该调用转换为 I18n.translate("people.index.foo")。这使得在同一控制器/操作中翻译多个键不那么重复,并为您提供了一个简单的一致作用域框架。
也别名为: t
来源: 显示 | 在 GitHub 上
# File actionpack/lib/abstract_controller/translation.rb, line 17 def translate(key, **options) if key&.start_with?(".") path = controller_path.tr("/", ".") defaults = [:"#{path}#{key}"] defaults << options[:default] if options[:default] options[:default] = defaults.flatten key = "#{path}.#{action_name}#{key}" end if options[:default] && ActiveSupport::HtmlSafeTranslation.html_safe_translation_key?(key) options[:default] = Array(options[:default]).map do |value| value.is_a?(String) ? ERB::Util.html_escape(value) : value end end ActiveSupport::HtmlSafeTranslation.translate(key, **options) end