Low commit activity in last 3 years
No release in over a year
Easily translate your ActiveRecord's enums.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

ActiveRecord Humanized Enum (I18n)

Easily translate your Active Record's enums.

Installation

Include to your Gemfile

gem 'active_record-humanized_enum'

Usage

ActiveRecord integration

The installation automatically self-includes in the ActiveRecord::Base.

How to use

  1. Call the enum macro method just like you already do:
class User
  enum status: [:enabled, :disabled]
end
  1. Translate the enums in your YML translation files:
pt-BR:
  activerecord:
    attributes:
      user:
        status: Estado
        statuses:
          enabled: Ativo
          disabled: Inativo
  1. Will be available the following methods:
User.humanized_status(:enabled) # Ativo
User.humanized_status(:disabled) # Inativo

user = User.first
puts user.status # enabled
puts user.humanized_status # Ativo

user.status = :disabled
puts user.humanized_status # Inativo

Related Projects

Maintainer

Dhyego Fernando