Get on Rails with Globalize: a comprehensive writeup in 8 parts

posted: November 10th, 2006 · by: Sven

in: Globalization, Programming · tagged as: , , , , , , ·  37 comments »

I don’t know where you’re coming from. But my former experiences using I18n solutions have never been so much fun.

I’ve been absolutely thrilled about Globalize. Imagine to just plug-in some extension and instantly being able to use simple, intuitive mechanisms to translate your (now multi-language) application. Wouldn’t that be wonderful exactly the way you’d expect a Rails solution for your most common programming problems to work?

Well, Globalize is just that. Globalize is a powerful, yet elegant and usable Rails plugin that’s here to help you with the translation and localization of:

  1. arbitrary text like in templates (“hello world!”), mails, messages, etc.
  2. model data like text that goes in the database as part of your ActiveRecord classes
  3. stuff like dates, time, numbers, currency etc.

This series is here to help you get started and get the most out of Globalize.

As most of the parts of this series aren’t complete yet, I’ll edit the following outline as soon as stuff sediments. To stay informed about updates please subscribe to my blog.

Part 1 of 8: Five minutes instant overview

  • How to install and configure Globalize
  • How to translate arbitrary text (ViewTranslations)
  • How to translate Rails models (ModelTranslations)
  • How to add translations to the database
  • How to localize Dates, Times and Numbers

Part 2 of 8: Some common questions on getting started

  • How to setup your application to use Unicode
  • How to select and persist the current user’s locale
  • How to translate Rails ActiveRecord messages
  • How to localize entire templates

Part 3 of 8: Globalize’s advanced features

  • Abstracting ViewTranslations (sprintf-like usage)
  • Singular and (multiple) plural ViewTranslations
  • Globalize’s Currency class
  • Piggyback translated ActiveRecord associations

Part 4 of 8: How to set up your routes?

  • Pros and cons of different ways to store the locale:
  • Sessions, accept-language header, geo-location
  • RESTful, URL-based approaches

Part 5 of 8: Advanced techniques, tips and tricks

  • Preload View Translations in Production
  • Bridge Globalize and TZInfo
  • Clear Globalize’s translations runtime cache
  • Use nice predicated block helpers in your views
  • Organize your translations through Globalize’s namespaces
  • Alternative Storage Mechanism for Model Translations
  • Disable Globalize::ViewTranslation’s SQL logging

Part 6 of 8: Pimp your Globalize! Extensions, plugins and patches

  • Multilingual URLs
  • Patch Globalize to get it working with :include and no base language
  • Translate your application while browsing it
  • Localized, concise Rails URL helpers
  • Get Liquid templates to play nice with Globalize
  • Globalize time_ago_in_words method of Rails
  • Multiple arguments to fetch

Part 7 of 8: Gotchas and other funny things to know and avoid

  • I’m seeing lot’s of strange characters!
  • Weird Currency parsing results
  • Globalize WrongLanguageError on attribute read
  • Globalizes screws my RJS (or: my IE6)!

Part 8 of 8: ...

<!- Globalize compared to other Rails I18n/L10n solutions (?) ->

Leave a comment


  1. cmarc said November 25th, 2006 at 12:29 AM  


    very nice article! I really appreciate. Just a question: is Globalize working in a windows development environment?

    thx for all

  2. Sven said November 27th, 2006 at 09:48 PM  

    Hey cmarc!

    Yes, absolutely. Globalize is working perfectly in a windows environment.

    One of the nice aspects of Globalize is that there are no external dependencies. So everything you need is a working Rails setup, your Webserver and Database.

  3. luc said January 10th, 2007 at 08:19 PM  

    Absolutely fantastic! Looking forward to the next article!

  4. BJ Vicks said January 28th, 2007 at 09:00 PM  

    Thanks for this!

    Have you looked into moving your applications to Rails 1.2 as of yet? If so, are you able to illuminate the areas in which the approach should differ?

  5. Sven said January 30th, 2007 at 12:29 PM  

    Hi BJ Vicks,

    no I haven't ... AFAIK the maintainers are working on a for-1.2 release. But yes, of course I'm going to cover this as soon it will be released.

  6. Benny said February 6th, 2007 at 06:33 PM  

    very nice tutorial, you lead me trough globalize like a warm knife trough butter. Thanks!

    I'm on 1.2.1 and so far everything seems to work fine. Be sure to get the trunk version though! so:

    script/plugin install svn://
    instead of
    script/plugin install svn://
  7. Sven said February 8th, 2007 at 04:31 PM  

    Like a warm knife through butter? Hum, I'll take that as a compliment, Benny :)

    Errm, yes. Actually you should get the brand new for-1.2 branch of Globalize.

    script/plugin install svn://

    That's about one minute before being released now :)

  8. cvogt said February 13th, 2007 at 05:03 PM  


    great tutorial, bit i have a problem trying out. i'm behind a firewall, which seems to block port to the svn. is there any solution to get globalize plugin installed in an other way?

  9. Sven said February 13th, 2007 at 07:04 PM  


    did you try to checkout via http?

    svn co
  10. cvogt said February 13th, 2007 at 10:19 PM  

    hi sven, thanks for answering. yes i did, answer of ruby with --trace was: plugin not found. without --trace console was blank, only promt was there.

    i'm using winxp, if this is important.

  11. Sven said February 14th, 2007 at 02:28 AM  


    I've added two download links to the Globalize wiki that point to tar.gz download files.

    We'll also look into providing a more reliable solution.

  12. cvogt said February 14th, 2007 at 08:28 AM  

    thank you very much, my day is rescued - i can go on working :)

  13. titou said April 26th, 2007 at 05:02 PM  

    Hi :)

    Seems your link to “Part 4 of 6: How to set up your routes?” is down ;)

    Thanks a lot for those lessons.

  14. Sven said April 26th, 2007 at 07:59 PM  

    Thanks titou! The link is fixed now.

  15. Fildz said August 15th, 2007 at 05:05 PM  

    Thank you Sven !

  16. robert said September 29th, 2007 at 11:24 PM  

    Great tutorial,

    Not really sure if this is even a good idea, but I was wondering if anyone new of a way to store the globalize tables inside of a separate database? For backup and distribution purposes, it seems like it would be convenient to be able to have all of the globalize (essentially static) translations in a separate place.

    Everything from a google of rails and “Multiple Databases” involve patching the code, which i would like to avoid.

    cheers, robert

  17. Sven Fuchs said October 4th, 2007 at 11:45 AM  

    Hi Robert!

    Though I believe that Rails is capable of connecting to multiple databases this certainly would only work for view translations. Model translations require to be looked up in a single query joined with the model data itself. As far as I know there’s no way to do this “out of the box” with Globalize for view translations, and I wonder if that’s really a good idea, too :) All the translations are boxed into one database table anyways. So why would we want to move them to a separate database?

  18. robert said October 7th, 2007 at 12:04 AM  

    Hey Sven,

    I took a look at a few ways of putting certain tables into other databases, and all of them were less then satisfactory. In my case, I am developing an application that is going to be distributed, so I have to figure out a way to package updates to the globalize tables without affecting the user data on a particular machine. I know this won’t be very difficult, but my original thought was to just send the user a new file with all of the translations in it. (I will probably still do this, but use the file to repopulate the tables instead).

    Although inefficient, wipe and replace is simple and clean, leaving less room for error.

    cheers, robert

  19. Sven said October 12th, 2007 at 09:22 AM  

    Hi Robert,

    if you can spare a minute it would be great if you could put this together and post it to either the Globalize mailinglist or send me an email.

    We are currently in the process of gathering information for a major revamp of Globalize and are looking for usecases like you describe.

    Thanks in advance :)

  20. Ricardo Sazima said January 9th, 2008 at 04:32 PM  

    Hey Sven!

    I noticed in your last post that you are preparing “major revamp of Globalize”. Is that ready? Is Globalize fully Rails 2.0-compatible?

    Cheers, Sazima

  21. Sven said January 9th, 2008 at 06:51 PM  

    I really mentioned that? If so, I totally forgot about that :)

    As for your first question: no, we are still in the planning phase for Globalize 2.0 (that major revamp), which takes that long because it relies on a Rails core patch that we participate in. The big plan is to get some basic I18n support into Rails core and then provide a basic L10n gem to back it up. Plugins like Globalize will then build on this gem, extend it and provide additional features that are too specific to put them into the gem. You might imagine that this takes quite some time to work out all the details. So, yes, Globalize 2.0 is in the oven, but nobody knows when it will be ready.

    But Globalize should be ready for Rails 2.0. Yann and Saimon have work on a Rails 2.0 version for the same reason: Globalize 2.0 will take too long to let Rails 2.0 users wait for it.

  22. Jose Didriksen said April 21st, 2008 at 04:38 PM  

    Hey Sven, thanks for the articles! I was all ready to play with globalize, but seems to be down, so I thought I’d come here and ask some pesky questions instead!! How is Globalize 2.0 coming? What about putting globalize on github? Have you seen click to globalize? :)

  23. said April 21st, 2008 at 08:46 PM  

    Hi, i have just installed Globalize and started to get it working. The trouble is that i use calendar_helper which has its own way of setting date_format in application.rb such as:

    ActiveRecord::Base.date_format = ‘%d/%m/%Y’

    When i try to run i get:

    date_format is defined by ActiveRecord

    I don’t really want to use Globalize’s date_format because i have my own way of allowing users to choose their date format (including yyyy-mm-dd) so is there a way of turning it off?

  24. Sven said May 11th, 2008 at 06:06 PM  

    Hi Jose,

    in the meantime Yann has published Globalize on GitHub. There hasn’t been much activity lately because everybody seems to be busy otherwise. Expect Globalize 2.0 to definitely happen though :)

    Hi Aimee,

    I’m not aware of a way to turn that off. If you’ve found something please be sure to post your solution here. Thanks!

  25. Prakash Teli said April 21st, 2009 at 03:47 PM  


    First of all, thanks for this detailed article. I am an experienced Rails/Java architect/developer but new to i18n and internationalization in general.

    Q1: How much of this tutorial applicable to Globalize2? Q2: is there an equivalent tutorial/documentation on Globalize2?. After spending few hours googling, I did not come across a comprehensive documentation on how to use Globalize2. Q3: Is Globalize2 ready for production use?. Q4: What is the best/scalable way of creating translations of static and dynamic (database) text in multiple Indian languages (Hindi, Gujarati, Tamil, etc.)?


    Prakash Teli

  26. DragolinDesign Webdesign said September 12th, 2010 at 12:47 AM  

    Hey thanks for the tutorials, though I guess I should be checking out Globalise 2.0 instead :)

  27. jack said January 24th, 2011 at 03:20 PM  

    UCVHOST has changed the face of web hosting industry in a major way, people were paying gold for peanuts (and it is still happening). cheap hosting has become synonym with UCVHOST, anybody and everybody who wants a reliable and affordable domain web hosting visits UCVHOST and gets either windows vps or Linux hosting from UCVHOST. UCVHOST sells cheap hosting WITHOUT hidden terms and conditions where as competition has huge MSA and SLA’s which are good enough to confuse a seasoned lawyer also. For clients by now Business with us for the value of windows vps became very critical piece of puzzle for their whole operation, uptime and performance became a huge concern.. However it came with a cost, dedicated servers proved to be at least 100 times expensive in comparison to any windows or Linux plans. Somewhere in the labs engineers were working on splicing raw power of a server into virtual instances, this technology was called as Virtualization also termed as or virtual private servers. Also UCVHOST comes handy when you are looking for remotely hosted and managed FOREX MetaTrader4 terminals. Our forex vps platform is all geared up in fight of pips, our platform support any number of expert advisory (EA) and along with an assure of 100% uptime. Our Virtual Forex Tradng Terminals are well equipped to help you in making money .

  28. QQQ said February 7th, 2011 at 06:37 PM  

    Finally we kissed and the passion scale went sky high and I knew I was onto a good thing - sex was a certainty free porn videos. She never hesitated when I began to fondle her breasts and she willingly exposed them for me mobile porn. They were firm and I suspected a breast enhancement but said nothing - they still felt good and I was enjoying them and gradually working my way further south free porn tube. She was a step ahead of me and before I could completely undress her she moved on me atk hairy and I was suddenly having my pants pulled down and I was enjoying one of he best cock sucking hairy pussy experiences I had ever had. ABB728019394

  29. Coach said March 2nd, 2011 at 10:19 AM  

    When will 3.0 be out?

  30. chat said March 31st, 2011 at 08:06 PM  

    The following cleaned up the issue:

    Dependencies.loadoncepaths -={|path| \ path =~ %r(^#{File.dirname(FILE)}) }

  31. Jacob said April 5th, 2011 at 09:50 AM  

    This Globalize Plugin looks good, I recently met somebody on the aida who said. Wenn du auf der Aida Kreuzfahrt bist, dann ist es gut auch über die weiteren Clubschiff Aida Kreuzfahrten nachzudenken, damit du besser planen kannst. wenn du Globalize nutzt läuft das auch gleich viel besser. I will follow the advice and see what globalize can do for us.

  32. side sleeper pillow said April 22nd, 2011 at 07:01 AM  

    Nicely written article, Knowledgeable and informative post. I’m really glad I came my way along your site. Keep posting, I really like the whole topic. Thanks for sharing.

  33. Okey oyunu said May 12th, 2011 at 04:15 PM  

    Thanks for this article. Tüm dünya artik okey oyunu oynuyor. Yillardir bir çok oyun programi olmasina ragmen, içlerinden en güzeli olarak nitelendirebilecegimiz tek bir site göze çarpmaktadir. Diger tüm okey oyunu programlarinin aksine ücretsiz olmasi ve 3 boyutlu olarak hizmet vermesi mükemmel bir gelismedir. Sizlerde adresinden bu essiz okey oyununu indirebilirsiniz. Kullanimi çok basit ve Türkçe dil seçenegi ile kolaylikla oyuna baslayabilirsiniz. Ister kendi ülkenizden, isterseniz dünyanin tüm farkli bölgelerinden dilediginiz oyun odalarini seçerek, oyuna hemen baslayabilirsiniz. Okey oyunu oynamak için artik arkadas bile aramaniza gerek kalmadan, bilgisayarinizdan 100 binlerce üye ile online olarak okey oyununu oynamanin zevkine varabilirsiniz.

  34. indrie said May 19th, 2011 at 04:29 AM  

    I keep coming back to read your excellent quality content, The information you provide is quiet helpful. iklan baris

  35. Chung said May 20th, 2011 at 08:16 AM  

    If you wish the facts, you gotta apprehend this commodity (link below). pass4sure 646-985 It as well describes default benumbed modes and added advantageous information. pass4sure CISM I am in the action of customizing my modes and begin this commodity an accomplished beat on the abstruse aspects of this bike. pass4sure COG-112 I apperceive my bike better.

  36. porno said May 22nd, 2011 at 01:12 PM  

    I do agree with all of the ideas you have presented in your post. They’re really convincing and will definitely work. Still, the posts are too short for newbies. Could you please extend them a bit from next time? Thanks for the post.

  37. porno said May 22nd, 2011 at 01:50 PM  

    good comment. thanks you friends.

    I’ve surfed the net more than three hours today, however, I haven’t found such useful information. Thanks a lot, it is really useful to me

Sorry, comments are closed for this article.

artweb design
Sven Fuchs
Grünberger Str. 65
10245 Berlin, Germany

Fon +49 (30) 47 98 69 96
Fax +49 (30) 47 98 69 97