public
Description: Makes the default Rails helpers i18n compatible
Homepage: http://iain.nl/
Clone URL: git://github.com/iain/i18n_helper.git
name age message
file README.textile Fri Jan 23 08:25:41 -0800 2009 Extracted view_translate to call just t(). Use ... [iain]
file Rakefile Tue Oct 28 07:23:33 -0700 2008 First commit [iain]
file init.rb Tue Oct 28 13:52:10 -0700 2008 Small optimalization in load time [iain]
file init.yml Tue Oct 28 09:11:36 -0700 2008 README upgrade [iain]
file install.rb Tue Oct 28 07:23:33 -0700 2008 First commit [iain]
directory lib/ Fri Jan 23 08:25:41 -0800 2009 Extracted view_translate to call just t(). Use ... [iain]
directory spec/ Tue Oct 28 07:23:33 -0700 2008 First commit [iain]
directory tasks/ Tue Oct 28 07:23:33 -0700 2008 First commit [iain]
file uninstall.rb Tue Oct 28 07:23:33 -0700 2008 First commit [iain]
README.textile

I18nHelper

With this plugin you can pass symbols to all popular Rails helpers and have
them translated. Also provides view_translate() method to translate within
the scope of the controller and action.

Installation

Install this plugin the usual way and add :i18n to your helpers in the
ApplicationController, for example:

class ApplicationController < ActionController::Base helper :all, :i18n end

Usage

in app/views/posts/index.html.erb:

<%= link_to(:new_post, new_post_path) %>

This will be the same as:

<%= link_to(t(:new_post), new_post_path) %>

If the argument is not a symbol, it won’t call t(). In the past this would call some interesting view_translate method, which did some scoping. I moved that part (and improved it) to the Mr. T plugin. Please install that to get all kinds of wonderfull goodies for translating from views.

Translating existing helpers

To translate helper methods of plugins or your own helpers, you can place a
yaml file i18n_helper.yml in your config directory. The format is like this:

link_to: 0 content_tag: 1

The number after the method name is the index of the argument to be translated.
This is usually 0, but can of course vary. You can specify an array of indexes
if you want.

You can also translate a helper on the spot in code:

I18nHelper.translate_helper(:my_helper, 1, self)

The self is the object on which the helper can be found.

Notes

Still beta, needs tests. If you wish to contribute or found a bug, please
send me a message.

On my todo-list is translating certain options too, like the :confirm option in
link_to.

Copyright © 2008 Iain Hecker, released under the MIT license