Rails currently doesn’t offer any explicit support for internationalization. Perhaps it should, perhaps it’s too app specific to generalize. We’ll explore that topic here.
The first place you should go is Julik’s excellent guide to i18n-proofing your Rails app: HowToUseUnicodeStrings.
You’ll probably also want to check out the Globalize plugin, which supports translating database and view content and localizes things like times, dates, and numbers. Note that the InternationalizationComparison page provides an excellent comparison of the various plugins available (including Globalize, GlobaLite, Localize, and others), their capabilities, and their requirements.
Some words of advice from Collaboraid (who did a bunch of i18n stuff for \OpenACS):
Additionally, it’s much easier to translate an application if the translator can see the strings in context. So in-app translation links are a really good idea (they won’t capture all error states or system messages, though).
See http://translate.openacs.org/ as an example of a major translation app for a system.
Hal Helms has another example of how to do internationalization. My thoughts would be to have
What kind of unicode support is expected?
Also, maybe using ruby-gettext may make sense here?
Current version is converting non-English (accented) characters to entities. This is fine for display, but not OK for editing in forms. This bug is even present in Basecamp…
Using utf-8 is indeed the only way to display all characters in an editing form. For those who want to know more, read On the Goodness of Unicode and/or my shorter Do not fear Unicode.
Thanks! Is there some HOWTO about switching Rails application ro use UTF-8? I didn’t find anything in this wiki.
This should not be too difficult: use UTF-8 strings in the DB, save the templates as UTF-8, and set the content-type to “text/html;charset=utf-8” (either the HTTP header or a http-equiv meta tag). But expect some incompatibilities with older browsers (especially Netscape 4.x).
I am really interested in this topic, a webapplication I just started making with Rails will need to be internationalized (or at least multilanguaged) eventually. Have any of the Rails users made an implementation? or some more detailed ideas/suggestions on where to start?
—jsdk
Internationalization doesn’t only mean translating all text only. It can also lead to different layout, e.g. if words are longer or shorter in different languages – it could break the layout in some cases.
To go the next step to Localization?, you need to take into account that different countries can have different requirements regarding units of measurement (e.g. for length, volume, weight, currency etc.) or different ways of displaying text ().
Sometimes it could also be necessary to have different templates because in some countries you need different form values (e.g. addresses – ever thought of european ZIP codes or street addresses?).
One way to make this possible would be to have localizes versions of templates, maybe each in directories for each supportes locale, and a fallback template if no other version exists.
—hli
Andreas Schwarz outlined how to convert your site to UTF-8. An additional step might be needed depending on your \MySQL setup – telling \MySQL that you want to use UTF-8 for the Rails connection.
(edited;the original info was outdated. Jay donnell?)
Add the encoding line to your database.yml
This line tells the mysql adapter to run ‘set names utf8’ on the mysql connection.
development: adapter: mysql database: xxx username: yyy password: zzz encoding: UTF8
—RalphB? edited by jay donnell
Maybe a Java-like approach ?
This is a must for rails. I’ll agree 100% on the “don’t try to reuse keys”: We developed an app to be i18ned in 4 languages (English, Greek, Spanish, Portuguese) and the result was hilarious, as there were a lot of ugly messages. However I think this goes to the developers more than the framework.
Maybe something as easy as Java’s .properties files ?
<span class="newWikiWord">ApplicationResources<a href="http://wiki.rubyonrails.com/rails/pages/ApplicationResources">?</a></span>_en.properties
<span class="newWikiWord">ApplicationResources<a href="http://wiki.rubyonrails.com/rails/pages/ApplicationResources">?</a></span>_el.properties
<span class="newWikiWord">ApplicationResources<a href="http://wiki.rubyonrails.com/rails/pages/ApplicationResources">?</a></span>.properties (for not found strings)
messages.getMessage("key.with.nice.dots.for.grouping", locale)
messages.getMessage("key.with.nice.dots.for.grouping",
new Object[] { "this is a named parameter",
new Date(),
new Double(32.445),
locale } )
The files are in the format:
group.group.group.paramkey=This is i18ned text
group1.group2.group.paramkey=This is i18ned text, {0} !!!
—orestis
What about URLs? Should controller and action names also be localized? Could this be done within Rails or would you need to use Apache somehow?
—Martyn
category: I18n
I like the Java approach.
An Application knows it’s default Locale, and you can set a different one at any time. The App then knows which property file to look at.
Please, take a look at how one Php framework solved i18n issue: http://www.symfony-project.com/content/book/page/i18n.html
There are very good ideas there to implement in rails.
—Metin
I second Metin and orestis above – please have a look at how Java solved this issue. Also have a look at how Spring Framework have incorporated this into their framework.
Re-inventing the wheel is bad™.
—AndersEngstrom
Please see InternationalizationComparison
—Max
If you plan to deploy with JRuby anyway, this becomes a non-issue as you have full access to Java’s I18N goodies, see: Internationalization with JRuby
—Matt
GlobaLite localization made simple and lite. Globalite offers a simple UI and Rails i18n/l10n Read more