isomorfeus-i18n 2.0.9 → 2.0.13

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: '0165259f2bf939eff485ce0da4908c9953b1baac391a65030dad19acd6d62027'
4
- data.tar.gz: 4d76412fad36fde2c64a266a884717f5e6917402ae07a68019e836a198ae82ad
3
+ metadata.gz: ea585a5bea7705cbbe044ced0b6d36d2c5abcea25ce7d769b9cd6f23c24c2cbc
4
+ data.tar.gz: f348a005aa131e9fe8ccf2c79ddf8360be8afe29bcff99ee397a716229838aba
5
5
  SHA512:
6
- metadata.gz: e447e01c12c0fad624f42e654b6a8f9f5c967153ba19f450f04ded65573d24329c40831caf854c06bf674c9da7e23aac15639bad0c15598d1e8bbacf7847baf7
7
- data.tar.gz: 7164a21e338aab63cc5c02480989c94f8687497d1e70e3302eecf88fefb5406d1998f0cace4851327695718966b3e5e026ac2b23c66b4289252468b54beecedb
6
+ metadata.gz: 6a6270eef401a5b9876ef8d8bebac278866715accc7bc5e0ab22c1e72171670145e911d2ec008c3ffd568e93a251ec5c80ca9b2f55437c79fb67f3ba63b4445c
7
+ data.tar.gz: 6e58bf7de6ae186ec8f70fcd68b2de0a582e8d48981c76a3642a3dca42a9d74882b7d76239b7a5713e0df3a59855da2f1192915138e68d2492411508c3556553
@@ -18,12 +18,13 @@ module Isomorfeus
18
18
  'domain' => FastGettext.text_domain }
19
19
  response_agent.agent_result['data']['locale'] = if Isomorfeus.available_locales.include?(locale)
20
20
  locale
21
- else
22
- FastGettext.locale
23
- end
21
+ else
22
+ FastGettext.locale
23
+ end
24
24
  else
25
25
  response_agent.agent_result[domain] = {}
26
26
  begin
27
+ Isomorfeus::I18n::Init.init if Isomorfeus.development?
27
28
  FastGettext.with_domain(domain) do
28
29
  response_agent.request[domain].each_key do |locale|
29
30
  response_agent.agent_result[domain][locale] = {}
@@ -1,45 +1,62 @@
1
1
  module Isomorfeus
2
2
  module I18n
3
3
  class Init
4
- if RUBY_ENGINE == 'opal'
5
- def self.init
6
- return if @initializing || initialized?
7
- @initializing = true
8
- if Isomorfeus.on_browser?
9
- root_element = `document.querySelector('div[data-iso-root]')`
10
- Isomorfeus.negotiated_locale = root_element.JS.getAttribute('data-iso-nloc') if root_element
11
- init_from_server
12
- else
13
- init_from_server
4
+ class << self
5
+ if RUBY_ENGINE == 'opal'
6
+ attr_accessor :init_promise
7
+
8
+ def init
9
+ return if @initializing || initialized?
10
+ @initializing = true
11
+ @initialized = false
12
+ if Isomorfeus.on_browser?
13
+ root_element = `document.querySelector('div[data-iso-root]')`
14
+ Isomorfeus.negotiated_locale = root_element.JS.getAttribute('data-iso-nloc') if root_element
15
+ end
16
+ self.init_promise = init_from_server
14
17
  end
15
- end
16
18
 
17
- def self.init_from_server
18
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.negotiated_locale).then do |agent|
19
- if agent.processed
20
- agent.result
21
- else
22
- agent.processed = true
23
- if agent.response.key?(:error)
24
- Isomorfeus.raise_error(message: agent.response[:error])
19
+ def init_from_server
20
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.negotiated_locale).then do |agent|
21
+ if agent.processed
22
+ agent.result
23
+ else
24
+ agent.processed = true
25
+ if agent.response.key?(:error)
26
+ Isomorfeus.raise_error(message: agent.response[:error])
27
+ end
28
+ @initializing = false
29
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
30
+ @initialized = true
25
31
  end
26
- @initializing = false
27
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
28
32
  end
29
33
  end
30
- end
31
34
 
