One of the new tools in Rails to stay DRY is the new I18n functionality. With this new tool you can keep away from customizing messages, text in your views etc. for your clients/customers, and instead let them to it themselves! Especially with this great new plugin
Some examples:
In your controller:
flash[:notice] = t("controller.#{current_resource}.#{current_action}",
:default => "controller.default.action")
If your using something like make_resourceful this becomes even more apparent. I have forked make_resourceful and implemented this which you can check on my github account.
A similar trick can be done in your views:
flash[:notice] = t("view.#{current_resource}.#{current_action}",
:default => t("view.default.#{current_action}") )
The only thing you have to is have a yaml file like this:
en:
controller:
default:
create:
"Succesfully created!
....
You can also add the translation of the resource you are working on by adding an option as in the following example:
flash[:notice] = t("view.#{current_resource}.#{current_action}",
:default => t("view.default.#{current_action}"),
:model => t("activerecord.model.#{model_name}") )
In your yaml file you will just have to add ‘{{model}}’ to include the translation.
en:
controller:
default:
create:
"Succesfully created {{model}}!
....
It might turn out that the above idea with this new feature in rails will make life even easier! Probably more on that in a future post!
Since this is my first blog post here I would welcome some feedback!