isomorfeus-i18n 2.0.10 → 2.0.11
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 +4 -4
- data/lib/isomorfeus/i18n/init.rb +36 -33
- data/lib/isomorfeus/i18n/version.rb +1 -1
- data/lib/lucid_translation/mixin.rb +45 -86
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d002b992f26be143f247b1443986d96a7f83005667069d1d2b8a448d21e7947d
|
4
|
+
data.tar.gz: 64e017a696a6b0e507fcb5993b0686b0999184c0baf4dd8ea5254d65b0458691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 791ef3d52d452536de39d7f4e7575ba348231fb21d3cb9c0c506bcd9c467df2cb692eeeb2df5ce0cd2871886c9317cb02354132aafded8ee4d36ce19c5edfccc
|
7
|
+
data.tar.gz: 29027a78469dc1d5637bd8dc6374b799c5518095ecab291024ec221d82887cce8254585bca65ce1683807f921c391dfd1be540c3b5c919e274d3553562d2ec1a
|
data/lib/isomorfeus/i18n/init.rb
CHANGED
@@ -1,45 +1,48 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module I18n
|
3
3
|
class Init
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
180
|
+
version: 2.0.11
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rake
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|