enumlingo 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02b5b7d176faeef3781f6469c7ab0d45502346d50810a5b4b2ba2591b9edeb91
4
- data.tar.gz: cdb9b65d590344cc24e658bbd30e385d39d6b3ec49ba27bb8efa7420347975b5
3
+ metadata.gz: 48cd9e00bd148c28569535cb619d820538dddcdc65bb9a90f23463d44f7dbd15
4
+ data.tar.gz: 99719f1d58bb92015a8e22d5931fcbd572d3d434bb7e2af2e4cb02c27fc3f021
5
5
  SHA512:
6
- metadata.gz: d7ae82e05e3b4c2ff44a897970baa0aa0a8e6748eb0ad5f986e8dd1004787ea5952420ed183a3d9d3d3276782afad0bbcfdf57c1b5b745f7a29269fff316d254
7
- data.tar.gz: 33397a7b74154abac5e017e9d9f5187a2ef48e120ed71493f1e4f55066193fce706aab21fd8ff6f26bbafcbc47edd19817ccdf6419828433026e7d8a9abc8874
6
+ metadata.gz: 8cb47bdd9901bec180f8390a0be9a07f102c8f3f2de03212b6e23aa17e0455a30659dcf74d2366865a7d57cc166a5e7c046cde6f01a62e560b9b51a31d6d8691
7
+ data.tar.gz: f7276e602968a6d3e81af8cf5db1e14379538c241c1221c7ba906da7004f336040144d4d2522bed14768a6eb44f4aaf8deea484981a03cdddd1cef447c1af075
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Enumlingo
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/enumlingo.svg)](https://badge.fury.io/rb/enumlingo)
4
+
3
5
  Enumlingo is a simple gem that helps you translate enum values in your Rails app.
4
6
 
5
7
  ## Usage
@@ -25,23 +27,23 @@ en:
25
27
  activerecord:
26
28
  attributes:
27
29
  product:
28
- status:
29
- active: "Active"
30
- inactive: "Inactive"
31
- kind:
32
- book: "Book"
33
- food: "Food"
34
- medical: "Medical"
35
- other: "Other"
30
+ statuses:
31
+ active: "Active"
32
+ inactive: "Inactive"
33
+ kinds:
34
+ book: "Book"
35
+ food: "Food"
36
+ medical: "Medical"
37
+ other: "Other"
36
38
 
37
39
  "zh-CN":
38
40
  activerecord:
39
41
  attributes:
40
42
  product:
41
- status:
43
+ statuses:
42
44
  active: "激活"
43
45
  inactive: "未激活"
44
- kind:
46
+ kinds:
45
47
  book: "书籍"
46
48
  food: "食品"
47
49
  medical: "医疗"
@@ -63,8 +65,17 @@ product.kind_lingo # => "书籍"
63
65
  ### Options translation
64
66
 
65
67
  ```ruby
68
+ # Translate options with key
66
69
  Product.statuses_lingo # => [["Active", "active"], ["Inactive", "inactive"]]
67
70
  Product.kinds_lingo # => [["Book", "book"], ["Food", "food"], ["Medical", "medical"], ["Other", "other"]]
71
+
72
+ # Translate options with value
73
+ Product.statuses_lingo_values # => [["Active", 0], ["Inactive", 1]]
74
+ Product.kinds_lingo_values # => [["Book", 0], ["Food", 1], ["Medical", 2], ["Other", 3]]
75
+ ```
76
+
77
+ ```ruby
78
+ Product.status_lingo(:active) # => "Active"
68
79
  ```
69
80
 
70
81
  ### Form translation
@@ -3,15 +3,25 @@ module Enumlingo
3
3
  attributes.each do |attribute|
4
4
  pluralized_attribute = attribute.to_s.pluralize
5
5
 
6
- define_method "#{attribute}_lingo" do
6
+ define_method "#{attribute}_lingo" do |locale: I18n.locale|
7
7
  value = send(attribute)
8
8
  # return nil if value.nil?
9
- I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{value}")
9
+ I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{value}", locale: locale)
10
10
  end
11
11
 
12
- define_singleton_method "#{attribute.to_s.pluralize}_lingo" do
12
+ define_singleton_method "#{pluralized_attribute}_lingo" do |locale: I18n.locale|
13
13
  send(attribute.to_s.pluralize).map do |key, value|
14
- [I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}"), key]
14
+ [I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale), key]
15
+ end
16
+ end
17
+
18
+ define_singleton_method "#{attribute}_lingo" do |key, locale: I18n.locale|
19
+ I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale)
20
+ end
21
+
22
+ define_singleton_method "#{pluralized_attribute}_lingo_values" do |locale: I18n.locale|
23
+ send(attribute.to_s.pluralize).map do |key, value|
24
+ [I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{pluralized_attribute}.#{key}", locale: locale), value]
15
25
  end
16
26
  end
17
27
  end
@@ -1,3 +1,3 @@
1
1
  module Enumlingo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumlingo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iuhoay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-11 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,7 +50,7 @@ metadata:
50
50
  homepage_uri: https://github.com/iuhoay/enumlingo
51
51
  source_code_uri: https://github.com/iuhoay/enumlingo
52
52
  changelog_uri: https://github.com/iuhoay/enumlingo/blob/main/CHANGELOG.md
53
- post_install_message:
53
+ post_install_message:
54
54
  rdoc_options: []
55
55
  require_paths:
56
56
  - lib
@@ -65,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.4.22
69
- signing_key:
68
+ rubygems_version: 3.5.6
69
+ signing_key:
70
70
  specification_version: 4
71
71
  summary: Enumlingo is a lightweight Ruby gem designed to enhance Rails applications
72
72
  by offering straightforward internationalization for enum fields. It simplifies