Project

traducto

0.0
No commit activity in last 3 years
No release in over 3 years
Rails helpers collection to simplify the localization code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 5.0
 Project Readme

Traducto Build Status Code Climate Coverage Status Gem Version

Rails helpers collection to simplify the localization code.

Install

gem install traducto

or add the following line to Gemfile:

gem 'traducto'

Usage

This gem will overwrite the helper method t in Rails. It will mostly stay the same except for the following modifications :

Lazy Lookup

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.

Recycle text for particular action

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' %>

Formatting

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

Copyright (c) 2013 Alchimik. See LICENSE for further details.