enumlingo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -10
- data/lib/enumlingo/helper.rb +14 -4
- data/lib/enumlingo/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48cd9e00bd148c28569535cb619d820538dddcdc65bb9a90f23463d44f7dbd15
|
4
|
+
data.tar.gz: 99719f1d58bb92015a8e22d5931fcbd572d3d434bb7e2af2e4cb02c27fc3f021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
43
|
+
statuses:
|
42
44
|
active: "激活"
|
43
45
|
inactive: "未激活"
|
44
|
-
|
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
|
data/lib/enumlingo/helper.rb
CHANGED
@@ -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 "#{
|
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
|
data/lib/enumlingo/version.rb
CHANGED
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.
|
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:
|
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.
|
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
|