Ruby I18n Gem hits 0.2.0

posted: July 12th, 2009 · by: Sven

in: Globalization, Programming ·  11 comments »

For a lowlevel library like I18n small changes are big ones because so many users depend on it. That said two huge changes have made it into the codebase and thus we’re bumping the version to 0.2.0.

So, here are some details about this release.

Here’s the release announcement on the rails-i18n mailinglist:

I've bumped the gem version to 0.2.0 and tagged v0.2.0 today.

Most importantly it includes:

* Lambda support (aka Yaroslav-prevails edition)
* Custom separators (aka Gettext-p0wned edition)
* Ruby 1.9 interpolation syntax (aka Masao-Mutoh-rocks edition)

For more details check out the changelog.

Thanks to everybody involved!

We still haven't managed to get the inclusion of Rails' vendorized gem right. Thus it's currently not possible to use 0.2.0 in Rails easily.

As we've moved from 0.1.x to 0.2.x the pessimistic gem version operator "~> 0.1.3" used in Rails won't load a 0.2.0 version of the gem. I've added a Rails patch that relaxes this to use the optimistic operator ">= 0.1.3" instead.

With that patch being applied we'll still have to sort out the Rubyforge release process. Josè Valim has volunteered for this and I've asked Matt to add him to his Rubyforge project.

Meanwhile, with above patch applied, we could always clone the Github repo and build the gem manually of course. This should also work fine for playing with experimental builds in the future.

Lambda support

Changesets: e27771, c90e62, 9d390a

Lambda support has been considered a potential feature from the beginning because it adds the remaining ton of flexibility you need to support wicked things like Russian’s irregular date formatting.

The shipped simple backend can store lambdas as translations when used with Ruby files. Other backends might implement different mechanisms.

E.g. you might store the translation:

:salutation => lambda { |gender| 
    gender == "m" ? "Mr. {{name}}" : "Mrs. {{name}}" 

This will, of course, resolve to either “Mr.” or “Mrs.” depending on the gender argument passed.

This is certainly a power feature and you need to use it wisely. As a rule of thumb make sure your lambdas are cheap and always return the same stuff when passed the same arguments.

Custom scope separators

Changeset: 5b75bf

This feature was a result of a discussion on the Rails core mailinglist about how easy it was to replicate Gettext’s behaviour using the I18n gem. The general answer was: It’s easy. But the nitty-gritty details are that I18n uses a period/dot as a scope separator so you can not use a full sentence as both a key and default value – as Gettext uses to do that.

So we’ve added support for customizing the scope separator both globally and on a per-request basis. You can:

# set a different scope separator globally:
I18n.default_separator ="\001" 
I18n.t("Foo. And bar, too.")

# pass it as an option to #translate: 
I18n.t("Foo. And bar, too.", :separator => "\001")

Yes. Of course the I18n API totally allows you to use Strings as keys. It will make more sense if you add a Gettext-like helper to access the backend though.

Symlinking translations

Changeset: 8c4ce3

After we’ve implemented the mentioned lambda support we’ve refactored some portions of Simple backend and and cleaned up the implementation. When we were done we accidentally noticed that we’ve also implemented support for a previously requested feature that we refer to as “symlinking translations”.

So far we’re not completely convinced that this should be made an official feature so we did not document it in the I18n module docs, yet. On the other hand people have asked for it and there’s no reason to officially “disallow” it either. So we’ll just mention it here and let people decide :)

You can now symlink translations by returning a Ruby Symbol from either your literal translation data or computed lambdas. So, for example:

    # yaml translation data
      edit: Edit
        edit: :"actions.edit"

    I18n.t(:"articles.actions.edit") # => "Edit"

Leave a comment


  1. jack said January 23rd, 2011 at 10:28 AM  

    Great site, where did you come up with the information in this piece? Im happy I found it though, ill be checking back soon to see what other articles you have. cheap hosting

  2. Sadi said February 22nd, 2011 at 02:47 PM  

    This is awesome! I bet the people at free online dating site would love to hear about this. They’d been scouring the net for an information like this. Thanks for sharing.

  3. p said March 22nd, 2011 at 12:04 PM  


  4. Cams said March 30th, 2011 at 07:36 PM  

    This version wasn’t compatible with my lambda installation. Some further documentation would be helpful.

  5. side sleeper pillow said April 22nd, 2011 at 06:59 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.

  6. PROMOTIONAL PRODUCTS said April 27th, 2011 at 04:26 PM  

    Thank yo so much for posting this. It’s very informative and I surely learned a lot from it.

  7. Okey Oyunu said May 12th, 2011 at 03:31 PM  

    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 www. 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.

  8. p said May 21st, 2011 at 05:05 PM  

    chaussures nike lunarhaze+ white black red [cn3340] - €49.99 : nike tn,requin tn,tn nike,tn requin,nike requin,basket tn,chaussures tn
    nike tn,requin tn,tn nike,tn requin,nike bw,basket tn,chaussures tn : nike free 3.0 3 - Kvinner sko Menn sk
    Nous avons une satisfaction garantie à 100%. Si vous n’êtes pas satisfait avec votre produit dans les 365 jours suivant la réception vous pouvez l’envoyer de nouveau à nous pour un remboursement complet.

    Il est 24 heures période de traitement une fois le paiement re?u. Une fois que les chaussures sont expédiée, vous recevrez un email de notre part avec numéro de suivi afin que vous mai suivre votre commande. Vous aurez vos produits dans 3-5 jours d’affaires (sans compter les week-ends ou jours fériés). La plupart des commandes sont traitées et re?ues par les clients dans les 3 jours.

  9. porno said May 23rd, 2011 at 01:02 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.

  10. porno said May 23rd, 2011 at 01:02 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

  11. kadin said May 23rd, 2011 at 01:03 PM  

    kadinlara özgü bir site.

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