opal-i18next 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/opal/i18next/i18next.rb +296 -71
- data/opal/i18next/version.rb +1 -1
- data/opal-i18next.gemspec +6 -5
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fcbdd82651c265dc9b07aad0f56ae5dc80b13562e69904c7083d75d297fafed
|
4
|
+
data.tar.gz: 31bc9a0cd604bdc2b911290fd3aa7659dde49782ef8f02f2dee0cbd5df3618f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c81f84936adae8165b9519651d66ca0ffc84b472f1315793fd83157fa0c4bf3473760cef76fd500873544a52414de0cbbc0f09c5b423b8988b1078ba1e9bc0e4
|
7
|
+
data.tar.gz: 26dd77f60baf03f73791cf3dead57f98a5d8369b8ff60bda0e3c2ebe33767c188580469668b2a3fff08023d4337dfa4f01695053f1d7aacd47462b7704f2b9e4
|
data/opal/i18next/i18next.rb
CHANGED
@@ -2,30 +2,56 @@ require "opal"
|
|
2
2
|
require "native"
|
3
3
|
require "json"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Uses PromiseV2 if present
|
6
|
+
# @see https://opalrb.com/docs/guides/v1.5.1/async PromiseV2
|
7
|
+
module I18next
|
8
8
|
|
9
9
|
Promise = defined?(PromiseV2) ? PromiseV2 : ::Promise
|
10
10
|
|
11
|
-
# {I18next} is a basic wrapper around the JavaScript {https://www.i18next.com i18next
|
11
|
+
# {I18next} is a basic wrapper around the JavaScript I18N module {https://www.i18next.com i18next}.
|
12
12
|
#
|
13
|
-
# It wraps i18next
|
14
|
-
# {https://www.i18next.com/overview/api#
|
13
|
+
# It wraps i18next functions {https://www.i18next.com/overview/api#addresource addResource},
|
14
|
+
# {https://www.i18next.com/overview/api#addresourcebundle addResourceBundle},
|
15
|
+
# {https://www.i18next.com/overview/api#addresources addResources},
|
15
16
|
# {https://www.i18next.com/overview/api#changelanguage changeLanguage},
|
17
|
+
# {https://www.i18next.com/overview/api#cloneinstance cloneInstance},
|
16
18
|
# {https://www.i18next.com/overview/api#dir dir},
|
17
19
|
# {https://www.i18next.com/overview/api#exists exists},
|
18
|
-
# {https://www.i18next.com/overview/api#
|
19
|
-
# {https://www.i18next.com/overview/api#
|
20
|
+
# {https://www.i18next.com/overview/api#getdatabylanguage getDataByLanguage},
|
21
|
+
# {https://www.i18next.com/overview/api#getfixedt getFixedT},
|
22
|
+
# {https://www.i18next.com/overview/api#getresource getResource},
|
23
|
+
# {https://www.i18next.com/overview/api#getresourcebundle getResourceBundle},
|
24
|
+
# {https://www.i18next.com/overview/api#hasresourcebundle hasResourceBundle},
|
20
25
|
# {https://www.i18next.com/overview/api#init init},
|
21
26
|
# {https://www.i18next.com/overview/api#language language},
|
22
27
|
# {https://www.i18next.com/overview/api#languages languages},
|
23
|
-
# {https://www.i18next.com/overview/api#
|
24
|
-
# {https://www.i18next.com/overview/api#
|
25
|
-
# {https://www.i18next.com/overview/api#
|
28
|
+
# {https://www.i18next.com/overview/api#loadlanguages loadLanguages},
|
29
|
+
# {https://www.i18next.com/overview/api#loadnamespaces loadNamespaces},
|
30
|
+
# {https://www.i18next.com/overview/api#events off},
|
31
|
+
# {https://www.i18next.com/overview/api#events on},
|
32
|
+
# {https://www.i18next.com/overview/api#reloadresources reloadResources},
|
33
|
+
# {https://www.i18next.com/overview/api#removeresourcebundle removeResourceBundle},
|
34
|
+
# {https://www.i18next.com/overview/api#resolvedlanguage resolvedLanguage},
|
35
|
+
# {https://www.i18next.com/overview/api#setdefaultnamespace setDefaultNamespace},
|
36
|
+
# {https://www.i18next.com/overview/api#store-events store.on},
|
26
37
|
# {https://www.i18next.com/overview/api#t t}, and
|
27
38
|
# {https://www.i18next.com/overview/api#use use}.
|
28
|
-
#
|
39
|
+
#
|
40
|
+
# Function {https://www.i18next.com/overview/api#createinstance createInstance}
|
41
|
+
# is not supported because each I18next::I18next instance has its own
|
42
|
+
# JavaScript i18next module instance. To create a new instance use
|
43
|
+
# I18next::I18next.new.
|
44
|
+
#
|
45
|
+
# Function {https://www.i18next.com/overview/api#format format} is not supported
|
46
|
+
# because it is a legacy function that has been superseded by
|
47
|
+
# {https://www.i18next.com/translation-function/formatting built-in formatting
|
48
|
+
# functions}.
|
49
|
+
#
|
50
|
+
# It can handle {https://www.i18next.com/overview/api#events i18next events}.
|
51
|
+
# See methods {#on} and {#off}.
|
52
|
+
#
|
53
|
+
# It also provides method {#import_js_module} for loading
|
54
|
+
# {https://www.i18next.com/overview/plugins-and-utils i18next plugins}.
|
29
55
|
class I18next
|
30
56
|
|
31
57
|
# Each I18next instance has its own i18next Javascript module
|
@@ -41,7 +67,7 @@ require "json"
|
|
41
67
|
# @param module_path [String] the path to the module's *.js file, may be a
|
42
68
|
# file path or a URL
|
43
69
|
#
|
44
|
-
# @return [Promise] a promise that resolves to
|
70
|
+
# @return [Promise] a promise that resolves to a JavaScript module that can be passed
|
45
71
|
# to the {#use} method
|
46
72
|
#
|
47
73
|
def import_js_module(module_path)
|
@@ -55,16 +81,19 @@ require "json"
|
|
55
81
|
promise
|
56
82
|
end
|
57
83
|
|
58
|
-
# Loads an {https://www.i18next.com/overview/
|
84
|
+
# Loads an {https://www.i18next.com/overview/plugins-and-utils i18next plugin}
|
59
85
|
#
|
60
|
-
# @param js_module a plugin's JavaScript module that was imported
|
86
|
+
# @param js_module [Object] a plugin's JavaScript module that was imported
|
61
87
|
# by method {#import_js_module}
|
88
|
+
# @return [I18next::I18next] self
|
89
|
+
# @see https://www.i18next.com/overview/api#use The i18next use function
|
62
90
|
def use(js_module)
|
63
91
|
`#{@i18next}.use(js_module.default)`
|
92
|
+
self
|
64
93
|
end
|
65
94
|
|
66
95
|
# Initializes {https://www.i18next.com/overview/api#init i18next}
|
67
|
-
# @param options [Hash] a hash with keys matching the {https://www.i18next.com/overview/configuration-options i18next options}
|
96
|
+
# @param options [Hash] a hash with keys matching the {https://www.i18next.com/overview/configuration-options i18next options}
|
68
97
|
# @return [Promise] a promise that resolves when i18next has been initialized
|
69
98
|
def init(options = {})
|
70
99
|
promise = Promise.new
|
@@ -82,6 +111,7 @@ require "json"
|
|
82
111
|
# @param language [String] the new language
|
83
112
|
# @return [Promise] a promise that resolves when the language's
|
84
113
|
# translations have been loaded
|
114
|
+
# @see https://www.i18next.com/overview/api#changelanguage The i18next changeLanguage function
|
85
115
|
def change_language(language)
|
86
116
|
promise = Promise.new
|
87
117
|
`
|
@@ -93,7 +123,8 @@ require "json"
|
|
93
123
|
promise
|
94
124
|
end
|
95
125
|
|
96
|
-
# @return [String] the current
|
126
|
+
# @return [String] the current language
|
127
|
+
# @see https://www.i18next.com/overview/api#language The i18next language function
|
97
128
|
def language
|
98
129
|
`#{@i18next}.language`
|
99
130
|
end
|
@@ -102,36 +133,53 @@ require "json"
|
|
102
133
|
# @param [String, Array<String>] key one or more keys that reference translations
|
103
134
|
# @param [Hash] options options for formatters, post processors, etc.
|
104
135
|
# @return [String] the translation associated with the first key that resolves
|
136
|
+
# @see https://www.i18next.com/overview/api#t The i18next t function
|
105
137
|
def t(key, options={})
|
106
138
|
`#{@i18next}.t(key, #{options.to_n})`
|
107
139
|
end
|
108
140
|
|
109
141
|
# @return [Boolean] true if the key exists
|
142
|
+
# @see https://www.i18next.com/overview/api#exists The i18next exists function
|
110
143
|
def exists(key)
|
111
144
|
`#{@i18next}.exists(key)`
|
112
145
|
end
|
113
146
|
|
114
|
-
#
|
115
|
-
|
116
|
-
|
147
|
+
# Returns a Proc that acts as a +t+ method that defaults to a language and namespace.
|
148
|
+
# @example When calling the returned Proc, use brackets, not parentheses:
|
149
|
+
# en = get_fixed_t("en")
|
150
|
+
# translation = en["key"]
|
151
|
+
# @param lng [String] language
|
152
|
+
# @param ns [String] namespace
|
153
|
+
# @param key_prefix [String] key prefix
|
154
|
+
# @see https://www.i18next.com/overview/api#getfixedt The i18next getFixedT function
|
155
|
+
def get_fixed_t(lng = nil, ns = nil, key_prefix = nil)
|
156
|
+
if key_prefix && ns && lng
|
157
|
+
`#{@i18next}.getFixedT(lng, ns, key_prefix)`
|
158
|
+
elsif ns && lng
|
159
|
+
`#{@i18next}.getFixedT(lng, ns)`
|
160
|
+
elsif lng
|
161
|
+
`#{@i18next}.getFixedT(lng)`
|
162
|
+
else
|
163
|
+
`#{@i18next}.getFixedT()`
|
164
|
+
end
|
117
165
|
end
|
118
166
|
|
119
|
-
# @see https://www.i18next.com/overview/api#languages The i18next languages
|
167
|
+
# @see https://www.i18next.com/overview/api#languages The i18next languages function
|
120
168
|
# @return language codes that will be used to look up the translation value
|
121
169
|
def languages
|
122
170
|
`#{@i18next}.languages`
|
123
171
|
end
|
124
172
|
|
125
|
-
# @see https://www.i18next.com/overview/api#
|
173
|
+
# @see https://www.i18next.com/overview/api#resolvedlanguage The i18next resolvedLanguage function
|
126
174
|
# @return the current resolved language
|
127
175
|
def resolved_language
|
128
176
|
`#{@i18next}.resolvedLanguage`
|
129
177
|
end
|
130
178
|
|
131
179
|
# Loads additional namespaces not defined in init options
|
132
|
-
# @param [String, Array<String>]
|
180
|
+
# @param ns [String, Array<String>] one or more namespaces
|
133
181
|
# @return [Promise] a promise that resolves when the namespaces have been loaded
|
134
|
-
# @see https://www.i18next.com/overview/api#
|
182
|
+
# @see https://www.i18next.com/overview/api#loadnamespaces The i18next loadNamespaces function
|
135
183
|
def load_namespaces(ns)
|
136
184
|
promise = Promise.new
|
137
185
|
`
|
@@ -144,19 +192,45 @@ require "json"
|
|
144
192
|
promise
|
145
193
|
end
|
146
194
|
|
147
|
-
#
|
148
|
-
|
149
|
-
|
195
|
+
# Loads additional languages not defined in init options (preload).
|
196
|
+
# @param lngs [String, Array<String>] one or more languages
|
197
|
+
# @return [Promise] a promise that resolves when the languages have been loaded
|
198
|
+
# @see https://www.i18next.com/overview/api#loadlanguages The i18next loadLanguages function
|
199
|
+
def load_languages(lngs)
|
200
|
+
promise = Promise.new
|
201
|
+
`
|
202
|
+
#{@i18next}.loadLanguages(lngs)
|
203
|
+
.then(
|
204
|
+
() => {
|
205
|
+
promise.$resolve()
|
206
|
+
});
|
207
|
+
`
|
208
|
+
promise
|
150
209
|
end
|
151
210
|
|
152
|
-
#
|
153
|
-
|
154
|
-
|
211
|
+
# Reloads resources on given state.
|
212
|
+
#
|
213
|
+
# Optionally you can pass an array of languages and/or namespaces as params if
|
214
|
+
# you don't want to reload all.
|
215
|
+
# @param lng [String, Array<String>] one or more languages
|
216
|
+
# @param ns [String, Array<String>] one or more namespaces
|
217
|
+
# @return [Promise] a promise that resolves when the resources have been loaded
|
218
|
+
# @see https://www.i18next.com/overview/api#reloadresources The i18next reloadResources function
|
219
|
+
def reload_resources(lng = nil, ns = nil)
|
220
|
+
if !lng && !ns
|
221
|
+
reload_all_resources
|
222
|
+
elsif lng && !ns
|
223
|
+
reload_lng_resources(lng)
|
224
|
+
elsif !lng && ns
|
225
|
+
reload_ns_resources(ns)
|
226
|
+
else
|
227
|
+
reload_lng_ns_resources(lng, ns)
|
228
|
+
end
|
155
229
|
end
|
156
230
|
|
157
231
|
# Changes the default namespace.
|
158
232
|
# @param ns [String] new default namespace
|
159
|
-
# @see https://www.i18next.com/overview/api#
|
233
|
+
# @see https://www.i18next.com/overview/api#setdefaultnamespace The i18next setDefaultNamespace function
|
160
234
|
def set_default_namespace(ns)
|
161
235
|
`#{@i18next}.setDefaultNamespace(ns)`
|
162
236
|
end
|
@@ -164,81 +238,232 @@ require "json"
|
|
164
238
|
# Get a language's reading direction
|
165
239
|
# @param lng [String] the language; if omitted, the current language is used
|
166
240
|
# @return "ltr" or "rtl"
|
167
|
-
# @see https://www.i18next.com/overview/api#dir The i18next dir
|
241
|
+
# @see https://www.i18next.com/overview/api#dir The i18next dir function
|
168
242
|
def dir(lng)
|
169
243
|
`#{@i18next}.dir(lng)`
|
170
244
|
end
|
171
245
|
|
172
|
-
# @private
|
173
|
-
def format(data, format, lng)
|
174
|
-
raise 'Not implemented'
|
175
|
-
end
|
176
|
-
|
177
|
-
# @private
|
178
|
-
def create_instance(options)
|
179
|
-
raise 'Not implemented'
|
180
|
-
end
|
181
|
-
|
182
|
-
# @private
|
183
|
-
def clone_instance(options)
|
184
|
-
raise 'Not implemented'
|
185
|
-
end
|
186
|
-
|
187
|
-
# @private
|
188
|
-
def off
|
189
|
-
raise 'Not implemented'
|
190
|
-
end
|
191
|
-
|
192
|
-
# @private
|
193
|
-
def on
|
194
|
-
raise 'Not implemented'
|
195
|
-
end
|
196
|
-
|
197
246
|
# Gets one value by given key.
|
198
|
-
# @
|
247
|
+
# @param lng [String] language
|
248
|
+
# @param ns [String] namespace
|
249
|
+
# @param key_prefix [String] key prefix
|
250
|
+
# @param options [Hash] key separator and ignore JSON structure
|
251
|
+
# @see https://www.i18next.com/overview/api#getresource The i18next getResource function
|
199
252
|
def get_resource(lng, ns, key, options = {})
|
200
253
|
`#{@i18next}.getResource(lng, ns, key, options)`
|
201
254
|
end
|
202
255
|
|
203
256
|
# Adds one key/value.
|
204
|
-
# @see https://www.i18next.com/overview/api#
|
257
|
+
# @see https://www.i18next.com/overview/api#addresource The i18next addResource function
|
205
258
|
def add_resource(lng, ns, key, value, options = {})
|
206
259
|
`#{@i18next}.addResource(lng, ns, key, value, options)`
|
207
260
|
end
|
208
261
|
|
209
262
|
# Adds multiple key/values.
|
210
263
|
# @param resources [Hash] key/value pairs
|
211
|
-
# @see https://www.i18next.com/overview/api#
|
264
|
+
# @see https://www.i18next.com/overview/api#addresources The i18next addResources function
|
212
265
|
def add_resources(lng, ns, resources)
|
213
266
|
`#{@i18next}.addResources(lng, ns, #{resources.to_n})`
|
214
267
|
end
|
215
268
|
|
216
|
-
#
|
217
|
-
|
218
|
-
|
269
|
+
# Adds a complete bundle
|
270
|
+
# @param lng [String] bundle language
|
271
|
+
# @param ns [String] bundle namespace
|
272
|
+
# @param deep [Boolean] if true will extend existing translations in the bundle
|
273
|
+
# @param overwrite [Boolean] if true it will overwrite existing translations in the bundle
|
274
|
+
# @see https://www.i18next.com/overview/api#addresourcebundle The i18next addResourceBundle function
|
275
|
+
def add_resource_bundle(lng, ns, resources, deep = false, overwrite = false)
|
276
|
+
`#{@i18next}.addResources(lng, ns, #{resources.to_n}, deep, overwrite)`
|
219
277
|
end
|
220
278
|
|
221
|
-
#
|
279
|
+
# Checks if a resource bundle exists
|
280
|
+
# @param lng [String] language
|
281
|
+
# @param ns [String] namespace
|
282
|
+
# @return [Boolean] true if the bundle exists
|
222
283
|
def has_resource_bundle(lng, ns)
|
223
|
-
|
284
|
+
`#{@i18next}.hasResourceBundle(lng, ns)`
|
224
285
|
end
|
225
286
|
|
226
|
-
#
|
287
|
+
# Returns resource data for a language.
|
288
|
+
# @param lng [String] language
|
289
|
+
# @return [Hash] resource data
|
290
|
+
# @see https://www.i18next.com/overview/api#getbatabylanguage The i18next getDataByLanguage function
|
227
291
|
def get_data_by_language(lng)
|
228
|
-
|
292
|
+
js_obj_to_ruby_hash(`#{@i18next}.getDataByLanguage(lng)`)
|
229
293
|
end
|
230
294
|
|
231
295
|
# Gets a resource bundle.
|
296
|
+
# @param lng [String] language
|
297
|
+
# @param ns [String] namespace
|
232
298
|
# @return [Hash] key/value pairs
|
233
|
-
# @see https://www.i18next.com/overview/api#
|
299
|
+
# @see https://www.i18next.com/overview/api#getresourcebundle The i18next getResourceBundle function
|
234
300
|
def get_resource_bundle(lng, ns)
|
235
|
-
|
301
|
+
js_obj_to_ruby_hash(`#{@i18next}.getResourceBundle(lng, ns)`)
|
236
302
|
end
|
237
303
|
|
238
|
-
#
|
304
|
+
# Removes a resource bundle exists
|
305
|
+
# @param lng [String] language
|
306
|
+
# @param ns [String] namespace
|
307
|
+
# @see https://www.i18next.com/overview/api#removeresourcebundle The i18next removeResourceBundle function
|
239
308
|
def remove_resource_bundle(lng, ns)
|
240
|
-
|
309
|
+
`#{@i18next}.removeResourceBundle(lng, ns)`
|
310
|
+
end
|
311
|
+
|
312
|
+
# Create a listener for an i18next event.
|
313
|
+
# @param event [String] event name
|
314
|
+
# @param &listener [block] an event listener that is passed event-dependent arguments
|
315
|
+
# @return [Proc] a listener, which can be used to unsubscribe it via method +off(event, listener)+
|
316
|
+
# @see https://www.i18next.com/overview/api#events The i18next events
|
317
|
+
# @see #off
|
318
|
+
def on(event, &listener)
|
319
|
+
# Some events require special listeners because those events return JavaScript objects
|
320
|
+
# to the listeners, and those object must be converted to Ruby Hashes.
|
321
|
+
case event
|
322
|
+
when "initialized"
|
323
|
+
_onInitialized(listener)
|
324
|
+
when "loaded"
|
325
|
+
_onLoaded(listener)
|
326
|
+
else
|
327
|
+
`#{@i18next}.on(event, listener)`
|
328
|
+
end
|
329
|
+
listener
|
330
|
+
end
|
331
|
+
|
332
|
+
# Create a listener for an i18next store event.
|
333
|
+
#
|
334
|
+
# Only available after the +init+ call.
|
335
|
+
#
|
336
|
+
# @param event [String] event name ("added" or "removed")
|
337
|
+
# @param &listener [block] an event listener that is passed language and namespace arguments
|
338
|
+
# @return [Proc] the listener, which can be unsubscribed via method +off(event, listener)+
|
339
|
+
# @see https://www.i18next.com/overview/api#store-events The i18next store events
|
340
|
+
def store_on(event, &listener)
|
341
|
+
`#{@i18next}.store.on(event, listener)`
|
342
|
+
listener
|
343
|
+
end
|
344
|
+
|
345
|
+
# Unsubscribes an event's listener(s).
|
346
|
+
#
|
347
|
+
# Listeners are created by method {#on}.
|
348
|
+
# @param event [String] event name
|
349
|
+
# @param listener [Proc] the listener to unsubscribe; if absent, unsubscribe all listeners
|
350
|
+
# @see https://www.i18next.com/overview/api#events The i18next events
|
351
|
+
# @see #on
|
352
|
+
def off(event, listener = nil)
|
353
|
+
if listener
|
354
|
+
`#{@i18next}.off(event, listener)`
|
355
|
+
else
|
356
|
+
`#{@i18next}.off(event)`
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
# Creates a clone of the current instance.
|
361
|
+
#
|
362
|
+
# Shares store, plugins and initial configuration. Can be used to create an
|
363
|
+
# instance sharing storage but being independent on set language or default namespaces.
|
364
|
+
# @param options [Hash] a hash with keys matching the {https://www.i18next.com/overview/configuration-options i18next options}
|
365
|
+
# @return [I18next::I18next] a new instance
|
366
|
+
# @see https://www.i18next.com/overview/api#cloneinstance The i18next cloneInstance function
|
367
|
+
def clone_instance(options = {})
|
368
|
+
I18nextClone.new(@i18next, options)
|
369
|
+
end
|
370
|
+
|
371
|
+
private
|
372
|
+
|
373
|
+
# @private
|
374
|
+
class I18nextClone < I18next
|
375
|
+
def initialize(js_i18next, options)
|
376
|
+
@i18next = `#{js_i18next}.cloneInstance(#{options.to_n})`
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
# @private
|
381
|
+
def reload_all_resources
|
382
|
+
promise = Promise.new
|
383
|
+
`
|
384
|
+
#{@i18next}.reloadResources()
|
385
|
+
.then(
|
386
|
+
() => {
|
387
|
+
promise.$resolve()
|
388
|
+
});
|
389
|
+
`
|
390
|
+
promise
|
391
|
+
end
|
392
|
+
|
393
|
+
def reload_lng_resources(lng)
|
394
|
+
promise = Promise.new
|
395
|
+
`
|
396
|
+
#{@i18next}.reloadResources(lng)
|
397
|
+
.then(
|
398
|
+
() => {
|
399
|
+
promise.$resolve()
|
400
|
+
});
|
401
|
+
`
|
402
|
+
promise
|
403
|
+
end
|
404
|
+
|
405
|
+
def reload_ns_resources(ns)
|
406
|
+
promise = Promise.new
|
407
|
+
`
|
408
|
+
#{@i18next}.reloadResources(null, ns)
|
409
|
+
.then(
|
410
|
+
() => {
|
411
|
+
promise.$resolve()
|
412
|
+
});
|
413
|
+
`
|
414
|
+
promise
|
241
415
|
end
|
242
416
|
|
417
|
+
def reload_lng_ns_resources(lng, ns)
|
418
|
+
promise = Promise.new
|
419
|
+
`
|
420
|
+
#{@i18next}.reloadResources(lng, ns)
|
421
|
+
.then(
|
422
|
+
() => {
|
423
|
+
promise.$resolve()
|
424
|
+
});
|
425
|
+
`
|
426
|
+
promise
|
427
|
+
end
|
428
|
+
|
429
|
+
# @private
|
430
|
+
# Create a listener for the i18next initialized event.
|
431
|
+
# @param &listener [Proc] an event listener block that is passed initialized options Hash
|
432
|
+
# @see https://www.i18next.com/overview/api#oninitialized The i18next initialized event
|
433
|
+
def _onInitialized(listener)
|
434
|
+
`
|
435
|
+
#{@i18next}.on("initialized", (options) => {
|
436
|
+
// Convert the JavaScript options object to a string and
|
437
|
+
// then convert that string to a Ruby hash that is passed
|
438
|
+
// to the listener.
|
439
|
+
listener.$call(Opal.JSON.$parse(JSON.stringify(options)))
|
440
|
+
})
|
441
|
+
`
|
442
|
+
end
|
443
|
+
|
444
|
+
# @private
|
445
|
+
# Create a listener for the i18next loaded event.
|
446
|
+
# @param listener [Proc] an event listener block that is passed loaded Hash
|
447
|
+
# @see https://www.i18next.com/overview/api#onloaded The i18next onLoaded event
|
448
|
+
def _onLoaded(listener)
|
449
|
+
`
|
450
|
+
#{@i18next}.on("loaded", (loaded) => {
|
451
|
+
// Convert the JavaScript load object to a string and
|
452
|
+
// then convert that string to a Ruby hash that is passed
|
453
|
+
// to the listener.
|
454
|
+
listener.$call(Opal.JSON.$parse(JSON.stringify(loaded)))
|
455
|
+
})
|
456
|
+
`
|
457
|
+
end
|
458
|
+
|
459
|
+
# @private
|
460
|
+
# Convert a JavaScript obj to a Ruby Hash.
|
461
|
+
# @param js_obj JavaScript object
|
462
|
+
# @return [Hash] Ruby Hash
|
463
|
+
def js_obj_to_ruby_hash(js_obj)
|
464
|
+
# Convert the JavaScript object to a string and then convert that string
|
465
|
+
# to a Ruby hash.
|
466
|
+
JSON.parse(`JSON.stringify(js_obj)`)
|
467
|
+
end
|
243
468
|
end
|
244
469
|
end
|
data/opal/i18next/version.rb
CHANGED
data/opal-i18next.gemspec
CHANGED
@@ -5,11 +5,12 @@ Gem::Specification.new do |spec|
|
|
5
5
|
spec.version = I18next::VERSION
|
6
6
|
spec.summary = "An Opal wrapper for the JavaScript i18next module."
|
7
7
|
spec.description = <<~DESC
|
8
|
-
A basic Opal wrapper for the JavaScript
|
9
|
-
addResource, addResources, changeLanguage,
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
A basic Opal wrapper for the JavaScript I18N module i18next that supports functions
|
9
|
+
addResource, addResourceBundle, addResources, changeLanguage, cloneInstance,
|
10
|
+
dir, exists, getDataByLanguage, getFixedT, getResource, getResourceBundle,
|
11
|
+
hasResourceBundle, init, language, languages, loadLanguages, loadNamespaces,
|
12
|
+
off, on, reloadResources, removeResourceBundle, resolvedLanguage, store.on,
|
13
|
+
t, and use. It also provides method import_js_module for loading i18next plugins.
|
13
14
|
DESC
|
14
15
|
spec.authors = ["Larry North"]
|
15
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-i18next
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry North
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -25,11 +25,12 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.5.0
|
27
27
|
description: |
|
28
|
-
A basic Opal wrapper for the JavaScript
|
29
|
-
addResource, addResources, changeLanguage,
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
A basic Opal wrapper for the JavaScript I18N module i18next that supports functions
|
29
|
+
addResource, addResourceBundle, addResources, changeLanguage, cloneInstance,
|
30
|
+
dir, exists, getDataByLanguage, getFixedT, getResource, getResourceBundle,
|
31
|
+
hasResourceBundle, init, language, languages, loadLanguages, loadNamespaces,
|
32
|
+
off, on, reloadResources, removeResourceBundle, resolvedLanguage, store.on,
|
33
|
+
t, and use. It also provides method import_js_module for loading i18next plugins.
|
33
34
|
email:
|
34
35
|
- lnorth@swnorth.com
|
35
36
|
executables: []
|