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

enumlingo

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enumlingo

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Enumlingo

Gem Version

Enumlingo is a simple gem that helps you translate enum values in your Rails app.

Usage

extend Enumlingo in your model and call enumlingo with the enums you want to translate.

class Product < ApplicationRecord
  extend Enumlingo

  enum status: %i[active inactive]
  enum kind: %i[book food medical other]


  enumlingo :status, :kind
end

define the translations in your locale file

en:
  activerecord:
    attributes:
      product:
        statuses:
          active: "Active"
          inactive: "Inactive"
        kinds:
          book: "Book"
          food: "Food"
          medical: "Medical"
          other: "Other"

"zh-CN":
  activerecord:
    attributes:
      product:
      statuses:
        active: "激活"
        inactive: "未激活"
      kinds:
        book: "书籍"
        food: "食品"
        medical: "医疗"
        other: "其他"

Value translation

product = Product.new(status: :active, kind: :book)
product.status_lingo # => "Active"
product.kind_lingo # => "Book"

I18n.locale = "zh-CN"
product.status_lingo # => "激活"
product.kind_lingo # => "书籍"

Options translation

# Translate options with key
Product.statuses_lingo # => [["Active", "active"], ["Inactive", "inactive"]]
Product.kinds_lingo # => [["Book", "book"], ["Food", "food"], ["Medical", "medical"], ["Other", "other"]]

# Translate options with value
Product.statuses_lingo_values # => [["Active", 0], ["Inactive", 1]]
Product.kinds_lingo_values # => [["Book", 0], ["Food", 1], ["Medical", 2], ["Other", 3]]
Product.status_lingo(:active) # => "Active"

Form translation

<%= form_for @product do |f| %>
  <%= f.select :status, Product.statuses_lingo %>
  <%= f.select :kind, Product.kinds_lingo %>

  ...
<% end %>

Installation

Add this line to your application's Gemfile:

gem "enumlingo"

And then execute:

$ bundle

Or install it yourself as:

$ gem install enumlingo

Contributing

Contribution directions go here.

License

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

FAQs

Package last updated on 24 Mar 2024

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