对于您的通知消息,您可以这样做
def create
if user.save
flash[:notice] = t(:user_was_successfully_created)
redirect_to users_users_path
else
render :new
end
end
你应该不有 4 种不同的路线
Rails 国际化 (I18n) API
看看这个链接http://guides.rubyonrails.org/i18n.html
Rails 国际化 (I18n) API
Ruby on Rails(从 Rails 2.2 开始)附带的 Ruby I18n(国际化简写)gem 提供了一个易于使用和可扩展的框架,用于将您的应用程序翻译成英语以外的单一自定义语言,或提供您的应用程序中的多语言支持。
“国际化”过程通常意味着从您的应用程序中抽象出所有字符串和其他特定于语言环境的位(例如日期或货币格式)。 “本地化”过程意味着为这些比特提供翻译和本地化格式。1
因此,在将 Rails 应用程序国际化的过程中,您必须:
Ensure you have support for i18n.
Tell Rails where to find locale dictionaries.
Tell Rails how to set, preserve and switch locales.
在本地化应用程序的过程中,您可能需要做以下三件事:
Replace or supplement Rails' default locale — e.g. date and time formats, month names, Active Record model names, etc.
Abstract strings in your application into keyed dictionaries — e.g. flash messages, static text in your views, etc.
Store the resulting dictionaries somewhere.
本指南将引导您了解 I18n API,并包含有关如何从一开始就国际化 Rails 应用程序的教程。
阅读本指南后,您将知道: