Best practice in making Rails applications multilingual

眉间皱痕 提交于 2019-12-05 03:06:39

for your notice messages you can do

  def create
    if user.save
      flash[:notice] = t(:user_was_successfully_created)
      redirect_to users_users_path
    else
      render :new
    end
  end

you should not have 4 different routs

Rails Internationalization (I18n) API

take a look at this link http://guides.rubyonrails.org/i18n.html

Rails Internationalization (I18n) API

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.

The process of "internationalization" usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application. The process of "localization" means to provide translations and localized formats for these bits.1

So, in the process of internationalizing your Rails application you have to:

Ensure you have support for i18n.
Tell Rails where to find locale dictionaries.
Tell Rails how to set, preserve and switch locales.

In the process of localizing your application you'll probably want to do the following three things:

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.

This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.

After reading this guide, you will know:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!