32
- def self.initialized?
33
- result = Redux.fetch_by_path(:i18n_state, :available_locales)
34
- result ? true : false
35
- end
36
- else
37
- def self.init
38
- FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
39
- FastGettext.available_locales = Isomorfeus.available_locales
40
- FastGettext.text_domain = Isomorfeus.i18n_domain
41
- FastGettext.locale = Isomorfeus.locale
42
- Thread.current[:isomorfeus_i18n_initialized] = true
35
+ def reload_from_server
36
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.negotiated_locale).then do |agent|
37
+ if agent.processed
38
+ agent.result
39
+ else
40
+ agent.processed = true
41
+ if agent.response.key?(:error)
42
+ Isomorfeus.raise_error(message: agent.response[:error])
43
+ end
44
+ Isomorfeus.store.dispatch(type: 'I18N_STATE', set_state: agent.response[:data])
45
+ end
46
+ end
47
+ end
48
+
49
+ def initialized?
50
+ @initialized
51
+ end
52
+ else
53
+ def init
54
+ FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
55
+ FastGettext.available_locales = Isomorfeus.available_locales
56
+ FastGettext.text_domain = Isomorfeus.i18n_domain
57
+ FastGettext.locale = Isomorfeus.locale
58
+ Thread.current[:isomorfeus_i18n_initialized] = true
59
+ end
43
60
  end
44
61
  end
45
62
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module I18n
3
- VERSION = '2.0.9'
3
+ VERSION = '2.0.13'
4
4
  end
5
5
  end
@@ -5,13 +5,6 @@ module LucidTranslation
5
5
  NIL_BLOCK = -> { nil }
6
6
  TRANSLATION_METHODS = [:_, :n_, :np_, :ns_, :p_, :s_]
7
7
 
8
- if RUBY_ENGINE != 'opal'
9
- class InternalTranslationProxy
10
- extend FastGettext::Translation
11
- extend FastGettext::TranslationMultidomain
12
- end
13
- end
14
-
15
8
  if RUBY_ENGINE == 'opal'
16
9
  def _(*keys, &block)
17
10
  domain = Isomorfeus.i18n_domain
@@ -19,19 +12,7 @@ module LucidTranslation
19
12
  Isomorfeus.raise_error(message: "I18n _(): no key given!") if keys.empty?
20
13
  result = Redux.fetch_by_path(:i18n_state, domain, locale, '_', keys)
21
14
  return result if result
22
- if Isomorfeus::I18n::Init.initialized?
23
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, '_', keys).then do |agent|
24
- if agent.processed
25
- agent.result
26
- else
27
- agent.processed = true
28
- if agent.response.key?(:error)
29
- Isomorfeus.raise_error(message: agent.response[:error])
30
- end
31
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
32
- end
33
- end
34
- end
15
+ _promise_send_i18n_method(domain, locale, '_', keys)
35
16
  block_given? ? block.call : keys.first
36
17
  end
37
18
 
@@ -41,19 +22,7 @@ module LucidTranslation
41
22
  Isomorfeus.raise_error(message: "I18n n_(): no key given!") if keys.empty?
42
23
  result = Redux.fetch_by_path(:i18n_state, domain, locale, 'n_', keys + [count])
43
24
  return result if result
44
- if Isomorfeus::I18n::Init.initialized?
45
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'n_', keys + [count]).then do |agent|
46
- if agent.processed
47
- agent.result
48
- else
49
- agent.processed = true
50
- if agent.response.key?(:error)
51
- Isomorfeus.raise_error(message: agent.response[:error])
52
- end
53
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
54
- end
55
- end
56
- end
25
+ _promise_send_i18n_method(domain, locale, 'n_', keys + [count])
57
26
  block_given? ? block.call : keys.last
58
27
  end
59
28
 
@@ -61,7 +30,6 @@ module LucidTranslation
61
30
  nargs = ["#{context}#{separator || CONTEXT_SEPARATOR}#{plural_one}"] + args
62
31
  translation = n_(*nargs, &NIL_BLOCK)
63
32
  return translation if translation
64
-
65
33
  block_given? ? block.call : n_(plural_one, *args)
66
34
  end
67
35
 
@@ -71,19 +39,7 @@ module LucidTranslation
71
39
  Isomorfeus.raise_error(message: "I18n ns_(): no args given!") if args.empty?
72
40
  result = Redux.fetch_by_path(:i18n_state, domain, locale, 'ns_', args)
73
41
  return result if result
74
- if Isomorfeus::I18n::Init.initialized?
75
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'ns_', args).then do |agent|
76
- if agent.processed
77
- agent.result
78
- else
79
- agent.processed = true
80
- if agent.response.key?(:error)
81
- Isomorfeus.raise_error(message: agent.response[:error])
82
- end
83
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
84
- end
85
- end
86
- end
42
+ _promise_send_i18n_method(domain, locale, 'ns_', args)
87
43
  block_given? ? block.call : n_(*args).split(NAMESPACE_SEPARATOR).last
88
44
  end
89
45
 
@@ -93,19 +49,7 @@ module LucidTranslation
93
49
  args = separator ? [namespace, key, separator] : [namespace, key]
94
50
  result = Redux.fetch_by_path(:i18n_state, domain, locale, 'p_', args)
95
51
  return result if result
96
- if Isomorfeus::I18n::Init.initialized?
97
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 'p_', args).then do |agent|
98
- if agent.processed
99
- agent.result
100
- else
101
- agent.processed = true
102
- if agent.response.key?(:error)
103
- Isomorfeus.raise_error(message: agent.response[:error])
104
- end
105
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
106
- end
107
- end
108
- end
52
+ _promise_send_i18n_method(domain, locale, 'p_', args)
109
53
  block_given? ? block.call : key
110
54
  end
111
55
 
@@ -115,19 +59,7 @@ module LucidTranslation
115
59
  args = separator ? [key, separator] : [key]
116
60
  result = Redux.fetch_by_path(:i18n_state, domain, locale, 's_', args)
117
61
  return result if result
118
- if Isomorfeus::I18n::Init.initialized?
119
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, 's_', args).then do |agent|
120
- if agent.processed
121
- agent.result
122
- else
123
- agent.processed = true
124
- if agent.response.key?(:error)
125
- Isomorfeus.raise_error(message: agent.response[:error])
126
- end
127
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
128
- end
129
- end
130
- end
62
+ _promise_send_i18n_method(domain, locale, 's_', args)
131
63
  block_given? ? block.call : key.split(separator || NAMESPACE_SEPARATOR).last
132
64
  end
133
65
 
@@ -156,23 +88,50 @@ module LucidTranslation
156
88
  Isomorfeus.raise_error(message: "I18n D#{method}(): no args given!") if args.empty?
157
89
  result = Redux.fetch_by_path(:i18n_state, domain, locale, "D#{method}", args)
158
90
  return result if result
159
- if Isomorfeus::I18n::Init.initialized?
160
- Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, "D#{method}", args).then do |agent|
161
- if agent.processed
162
- agent.result
163
- else
164
- agent.processed = true
165
- if agent.response.key?(:error)
166
- Isomorfeus.raise_error(message: agent.response[:error])
167
- end
168
- Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
169
- end
170
- end
171
- end
91
+ _promise_send_i18n_method(domain, locale, "D#{method}", args)
172
92
  block_given? ? block.call : send(method, *args, &block)
173
93
  end
174
94
  end
95
+
96
+ private
97
+
98
+ def _promise_send_i18n_method(domain, locale, method, args)
99
+ if Isomorfeus::I18n::Init.initialized?
100
+ _promise_send_i18n_request(domain, locale, method, args)
101
+ else
102
+ Isomorfeus::I18n::Init.init_promise.then do
103
+ _promise_send_i18n_request(domain, locale, method, args)
104
+ end
105
+ end
106
+ end
107
+
108
+ def _promise_send_i18n_request(domain, locale, method, args)
109
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, method, args).then do |agent|
110
+ _handle_i18n_response(agent, domain)
111
+ end
112
+ end
113
+
114
+ def _handle_i18n_response(agent, domain)
115
+ if agent.processed
116
+ agent.result
117
+ else
118
+ agent.processed = true
119
+ if agent.response.key?(:error)
120
+ Isomorfeus.raise_error(message: agent.response[:error])
121
+ end
122
+ if on_browser?
123
+ Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
124
+ else
125
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
126
+ end
127
+ end
128
+ end
175
129
  else
130
+ class InternalTranslationProxy
131
+ extend FastGettext::Translation
132
+ extend FastGettext::TranslationMultidomain
133
+ end
134
+
176
135
  TRANSLATION_METHODS.each do |method|
177
136
  define_method(method) do |domain, *args, &block|
178
137
  Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
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: 2.0.9
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.14.6
103
+ version: 0.14.8
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.14.6
110
+ version: 0.14.8
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: isomorfeus-preact
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 10.6.14
117
+ version: 10.6.24
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 10.6.14
124
+ version: 10.6.24
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: isomorfeus-redux
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,42 +142,42 @@ dependencies:
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 2.0.9
145
+ version: 2.0.13
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: 2.0.9
152
+ version: 2.0.13
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: isomorfeus-data
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 2.0.9
159
+ version: 2.0.13
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 2.0.9
166
+ version: 2.0.13
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: isomorfeus
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 2.0.9
173
+ version: 2.0.13
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 2.0.9
180
+ version: 2.0.13
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement