isomorfeus-i18n 2.0.10 → 2.0.14

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: d605567bda1c6c15752e586e466070e8d66223bae3e798862a968c600cf20bcf
4
+ data.tar.gz: 81752f5ea8b565641e431545aa04aa7639610f2b1124bab1355a10bf209eb83f
5
5
  SHA512:
6
- metadata.gz: 780a3e909248c1aebf214146629f74a7644820638cb224f99e582fce75195bf28dc6558d6dbef6c9134552b6a4d58cb63475f1e3af6571ffc3e5dafcfc84905f
7
- data.tar.gz: 0e450a393d056c601cf742afde7ea0d4d75b5649c0c9ff7b78bdc0fc9d5833e000b2ba51a2eca3573bf11cebb9ef3987bc94460fe762c342efb0b5e1a1bdbbc3
6
+ metadata.gz: 6632f0a848dd398a0860417710f1f2d13ce1c5771969654aabcb9b34edd31ce634a01f52d278cf59174d145be89834a6474a02bca8f6065a6bd726ebfad61b01
7
+ data.tar.gz: b7aabeb918ab0c193210163c9e964a1cc8c517c3fb5ff6db38c3885a93b333aa8998562c66d015746fd7c4bf537bb9c9f6f6433aebeb1f4f49257d8000f3eb3e
@@ -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,50 @@
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
+ agent.process do
22
+ @initializing = false
23
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
24
+ @initialized = true
25
25
  end
26
- @initializing = false
27
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
28
26
  end
29
27
  end
30
- end
31
28
 
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
29
+ def reload_from_server
30
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.negotiated_locale).then do |agent|
31
+ agent.process do
32
+ Isomorfeus.store.dispatch(type: 'I18N_STATE', set_state: agent.response[:data])
33
+ end
34
+ end
35
+ end
36
+
37
+ def initialized?
38
+ @initialized
39
+ end
40
+ else
41
+ def init
42
+ FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
43
+ FastGettext.available_locales = Isomorfeus.available_locales
44
+ FastGettext.text_domain = Isomorfeus.i18n_domain
45
+ FastGettext.locale = Isomorfeus.locale
46
+ Thread.current[:isomorfeus_i18n_initialized] = true
47
+ end
43
48
  end
44
49
  end
45
50
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module I18n
3
- VERSION = '2.0.10'
3
+ VERSION = '2.0.14'
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,44 @@ 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
+ agent.process do
116
+ if on_browser?
117
+ Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
118
+ else
119
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
120
+ end
121
+ end
122
+ end
175
123
  else
124
+ class InternalTranslationProxy
125
+ extend FastGettext::Translation
126
+ extend FastGettext::TranslationMultidomain
127
+ end
128
+
176
129
  TRANSLATION_METHODS.each do |method|
177
130
  define_method(method) do |domain, *args, &block|
178
131
  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.14
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-02 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.25
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.25
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.14
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.14
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.14
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.14
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.14
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.14
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement