Plugin details

Pity the fools that have to specify scopes in views and controllers!

Websitehttp://github.com/iain/mr.-t Repositorygit://github.com/iain/mr.-t.git Author Iain Hecker LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/iain/mr.-t.git

Translating in views or controllers
---------------------------------------

A normal case would be that the both the new- and the edit-action of a controller renders the form partial. Most of the names will be the same, but not always. Mr. T have his defaults in such a manner that you can easily manage this.

  # app/views/posts/_form.html.erb
  <%= t("Shut up, fool!") %>


will look up these keys:

    * posts.new.shut_up_fool # or posts.edit.save, depending on which action was run
    * posts._form.shut_up_fool
    * posts.__common.shut_up_fool
    * shut_up_fool


When working from the controller, it will be:

    * posts.new.shut_up_fool
    * posts.__common.shut_up_fool
    * shut_up_fool


Notice that any special characters from the key will be removed, when used as translation lookup key, but the original key will be defaulted to, and will be stored in the missing locale file.

And finally it’ll serve the original string as a default, but not without writing to config/locales/missing_en.yml (depending on your locale of course).

The log will display which fallbacks have been used, so you easily check out where you can place your translations.

  Mr. T says (from /app/views/posts/_form.html.haml:3): ["posts.new.shut_up_fool", "posts._form.shut_up_fool", "posts.__common.shut_up_fool", :shut_up_fool, "Shut up, fool!"]


Notice: The t() method will be overridden by Mr. T, but the translate method doensn’t. Use translate if you wish to use the old behavior. Also, setting the default option, will disable Mr T’s special abilities and perform a regular lookup, without complicated fallbacks.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 9 months ago