isomorfeus-i18n 1.0.0.delta11 → 1.0.0.delta12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 517b69898ba863abe013e1d04288970a6d398137ab4b39b7ef8a8b604ffffeb8
4
- data.tar.gz: 7d9afaa9e3ec79ff07e6c76c921024ce79e521b0d947f05f9c5219675e466e60
3
+ metadata.gz: 5f8f296a3740f5e9885d04fd9bfe7c69e918382db5408e361c28b03812486d39
4
+ data.tar.gz: b6f4cc30d1622f4c16eebf50a99d2f1073ff3c19fe0936952bb5973eea6e93c5
5
5
  SHA512:
6
- metadata.gz: 0fad88f98f0c80b712301e0ade3bc72cb8de6496cd7fc0451b1acd715e92fa55f3c07a82ce2c7eb0e6a76645faeac2b2b4fa2f61f5d63bdad39fd83a4bd582ac
7
- data.tar.gz: 5bdb60a2804cee36df9ead50fa1081efc2ee709334619ac7a848a6e3bd4f006f29ba310e87a80f7fc26a34c8a05bcc36d08d051ff7f497018eb77a7b822819d1
6
+ metadata.gz: 12b91afde9dbbf23240d97c86ac03c5d943d8db0e3152250200e8b99018506485b80cf43182f9903785176d2dfc8e812b438f81932e25df8753b833529cbdd00
7
+ data.tar.gz: 7abcb0c9c5566c798eec46e65f43a1051ce0709f17df11fa83c4ac672750c6ea09527ef6a4d43fb96d9162c4428bdcc94b065d87efefa9ac26f706d05f656b13
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # isomorfeus-i18n
2
+
3
+ Locale files go in my_app/isomorfeus/locales.
4
+ Supported formats: .mo, .po, .yml
5
+
6
+ Using fast_gettext internally.
7
+
8
+ ## Usage
9
+
10
+ In any class:
11
+ ```
12
+ include LucidTranslation::Mixin
13
+ ```
14
+
15
+ after which the _ gettext methods are available for translation.
16
+ See https://github.com/grosser/fast_gettext and https://rubydoc.info/gems/gettext/
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module I18n
3
- VERSION = '1.0.0.delta11'
3
+ VERSION = '1.0.0.delta12'
4
4
  end
5
5
  end
@@ -12,219 +12,153 @@ module LucidTranslation
12
12
  end
13
13
  end
14
14
 
15
- def self.included(base)
16
- if RUBY_ENGINE == 'opal'
17
- base.instance_exec do
18
- def _(*keys, &block)
19
- domain = Isomorfeus.i18n_domain
20
- locale = Isomorfeus.locale
21
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, '_', keys)
22
- return result if result
23
- if Isomorfeus::I18n::Init.initialized?
24
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, '_', keys).then do |response|
25
- if response[:agent_response].key?(:error)
26
- `console.error(#{response[:agent_response][:error].to_n})`
27
- raise response[:agent_response][:error]
28
- end
29
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
30
- end
15
+ if RUBY_ENGINE == 'opal'
16
+ def _(*keys, &block)
17
+ domain = Isomorfeus.i18n_domain
18
+ locale = Isomorfeus.locale
19
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, '_', keys)
20
+ return result if result
21
+ if Isomorfeus::I18n::Init.initialized?
22
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, '_', keys).then do |response|
23
+ if response[:agent_response].key?(:error)
24
+ `console.error(#{response[:agent_response][:error].to_n})`
25
+ raise response[:agent_response][:error]
31
26
  end
32
- block_given? ? block.call : keys.first
27
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
33
28
  end
29
+ end
30
+ block_given? ? block.call : keys.first
31
+ end
34
32
 
35
- def n_(*keys, count, &block)
36
- domain = Isomorfeus.i18n_domain
37
- locale = Isomorfeus.locale
38
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'n_', keys + [count])
39
- return result if result
40
- if Isomorfeus::I18n::Init.initialized?
41
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'n_', keys + [count]).then do |response|
42
- if response[:agent_response].key?(:error)
43
- `console.error(#{response[:agent_response][:error].to_n})`
44
- raise response[:agent_response][:error]
45
- end
46
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
47
- end
33
+ def n_(*keys, count, &block)
34
+ domain = Isomorfeus.i18n_domain
35
+ locale = Isomorfeus.locale
36
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'n_', keys + [count])
37
+ return result if result
38
+ if Isomorfeus::I18n::Init.initialized?
39
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'n_', keys + [count]).then do |response|
40
+ if response[:agent_response].key?(:error)
41
+ `console.error(#{response[:agent_response][:error].to_n})`
42
+ raise response[:agent_response][:error]
48
43
  end
49
- block_given? ? block.call : keys.last
44
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
50
45
  end
46
+ end
47
+ block_given? ? block.call : keys.last
48
+ end
51
49
 
52
- def np_(context, plural_one, *args, separator: nil, &block)
53
- nargs = ["#{context}#{separator || CONTEXT_SEPARATOR}#{plural_one}"] + args
54
- translation = n_(*nargs, &NIL_BLOCK)
55
- return translation if translation
56
-
57
- block_given? ? block.call : n_(plural_one, *args)
58
- end
50
+ def np_(context, plural_one, *args, separator: nil, &block)
51
+ nargs = ["#{context}#{separator || CONTEXT_SEPARATOR}#{plural_one}"] + args
52
+ translation = n_(*nargs, &NIL_BLOCK)
53
+ return translation if translation
59
54
 
60
- def ns_(*args, &block)
61
- domain = Isomorfeus.i18n_domain
62
- locale = Isomorfeus.locale
63
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'ns_', args)
64
- return result if result
65
- if Isomorfeus::I18n::Init.initialized?
66
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'ns_', args).then do |response|
67
- if response[:agent_response].key?(:error)
68
- `console.error(#{response[:agent_response][:error].to_n})`
69
- raise response[:agent_response][:error]
70
- end
71
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
72
- end
73
- end
74
- block_given? ? block.call : n_(*args).split(NAMESPACE_SEPARATOR).last
75
- end
55
+ block_given? ? block.call : n_(plural_one, *args)
56
+ end
76
57
 
77
- def p_(namespace, key, separator = nil, &block)
78
- domain = Isomorfeus.i18n_domain
79
- locale = Isomorfeus.locale
80
- args = separator ? [namespace, key, separator] : [namespace, key]
81
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'p_', args)
82
- return result if result
83
- if Isomorfeus::I18n::Init.initialized?
84
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'p_', args).then do |response|
85
- if response[:agent_response].key?(:error)
86
- `console.error(#{response[:agent_response][:error].to_n})`
87
- raise response[:agent_response][:error]
88
- end
89
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
90
- end
58
+ def ns_(*args, &block)
59
+ domain = Isomorfeus.i18n_domain
60
+ locale = Isomorfeus.locale
61
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'ns_', args)
62
+ return result if result
63
+ if Isomorfeus::I18n::Init.initialized?
64
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'ns_', args).then do |response|
65
+ if response[:agent_response].key?(:error)
66
+ `console.error(#{response[:agent_response][:error].to_n})`
67
+ raise response[:agent_response][:error]
91
68
  end
92
- block_given? ? block.call : key
69
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
93
70
  end
71
+ end
72
+ block_given? ? block.call : n_(*args).split(NAMESPACE_SEPARATOR).last
73
+ end
94
74
 
95
- def s_(key, separator = nil, &block)
96
- domain = Isomorfeus.i18n_domain
97
- locale = Isomorfeus.locale
98
- args = separator ? [key, separator] : [key]
99
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 's_', args)
100
- return result if result
101
- if Isomorfeus::I18n::Init.initialized?
102
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 's_', args).then do |response|
103
- if response[:agent_response].key?(:error)
104
- `console.error(#{response[:agent_response][:error].to_n})`
105
- raise response[:agent_response][:error]
106
- end
107
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
108
- end
75
+ def p_(namespace, key, separator = nil, &block)
76
+ domain = Isomorfeus.i18n_domain
77
+ locale = Isomorfeus.locale
78
+ args = separator ? [namespace, key, separator] : [namespace, key]
79
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 'p_', args)
80
+ return result if result
81
+ if Isomorfeus::I18n::Init.initialized?
82
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'p_', args).then do |response|
83
+ if response[:agent_response].key?(:error)
84
+ `console.error(#{response[:agent_response][:error].to_n})`
85
+ raise response[:agent_response][:error]
109
86
  end
110
- block_given? ? block.call : key.split(separator || NAMESPACE_SEPARATOR).last
111
- end
112
-
113
- def N_(translate)
114
- translate
87
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
115
88
  end
89
+ end
90
+ block_given? ? block.call : key
91
+ end
116
92
 
117
- def Nn_(*keys)
118
- keys
119
- end
120
-
121
- TRANSLATION_METHODS.each do |method|
122
- define_singleton_method("d#{method}") do |domain, *args, &block|
123
- old_domain = Isomorfeus.i18n_domain
124
- begin
125
- Isomorfeus.i18n_domain = domain
126
- send(method, *args, &block)
127
- ensure
128
- Isomorfeus.i18n_domain = old_domain
129
- end
130
- end
131
-
132
- define_singleton_method("D#{method}") do |*args, &block|
133
- domain = Isomorfeus.i18n_domain
134
- locale = Isomorfeus.locale
135
- result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, "D#{method}", args)
136
- return result if result
137
- if Isomorfeus::I18n::Init.initialized?
138
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, "D#{method}", args).then do |response|
139
- if response[:agent_response].key?(:error)
140
- `console.error(#{response[:agent_response][:error].to_n})`
141
- raise response[:agent_response][:error]
142
- end
143
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
144
- end
145
- end
146
- block_given? ? block.call : send(method, *args, &block)
93
+ def s_(key, separator = nil, &block)
94
+ domain = Isomorfeus.i18n_domain
95
+ locale = Isomorfeus.locale
96
+ args = separator ? [key, separator] : [key]
97
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, 's_', args)
98
+ return result if result
99
+ if Isomorfeus::I18n::Init.initialized?
100
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 's_', args).then do |response|
101
+ if response[:agent_response].key?(:error)
102
+ `console.error(#{response[:agent_response][:error].to_n})`
103
+ raise response[:agent_response][:error]
147
104
  end
105
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
148
106
  end
149
107
  end
108
+ block_given? ? block.call : key.split(separator || NAMESPACE_SEPARATOR).last
109
+ end
150
110
 
151
- def _(*args, &block)
152
- self.class._(*args, &block)
153
- end
154
-
155
- def n_(*args, &block)
156
- self.class.n_(*args, &block)
157
- end
158
-
159
- def np_(*args, &block)
160
- self.class.np_(*args, &block)
161
- end
162
-
163
- def ns_(*args, &block)
164
- self.class.n_(*args, &block)
165
- end
166
-
167
- def p_(*args, &block)
168
- self.class.p_(*args, &block)
169
- end
170
-
171
- def s(*args, &block)
172
- self.class.s_(*args, &block)
173
- end
174
-
175
- def N_(translate)
176
- translate
177
- end
178
-
179
- def Nn_(*keys)
180
- keys
181
- end
111
+ def N_(translate)
112
+ translate
113
+ end
182
114
 
183
- TRANSLATION_METHODS.each do |method|
184
- # translate in given domain
185
- define_method("d#{method}") do |domain, *args, &block|
186
- self.class.send("d#{method}", domain, *args, &block)
187
- end
115
+ def Nn_(*keys)
116
+ keys
117
+ end
188
118
 
