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: about 1 year ago
JSON representation
Easily translate your Active Record's enums. :speech_balloon:
- Host: GitHub
- URL: https://github.com/dhyegocalota/active_record-humanized_enum
- Owner: dhyegocalota
- License: mit
- Created: 2017-10-06T15:42:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-09-28T12:09:37.000Z (over 3 years ago)
- Last Synced: 2025-03-30T11:01:53.835Z (about 1 year ago)
- Topics: activerecord, enum, i18n, rails, ruby
- Language: Ruby
- Homepage:
- Size: 9.77 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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)