Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enum_translate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enum_translate

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EnumTranslate

EnumTranslate is a gem to translate ActiveRecord::Enum defined attributes with i18n system.

Installation

Add this line to your application's Gemfile:

gem 'enum_translate'

Usage

Preparation

If you have an ActiveRecord model like this

class Article < ActiveRecord::Base
  enum category: { finance: 0, lifehack: 1, technology: 2 }
end

include EnumTranslate module as a concern

class Article < ActiveRecord::Base
  include EnumTranslate

  enum category: { finance: 0, lifehack: 1, technology: 2 }
end

And if you set i18n locale as ja

I18n.locale = :ja

Please make a locale file like this

ja:
  activerecord:
    attributes:
      article/category:
        finance: 経済
        lifehack: 生活豆知識
        technology: 技術

APIs

Class Method

.human_attribute_options(:attribute_name)

Article.human_attribute_options(:category)
# => [["経済", "finance"],
#     ["生活豆知識", "lifehack"],
#     ["技術", "technology"]]
Instance Method

#human_attribute_text(:attribute_name)

article = Article.last
article.category
# => "technology"

article.human_attribute_text(:category)
# => "技術"

Contribute

PullRequests are welcome!

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 09 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc