Easily translate your Active Record's enums.
Include to your Gemfile
gem 'active_record-humanized_enum'
The installation automatically self-includes in the ActiveRecord::Base
.
- Call the
enum
macro method just like you already do:
class User
enum status: [:enabled, :disabled]
end
- Translate the enums in your YML translation files:
pt-BR:
activerecord:
attributes:
user:
status: Estado
statuses:
enabled: Ativo
disabled: Inativo
- 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