isomorfeus-i18n 2.0.10 → 2.0.11

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: e4bc737c68ff0c61721a12a27ae685ce04fafc1d9b9145b624671404a10a75d7
4
- data.tar.gz: a0331414ad506e6ac33c612e9b08bbea957b25b64463d151829941911f31111d
3
+ metadata.gz: d002b992f26be143f247b1443986d96a7f83005667069d1d2b8a448d21e7947d
4
+ data.tar.gz: 64e017a696a6b0e507fcb5993b0686b0999184c0baf4dd8ea5254d65b0458691
5
5
  SHA512:
6
- metadata.gz: 780a3e909248c1aebf214146629f74a7644820638cb224f99e582fce75195bf28dc6558d6dbef6c9134552b6a4d58cb63475f1e3af6571ffc3e5dafcfc84905f
7
- data.tar.gz: 0e450a393d056c601cf742afde7ea0d4d75b5649c0c9ff7b78bdc0fc9d5833e000b2ba51a2eca3573bf11cebb9ef3987bc94460fe762c342efb0b5e1a1bdbbc3
6
+ metadata.gz: 791ef3d52d452536de39d7f4e7575ba348231fb21d3cb9c0c506bcd9c467df2cb692eeeb2df5ce0cd2871886c9317cb02354132aafded8ee4d36ce19c5edfccc
7
+ data.tar.gz: 29027a78469dc1d5637bd8dc6374b799c5518095ecab291024ec221d82887cce8254585bca65ce1683807f921c391dfd1be540c3b5c919e274d3553562d2ec1a
@@ -1,45 +1,48 @@
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 initialized?
36
+ @initialized
37
+ end
38
+ else
39
+ def init
40
+ FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
41
+ FastGettext.available_locales = Isomorfeus.available_locales
42
+ FastGettext.text_domain = Isomorfeus.i18n_domain
43
+ FastGettext.locale = Isomorfeus.locale
44
+ Thread.current[:isomorfeus_i18n_initialized] = true
45
+ end
43
46
  end
44
47
  end
45
48
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module I18n
3
- VERSION = '2.0.10'
3
+ VERSION = '2.0.11'
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.10
4
+ version: 2.0.11
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-01-31 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.7
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.7
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.23
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.23
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.10
145
+ version: 2.0.11
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.10
152
+ version: 2.0.11
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.10
159
+ version: 2.0.11
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.10
166
+ version: 2.0.11
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.10
173
+ version: 2.0.11
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.10
180
+ version: 2.0.11
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement