Hello everyone :D I've just started learning Rails and currently I have one concern.
I am building a Rails web site which needs to be translated to 4 languages. What would be the most practical and convenient method to do it?
I've read the main goal would be to make separate folders for each language and copy all the views for each language. But I would still have notice
messages on English inside my controller so how would I handle that. Routes
are also my concern. Should I have 4 different routes for 4 different translated Views.
What do you recommend to handle this problem? I didn't find anything concrete online.
Thank you for your suggestions!
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With