translate_enum 0.1.1 → 0.1.2

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
- SHA1:
3
- metadata.gz: '0458034e29b34aa38f6ef31d4953f49b251c64d7'
4
- data.tar.gz: 0fba5acb5a6f1ab53d84cd3fd16c43de285c34a5
2
+ SHA256:
3
+ metadata.gz: e77857ff770931aacd8caa9d704f2678d6befd15cf830a33821fe6a594c61558
4
+ data.tar.gz: 5741720d55c013d5b7490a56eecb5fccf9a7e60f53ff1c9e578939c651b2e44a
5
5
  SHA512:
6
- metadata.gz: f98032ffc41ba60eabea064af70fa58c083665bf1378379f79e4ff1a5db9a21554ace3b74290962085f34019879cc9f2602d6d2fc1c8b5098d532c8d44ee05ef
7
- data.tar.gz: f32895d7d47d84777a602cbb381866f463de14b90852ab7119ab9b9add9a6bad58af105236f4e31d7f9e86721ba08bf862f43699c0e954f025a88735b6e25b70
6
+ metadata.gz: 8eb9415674c8b1cb5d768243c10468ad5b57682501000beaf304fa3074e10d7ec06c55d71dbf6c0bb72024fb31af6b2ef73ecef2f9c51746a1e89450de2ff728
7
+ data.tar.gz: 4d6556564500f1bf540b7b02359d2b15ee0422327a6ece5afd3d95650da1ed51a8542873bd8b9967ab933507f2480b9658c366982d85173a40e08645d72d7997
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.2
2
+ * add support of default locale lookup (en.attributes) to share locales between models
data/README.md CHANGED
@@ -31,12 +31,22 @@ en:
31
31
  post:
32
32
  status_list:
33
33
  published: Was published
34
- archive: Was achieved
34
+ archive: Was archived
35
+ ```
36
+
37
+ Or if you wish your locales to be available across all models
38
+
39
+ ```yaml
40
+ en:
41
+ attributes:
42
+ status_list:
43
+ published: Was published
44
+ archive: Was archived
35
45
  ```
36
46
 
37
47
  ```ruby
38
48
  Post.translated_status(:published) #=> "Was published"
39
- Post.translated_statuses => [["Was published", :published, 0], ["Was achieved", :archive, 1]]
49
+ Post.translated_statuses => [["Was published", :published, 0], ["Was archived", :archive, 1]]
40
50
 
41
51
  @post = Post.new(status: :published)
42
52
  @post.translated_status #=> "Was published"
@@ -46,7 +56,7 @@ Post.translated_statuses => [["Was published", :published, 0], ["Was achieved",
46
56
 
47
57
  ```haml
48
58
  = form_for @post do |f|
49
- = f.select :status, options_for_select(f.object.translated_statuses.map { |translation, k, _v| [translation, k] })
59
+ = f.select :status, options_for_select(f.object.class.translated_statuses.map { |translation, k, _v| [translation, k] })
50
60
  ```
51
61
 
52
62
  ## Extending ActiveRecord
@@ -32,6 +32,10 @@ module TranslateEnum
32
32
  "#{model.model_name.i18n_key}.#{i18n_key}.#{key}"
33
33
  end
34
34
 
35
+ def i18n_default_location(key)
36
+ :"attributes.#{i18n_key}.#{key}"
37
+ end
38
+
35
39
  # @param [String]
36
40
  # like "translated_genders"
37
41
  def method_name_plural
@@ -1,3 +1,3 @@
1
1
  module TranslateEnum
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -21,7 +21,7 @@ module TranslateEnum
21
21
 
22
22
  # User.translated_status(:active)
23
23
  define_singleton_method(builder.method_name_singular) do |key|
24
- I18n.translate(builder.i18n_location(key), scope: builder.i18n_scope)
24
+ I18n.translate("#{builder.i18n_scope}.#{builder.i18n_location(key)}", default: builder.i18n_default_location(key))
25
25
  end
26
26
 
27
27
  # @return [Array]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translate_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
+ - CHANGELOG.md
120
121
  - Gemfile
121
122
  - README.md
122
123
  - Rakefile
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  requirements: []
148
149
  rubyforge_project:
149
- rubygems_version: 2.6.10
150
+ rubygems_version: 2.7.3
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Rails translate enum