Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dhyegocalota/active_record-humanized_enum

Easily translate your Active Record's enums. :speech_balloon:
https://github.com/dhyegocalota/active_record-humanized_enum

activerecord enum i18n rails ruby

Last synced: 2 days ago
JSON representation

Easily translate your Active Record's enums. :speech_balloon:

Awesome Lists containing this project

README

        

# ActiveRecord Humanized Enum (I18n)
Easily translate your Active Record\'s enums.

## Installation
Include to your Gemfile
```ruby
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:
```ruby
class User
enum status: [:enabled, :disabled]
end
```

2. Translate the enums in your YML translation files:
```yaml
pt-BR:
activerecord:
attributes:
user:
status: Estado
statuses:
enabled: Ativo
disabled: Inativo
```

3. Will be available the following methods:
```ruby
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
- [Integration with ActiveAdmin](http://github.com/dhyegocalota/active_admin-humanized_enum)

## Maintainer
[Dhyego Fernando](https://github.com/dhyegocalota)