189
- define_method("D#{method}") do |*args, &block|
190
- self.class.send("D#{method}", *args, &block)
119
+ TRANSLATION_METHODS.each do |method|
120
+ define_method("d#{method}") do |domain, *args, &block|
121
+ old_domain = Isomorfeus.i18n_domain
122
+ begin
123
+ Isomorfeus.i18n_domain = domain
124
+ send(method, *args, &block)
125
+ ensure
126
+ Isomorfeus.i18n_domain = old_domain
191
127
  end
192
128
  end
193
- else
194
- base.instance_exec do
195
- TRANSLATION_METHODS.each do |method|
196
- define_singleton_method(method) do |*args, &block|
197
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
198
- InternalTranslationProxy.send(method, *args, &block)
199
- end
200
129
 
201
- define_singleton_method("d#{method}") do |domain, *args, &block|
202
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
203
- InternalTranslationProxy.send("d#{method}", domain, *args, &block)
204
- end
205
-
206
- define_singleton_method("D#{method}") do |*args, &block|
207
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
208
- InternalTranslationProxy.send.send("D#{method}", *args, &block)
130
+ define_method("D#{method}") do |*args, &block|
131
+ domain = Isomorfeus.i18n_domain
132
+ locale = Isomorfeus.locale
133
+ result = Redux.register_and_fetch_by_path(:i18n_state, domain, locale, "D#{method}", args)
134
+ return result if result
135
+ if Isomorfeus::I18n::Init.initialized?
136
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, "D#{method}", args).then do |response|
137
+ if response[:agent_response].key?(:error)
138
+ `console.error(#{response[:agent_response][:error].to_n})`
139
+ raise response[:agent_response][:error]
140
+ end
141
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => response[:agent_response][domain] })
209
142
  end
210
143
  end
144
+ block_given? ? block.call : send(method, *args, &block)
145
+ end
146
+ end
147
+ else
148
+ TRANSLATION_METHODS.each do |method|
149
+ define_method(method) do |domain, *args, &block|
150
+ Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
151
+ InternalTranslationProxy.send(method, domain, *args, &block)
211
152
  end
212
153
 
213
- TRANSLATION_METHODS.each do |method|
214
- define_method(method) do |domain, *args, &block|
215
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
216
- InternalTranslationProxy.send(method, domain, *args, &block)
217
- end
218
-
219
- define_method("d#{method}") do |domain, *args, &block|
220
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
221
- InternalTranslationProxy.send("d#{method}", domain, *args, &block)
222
- end
154
+ define_method("d#{method}") do |domain, *args, &block|
155
+ Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
156
+ InternalTranslationProxy.send("d#{method}", domain, *args, &block)
157
+ end
223
158
 
224
- define_method("D#{method}") do |*args, &block|
225
- Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
226
- InternalTranslationProxy.send("D#{method}", *args, &block)
227
- end
159
+ define_method("D#{method}") do |*args, &block|
160
+ Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
161
+ InternalTranslationProxy.send("D#{method}", *args, &block)
228
162
  end
229
163
  end
230
164
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.delta11
4
+ version: 1.0.0.delta12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-12 00:00:00.000000000 Z
11
+ date: 2019-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.0.0.delta11
131
+ version: 1.0.0.delta12
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.0.0.delta11
138
+ version: 1.0.0.delta12
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: isomorfeus-data
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 1.0.0.delta11
145
+ version: 1.0.0.delta12
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 1.0.0.delta11
152
+ version: 1.0.0.delta12
153
153
  description: I18n for Isomorfeus.
154
154
  email: jan@kursator.de
155
155
  executables: []
@@ -157,6 +157,7 @@ extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
159
  - LICENSE
160
+ - README.md
160
161
  - lib/isomorfeus-i18n.rb
161
162
  - lib/isomorfeus/i18n/config.rb
162
163
  - lib/isomorfeus/i18n/handler/locale_handler.rb