LocalizationSimplified
Posted By Slobodan Kovacevic on January 26, 2007
Rails is excellent in handling almost everything if you are building a site in English. Unfortunately, when it comes to localization (sites in other languages, UTF-8 support, etc.) Rails is not very well equipped to handle it.
There are localization plugins that make life easier, but most of them are rather complex, hard to use and have significant overhead (i.e. takes time to setup, learn, etc.). Fortunately, plugin called Localization Simplified aims to simplify localization as much as possible:
Fast and easy localization of one-language applications. Adds UTF-8 support for Ruby + database. Modifies ActiveRecord errors + html error helpers, Date/Time helpers, locale time formats, to_currency, to_sentence
It’s easy to use mainly because it only overrides existing Rails methods, so you don’t have to do anything special to use it.
Localization Simplified is a great plugin which you can download from Ruby Forge.
Comments
bmihelac says:
encoding: UTF8
database.yml
LocalizationSimplified
Slobodan Kovacevic says:
bmihelac says:
Slobodan Kovacevic says:
4 Responses to “LocalizationSimplified”
April 26th, 2007 at 3:45 pm
What means ‘Adds UTF-8 support for Ruby + database.’? Isn’t just
enough to be added in
,
Is there way to translate custom strings or
only translates Rails messages?
April 26th, 2007 at 4:45 pm
Before I tried out the Localization Simplified I added only ‘encoding’ in database.yml and it worked for me. But I’ve read on the net that people had more problems with UTF-8 and that function such the one below (which has been taken from Localization Simplified) has helped them:
class ActionController::Base before_filter :configure_charsets def configure_charsets(charset='utf-8') # Set connection charset. MySQL 4.0 doesn't support this so it # will throw an error, MySQL 4.1+ needs this. suppress(ActiveRecord::StatementInvalid) do ActiveRecord::Base.connection.execute "SET NAMES 'UTF8'" end end endAs far as I can see it only sets encoding for database communication, which obviously is what ‘encoding’ setting in database.yml should do. Perhaps it’s a left-over from previous Rails versions, i.e. when ‘encoding’ wasn’t available.
I am not sure what exactly you mean when you say “custom strings”, but it replaces ActiveRecord::Errors::@@default_error_messages, distance_of_time_in_words(), date, time and currency formats and few others.
April 26th, 2007 at 7:04 pm
By ‘custom strings’ I meant that plugin would handle messages your application PRODUCE and handle them in one YAML file or database (it uses YAML right?). For example in controller you may need to create message that “E-mail entered is already in use”. Next, you would need to handle translations of models and model fields.
Both Globalize-Rails and GetText offer these but are overkill for projects in one language only.
May 3rd, 2007 at 10:55 am
No, it doesn’t do that. I think that the author focused on Rails localization itself. You still need to handle “custom” localization yourself, i.e. while writing the code.