public
Description: Makes the default Rails helpers i18n compatible
Homepage: http://iain.nl/
Clone URL: git://github.com/iain/i18n_helper.git
iain (author)
Mon Nov 03 13:27:07 -0800 2008
commit  dff357743336c1eaf086422446e2ad912ec7adb1
tree    f4320ca2fd35e704c91d52859c006b7127411acb
parent  9b95fd97101bc638f6b91cca81e40a447e209408
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) %>

will lookup these translations:

  1. views.posts.index.new_post
  2. views.posts.common.new_post
  3. views.common.new_post

Basically all these helpers do is call view_translate(). The example above
is exactly the same as link_to(vt(:new_post), new_post_path).

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