← Home

Ruby I18n Gem hits 0.2.0

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. " : "Mrs. "
}

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
	actions:
	  edit: Edit
	articles:
	  actions:
	    edit: :"actions.edit"

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