Rails helpers collection to simplify the localization code.
gem install traducto
or add the following line to Gemfile:
gem 'traducto'This gem will overwrite the helper method t in Rails. It will mostly stay the same except for the following modifications :
The lazy lookup will check three more path. Here's the full stack of checkup if you call the following :
<%# app/views/persons/index.html.erb %>
<% t('.title') %> en:
views:
persons:
index:
title: "Title"This is for text in the persons view that is only present in the index action.
en:
views:
persons:
title: "Title"This is for text in the persons view that can be found in any actions.
en:
views:
title: "Title"This is for text that is used in any views.
# Rails default
en:
persons:
index:
title: "Title"The reason I add the views key in front of persons is to clearly separate the translations of the views, models and helpers.
If you want to reuse text of an action in a different context, for instance, if you are in the action create but you want to use the text of the new action. You can call the following on top of your view :
<%# app/views/persons/create.html.erb %>
<% use_translations_of 'new' %>You can also provide the format options to wrap the content by paragraphs.
en:
description:
intro: "Let me start by ..."
main:
- "A lot of ..."
- "Paragraphs that needs to be ..."
- "Separated by p tags." t('description.intro', format: nil)
# => Let me start by
t('description.intro', format: :text)
# => <p>Let me start by</p>
t('description.main', format: :text)
# => <p>A lot of ...</p><p>Paragraphs that needs to be ...</p><p>Separated by p tags.</p>Copyright (c) 2013 Alchimik. See LICENSE for further details.



