Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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:
- Host: GitHub
- URL: https://github.com/dhyegocalota/active_record-humanized_enum
- Owner: dhyegocalota
- License: mit
- Created: 2017-10-06T15:42:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-28T12:09:37.000Z (about 2 years ago)
- Last Synced: 2024-10-03T10:08:31.433Z (about 1 month ago)
- Topics: activerecord, enum, i18n, rails, ruby
- Language: Ruby
- Homepage:
- Size: 9.77 KB
- Stars: 10
- Watchers: 2
- 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) # Inativouser = User.first
puts user.status # enabled
puts user.humanized_status # Ativouser.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)