isomorfeus-i18n 2.5.4 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/isomorfeus/i18n/config.rb +4 -4
- data/lib/isomorfeus/i18n/enhancer.rb +55 -0
- data/lib/isomorfeus/i18n/init.rb +19 -26
- data/lib/isomorfeus/i18n/reducer.rb +34 -25
- data/lib/isomorfeus/i18n/version.rb +1 -1
- data/lib/isomorfeus-i18n.rb +15 -16
- data/lib/lucid_i18n_mixin.rb +169 -0
- metadata +24 -38
- data/lib/isomorfeus/i18n/handler/locale_handler.rb +0 -86
- data/lib/lucid_i18n/mixin.rb +0 -224
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3893f1f4b352b6e2e6cb2ff85eae4c8ea8a47ae277c169124b2ed2142358693
|
4
|
+
data.tar.gz: 782bf79faf33d6c4514f3e7d2cc3128a129d68ccbbb6c3849f783196079e37cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dccc5bb3e1a44f8c7a5f7a68953b511390a9064d11ace5f7f23f840b25837034c084668384213843be64ec09491941265c38d097c6e7ab8ba36e14c29d91d2f6
|
7
|
+
data.tar.gz: 7db066fed00ba4c942e417102015a8a985e6392a9813e87012c2aed9d9b4f0471ae37f331567f58309ed92551b731f0845b097d178d4936d0065fc71a256df58
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Using fast_gettext internally.
|
|
15
15
|
|
16
16
|
In any class:
|
17
17
|
```
|
18
|
-
include
|
18
|
+
include LucidI18nMixin
|
19
19
|
```
|
20
20
|
after which the _ gettext methods are available for translation.
|
21
21
|
See the [fast_gettext documentation](https://github.com/grosser/fast_gettext) or the
|
@@ -27,7 +27,7 @@ Also available is the `current_locale` helper, which provides the current locale
|
|
27
27
|
|
28
28
|
In any class:
|
29
29
|
```
|
30
|
-
include
|
30
|
+
include LucidI18nMixin
|
31
31
|
```
|
32
32
|
after which the l method is available, which currently can localize Times, Dates and numbers.
|
33
33
|
See the [R18n core documentation](https://github.com/r18n/r18n-core)
|
@@ -5,12 +5,12 @@ module Isomorfeus
|
|
5
5
|
|
6
6
|
if RUBY_ENGINE == 'opal'
|
7
7
|
def available_locales
|
8
|
-
result =
|
8
|
+
result = Isomorfeus.store.dig(:i18n_state, :available_locales)
|
9
9
|
result ? result : ['en']
|
10
10
|
end
|
11
11
|
|
12
12
|
def i18n_domain
|
13
|
-
result =
|
13
|
+
result = Isomorfeus.store.dig(:i18n_state, :domain)
|
14
14
|
result ? result : 'app'
|
15
15
|
end
|
16
16
|
|
@@ -20,7 +20,7 @@ module Isomorfeus
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def default_locale
|
23
|
-
result =
|
23
|
+
result = Isomorfeus.store.dig(:i18n_state, :locale)
|
24
24
|
result ? result : available_locales.first
|
25
25
|
end
|
26
26
|
|
@@ -57,7 +57,7 @@ module Isomorfeus
|
|
57
57
|
|
58
58
|
def current_locale=(loc)
|
59
59
|
FastGettext.locale = loc
|
60
|
-
R18n.thread_set(loc)
|
60
|
+
R18n.thread_set(R18n::I18n.new(loc, R18n.default_places))
|
61
61
|
Thread.current[:isomorfeus_locale] = loc
|
62
62
|
end
|
63
63
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
module I18n
|
3
|
+
if RUBY_ENGINE != 'opal'
|
4
|
+
class InternalTranslationProxy
|
5
|
+
extend FastGettext::Translation
|
6
|
+
extend FastGettext::TranslationMultidomain
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Enhancer
|
11
|
+
if RUBY_ENGINE == 'opal'
|
12
|
+
I18N_ACTION_TYPES = %w[I18N_LOAD I18N_INIT]
|
13
|
+
CLIENT_I18N_ENHANCER = proc do |action, next_enh|
|
14
|
+
Isomorfeus.store.promise_action(action) if I18N_ACTION_TYPES.include?(action[:type])
|
15
|
+
next_enh.call(action)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.add_enhancer_to_store
|
19
|
+
::Redux::Store.add_middleware(CLIENT_I18N_ENHANCER)
|
20
|
+
end
|
21
|
+
else # RUBY_ENGINE
|
22
|
+
LOCALE_METHODS = %w[_ n_ np_ ns_ p_ s_ N_ Nn_ d_ dn_ dnp_ dns_ dp_ ds_ D_ Dn_ Dnp_ Dns_ Dp_ Ds_]
|
23
|
+
|
24
|
+
SERVER_I18N_ENHANCER = proc do |action, next_enh|
|
25
|
+
if action[:type] == 'I18N_LOAD'
|
26
|
+
Isomorfeus::I18n::Init.init
|
27
|
+
domain = action[:domain]
|
28
|
+
locale = action[:locale]
|
29
|
+
method = action[:method]
|
30
|
+
args = action[:args]
|
31
|
+
if LOCALE_METHODS.include?(method)
|
32
|
+
result = InternalTranslationProxy.send(method, *args)
|
33
|
+
action = { type: 'I18N_MERGE', data: { domain => { locale => { method => { Oj.dump(args, mode: :strict) => result }}}}}
|
34
|
+
end
|
35
|
+
elsif action[:type] == 'I18N_INIT'
|
36
|
+
locale = action[:locale]
|
37
|
+
available_locales = FastGettext.available_locales
|
38
|
+
domain = FastGettext.text_domain
|
39
|
+
ne_locale = if Isomorfeus.available_locales.include?(locale)
|
40
|
+
Isomorfeus.current_locale = locale
|
41
|
+
else
|
42
|
+
Isomorfeus.current_locale = Isomorfeus.default_locale
|
43
|
+
end
|
44
|
+
action = { type: 'I18N_MERGE', data: { available_locales: available_locales, domain: domain, locale: ne_locale }}
|
45
|
+
end
|
46
|
+
next_enh.call(action)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.add_enhancer_to_store
|
50
|
+
::Redux::Store.add_middleware(SERVER_I18N_ENHANCER)
|
51
|
+
end
|
52
|
+
end # RUBY_ENGINE
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/isomorfeus/i18n/init.rb
CHANGED
@@ -1,41 +1,29 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module I18n
|
3
|
+
class StoreInit
|
4
|
+
def self.init
|
5
|
+
root_element = `document.querySelector('div[data-iso-root]')`
|
6
|
+
if root_element
|
7
|
+
Isomorfeus.current_locale = root_element.JS.getAttribute('data-iso-nloc')
|
8
|
+
else
|
9
|
+
Isomorfeus.current_locale = Isomorfeus.default_locale
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
class Init
|
4
15
|
class << self
|
5
16
|
if RUBY_ENGINE == 'opal'
|
6
|
-
attr_accessor :init_promise
|
7
|
-
|
8
17
|
def init
|
9
18
|
return if @initializing || initialized?
|
10
19
|
@initializing = true
|
11
20
|
@initialized = false
|
12
|
-
|
13
|
-
|
14
|
-
if root_element
|
15
|
-
Isomorfeus.current_locale = root_element.JS.getAttribute('data-iso-nloc')
|
16
|
-
else
|
17
|
-
Isomorfeus.current_locale = Isomorfeus.default_locale
|
18
|
-
end
|
19
|
-
end
|
20
|
-
self.init_promise = init_from_server
|
21
|
+
init_from_server
|
22
|
+
promise { Isomorfeus.store.dig(:i18n_state, :locale) }
|
21
23
|
end
|
22
24
|
|
23
25
|
def init_from_server
|
24
|
-
Isomorfeus
|
25
|
-
agent.process do
|
26
|
-
@initializing = false
|
27
|
-
Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
|
28
|
-
@initialized = true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def reload_from_server
|
34
|
-
Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.current_locale).then do |agent|
|
35
|
-
agent.process do
|
36
|
-
Isomorfeus.store.dispatch(type: 'I18N_STATE', set_state: agent.response[:data])
|
37
|
-
end
|
38
|
-
end
|
26
|
+
Isomorfeus.store.deferred_dispatch(type: 'I18N_INIT', locale: Isomorfeus.current_locale)
|
39
27
|
end
|
40
28
|
|
41
29
|
def initialized?
|
@@ -43,6 +31,11 @@ module Isomorfeus
|
|
43
31
|
end
|
44
32
|
else
|
45
33
|
def init
|
34
|
+
return if Thread.current[:isomorfeus_i18n_initialized] == true
|
35
|
+
unless Dir.exist?(Isomorfeus.locale_path)
|
36
|
+
STDERR.puts "locale directory '#{Isomorfeus.locale_path}' not found, please create it if using I18n"
|
37
|
+
return
|
38
|
+
end
|
46
39
|
FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
|
47
40
|
FastGettext.available_locales = Isomorfeus.available_locales
|
48
41
|
FastGettext.text_domain = Isomorfeus.i18n_domain
|
@@ -1,38 +1,47 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module I18n
|
3
3
|
module Reducer
|
4
|
-
|
5
|
-
|
4
|
+
if RUBY_ENGINE == 'opal'
|
5
|
+
CLIENT_REDUCER = proc do |prev_state, action|
|
6
6
|
action_type = action[:type]
|
7
|
-
if action_type.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
when 'I18N_LOAD'
|
16
|
-
new_state = {}.merge!(prev_state)
|
17
|
-
if action.key?(:collected)
|
18
|
-
action[:collected].each do |act|
|
19
|
-
new_state.deep_merge!(act[:data])
|
20
|
-
end
|
21
|
-
else
|
22
|
-
new_state.deep_merge!(action[:data])
|
23
|
-
end
|
24
|
-
new_state
|
7
|
+
if action_type == 'I18N_STATE' && action.key?(:set_state)
|
8
|
+
action[:set_state]
|
9
|
+
elsif action_type == 'REDUX_MERGE'
|
10
|
+
red_state = action.dig(:state, :i18n_state)
|
11
|
+
if red_state
|
12
|
+
new_state = prev_state ? prev_state.deep_dup : {}
|
13
|
+
new_state.deep_merge!(red_state)
|
25
14
|
else
|
26
|
-
prev_state
|
15
|
+
prev_state || {}
|
27
16
|
end
|
28
17
|
else
|
29
|
-
prev_state
|
18
|
+
prev_state || {}
|
30
19
|
end
|
31
20
|
end
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
def self.add_reducer_to_store
|
23
|
+
::Redux::Store.preloaded_state_merge!(i18n_state: {})
|
24
|
+
::Redux::Store.add_reducers(i18n_state: CLIENT_REDUCER)
|
25
|
+
end
|
26
|
+
else # RUBY_ENGINE
|
27
|
+
SERVER_REDUCER = proc do |prev_state, action|
|
28
|
+
action_type = action[:type]
|
29
|
+
if action_type == 'I18N_STATE' && action.key?(:set_state)
|
30
|
+
action[:set_state]
|
31
|
+
elsif action_type == 'I18N_MERGE'
|
32
|
+
new_state = prev_state ? prev_state.deep_dup : {}
|
33
|
+
new_state.deep_merge!(action[:data])
|
34
|
+
new_state
|
35
|
+
else
|
36
|
+
prev_state || {}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.add_reducer_to_store
|
41
|
+
::Redux::Store.preloaded_state_merge!(i18n_state: {})
|
42
|
+
::Redux::Store.add_reducers(i18n_state: SERVER_REDUCER)
|
43
|
+
end
|
44
|
+
end # RUBY_ENGINE
|
36
45
|
end
|
37
46
|
end
|
38
47
|
end
|
data/lib/isomorfeus-i18n.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'time' # which requires 'date'
|
2
|
-
# require 'datetime' # for opal 1.5
|
3
2
|
require 'isomorfeus-transport'
|
3
|
+
require 'isomorfeus-redux'
|
4
|
+
require 'isomorfeus/i18n/config'
|
5
|
+
require 'isomorfeus/i18n/reducer'
|
6
|
+
Isomorfeus::I18n::Reducer.add_reducer_to_store
|
7
|
+
|
8
|
+
require 'lucid_i18n_mixin'
|
9
|
+
require 'isomorfeus/i18n/init'
|
4
10
|
|
5
11
|
if RUBY_ENGINE == 'opal'
|
6
|
-
|
7
|
-
|
8
|
-
Isomorfeus::I18n::Reducer.add_reducer_to_store
|
9
|
-
require 'lucid_i18n/mixin'
|
10
|
-
require 'isomorfeus/i18n/init'
|
11
|
-
if Isomorfeus.on_browser?
|
12
|
-
Isomorfeus.add_client_init_after_store_class_name('Isomorfeus::I18n::Init')
|
13
|
-
else
|
14
|
-
Isomorfeus.add_transport_init_class_name('Isomorfeus::I18n::Init')
|
15
|
-
end
|
12
|
+
Isomorfeus.add_client_init_after_store_class_name('Isomorfeus::I18n::StoreInit')
|
13
|
+
Isomorfeus.add_transport_init_class_name('Isomorfeus::I18n::Init')
|
16
14
|
else
|
17
15
|
require 'active_support'
|
18
16
|
require 'oj'
|
@@ -20,13 +18,14 @@ else
|
|
20
18
|
require 'fast_gettext'
|
21
19
|
require 'isomorfeus/i18n/fast_gettext/cache'
|
22
20
|
require 'isomorfeus/i18n/fast_gettext/translation_repository/base'
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'isomorfeus/i18n/enhancer'
|
24
|
+
Isomorfeus::I18n::Enhancer.add_enhancer_to_store
|
25
|
+
|
26
|
+
if RUBY_ENGINE != 'opal'
|
23
27
|
require 'http_accept_language/parser'
|
24
28
|
require 'http_accept_language/middleware'
|
25
|
-
require 'isomorfeus-data'
|
26
|
-
require 'isomorfeus/i18n/config'
|
27
|
-
require 'isomorfeus/i18n/init'
|
28
|
-
require 'lucid_i18n/mixin'
|
29
|
-
require 'isomorfeus/i18n/handler/locale_handler'
|
30
29
|
require 'isomorfeus/i18n/middleware'
|
31
30
|
|
32
31
|
Isomorfeus.add_middleware(HttpAcceptLanguage::Middleware)
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module LucidI18nMixin
|
2
|
+
CONTEXT_SEPARATOR = "\004"
|
3
|
+
NAMESPACE_SEPARATOR = '|'
|
4
|
+
NIL_BLOCK = -> { nil }
|
5
|
+
TRANSLATION_METHODS = [:_, :n_, :np_, :ns_, :p_, :s_]
|
6
|
+
|
7
|
+
def i18n_domain
|
8
|
+
Isomorfeus.i18n_domain
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_locale
|
12
|
+
Isomorfeus.current_locale
|
13
|
+
end
|
14
|
+
|
15
|
+
def _(*keys)
|
16
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, '_', JSON.dump(keys))
|
17
|
+
return result if result
|
18
|
+
_send_i18n_method('_', keys)
|
19
|
+
end
|
20
|
+
|
21
|
+
def n_(*keys, count)
|
22
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, 'n_', JSON.dump(keys.push(count)))
|
23
|
+
return result if result
|
24
|
+
_send_i18n_method('n_', keys + [count])
|
25
|
+
end
|
26
|
+
|
27
|
+
def np_(context, plural_one, *args, separator: nil)
|
28
|
+
nargs = ["#{context}#{separator || CONTEXT_SEPARATOR}#{plural_one}"] + args
|
29
|
+
translation = n_(*nargs, &NIL_BLOCK)
|
30
|
+
return translation if translation
|
31
|
+
n_(plural_one, *args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ns_(*args)
|
35
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, 'ns_', JSON.dump(args))
|
36
|
+
return result if result
|
37
|
+
_send_i18n_method('ns_', args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def p_(namespace, key, separator = nil)
|
41
|
+
args = separator ? [namespace, key, separator] : [namespace, key]
|
42
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, 'p_', JSON.dump(args))
|
43
|
+
return result if result
|
44
|
+
_send_i18n_method('p_', args)
|
45
|
+
end
|
46
|
+
|
47
|
+
def s_(key, separator = nil)
|
48
|
+
args = separator ? [key, separator] : [key]
|
49
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, 's_', JSON.dump(args))
|
50
|
+
return result if result
|
51
|
+
_send_i18n_method('s_', args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def N_(translate)
|
55
|
+
translate
|
56
|
+
end
|
57
|
+
|
58
|
+
def Nn_(*keys)
|
59
|
+
keys
|
60
|
+
end
|
61
|
+
|
62
|
+
TRANSLATION_METHODS.each do |method|
|
63
|
+
define_method("d#{method}") do |domain, *args, &block|
|
64
|
+
old_domain = i18n_domain
|
65
|
+
begin
|
66
|
+
Isomorfeus.i18n_domain = domain
|
67
|
+
result = send(method, *args, &block)
|
68
|
+
ensure
|
69
|
+
Isomorfeus.i18n_domain = old_domain
|
70
|
+
end
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
define_method("D#{method}") do |*args|
|
75
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, "D#{method}", JSON.dump(args))
|
76
|
+
return result if result
|
77
|
+
_send_i18n_method("D#{method}", args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if RUBY_ENGINE == 'opal'
|
82
|
+
def _send_i18n_method(method, args)
|
83
|
+
Isomorfeus.something_loading!
|
84
|
+
Isomorfeus.store.deferred_dispatch(type: 'I18N_LOAD', domain: i18n_domain, locale: current_locale, method: method, args: args)
|
85
|
+
''
|
86
|
+
end
|
87
|
+
|
88
|
+
def l(object, format = :standard, options = {})
|
89
|
+
c_name = object.class.to_s
|
90
|
+
options = {} unless options
|
91
|
+
locale = options.delete(:locale) { current_locale }
|
92
|
+
options = options.transform_keys { |k| k.camelize(:lower) }
|
93
|
+
if object.is_a?(Numeric)
|
94
|
+
options[:minimumFractionDigits] = 4 unless object.is_a?(Integer)
|
95
|
+
# options for number formatting:
|
96
|
+
# locale: locale string like 'de'
|
97
|
+
# currency: any currency code (like "EUR", "USD", "INR", etc.)
|
98
|
+
# currency_display or currencyDisplay: "symbol"(default) "code" "name"
|
99
|
+
# locale_matcher or localeMatcher: "best-fit"(default) "lookup"
|
100
|
+
# maximum_fraction_digits or maximumFractionDigits: A number from 0 to 20 (default is 3)
|
101
|
+
# maximum_significant_digits or maximumSignificantDigits: A number from 1 to 21 (default is 21)
|
102
|
+
# minimum_fraction_digits or minimumFractionDigits: A number from 0 to 20 (default is 3)
|
103
|
+
# minimum_integer_digits or minimumIntegerDigits: A number from 1 to 21 (default is 1)
|
104
|
+
# minimum_significant_digits or minimumSignificantDigits: A number from 1 to 21 (default is 21)
|
105
|
+
# style: "decimal"(default) "currency" "percent"
|
106
|
+
# use_grouping or useGrouping: true(default) false
|
107
|
+
`(object).toLocaleString(locale, #{options.to_n})`
|
108
|
+
elsif c_name == 'Date' || c_name == 'DateTime'
|
109
|
+
# options for date/time formating:
|
110
|
+
# format: "standard" "full"
|
111
|
+
# locale: locale string like 'de'
|
112
|
+
# time_zone or timeZone: timezone string like 'CET'
|
113
|
+
# time_zone_name or timeZoneName: "long" "short"
|
114
|
+
# date_style or dateStyle: "full" "long" "medium" "short"
|
115
|
+
# time_style or timeStyle: "full" "long" "medium" "short"
|
116
|
+
# format_matcher or formatMatcher: "best-fit"(default) "basic"
|
117
|
+
# locale_matcher or localeMatcher: "best-fit"(default) "lookup"
|
118
|
+
# hour12: false true
|
119
|
+
# hour_cycle hourCycle: "h11" "h12" "h23" "h24"
|
120
|
+
# hour: "2-digit" "numeric"
|
121
|
+
# minute: "2-digit" "numeric"
|
122
|
+
# second: "2-digit" "numeric"
|
123
|
+
# day "2-digit" "numeric"
|
124
|
+
# month: "2-digit" "numeric" "long" "short" "narrow"
|
125
|
+
# weekday: "long" "short" "narrow"
|
126
|
+
# year: "2-digit" "numeric"
|
127
|
+
native_object = object.to_n
|
128
|
+
case format
|
129
|
+
when :standard
|
130
|
+
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
131
|
+
when :full
|
132
|
+
options[:dateStyle] = 'long'
|
133
|
+
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
134
|
+
when :custom
|
135
|
+
`native_object.toLocaleString(locale, #{options.to_n})`
|
136
|
+
else
|
137
|
+
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
138
|
+
end
|
139
|
+
elsif c_name == 'Time'
|
140
|
+
native_object = object.to_n
|
141
|
+
case format
|
142
|
+
when :standard
|
143
|
+
`native_object.toLocaleString(locale, #{options.to_n})`
|
144
|
+
when :full
|
145
|
+
options[:dateStyle] = 'long'
|
146
|
+
options[:timeStyle] = 'short'
|
147
|
+
`native_object.toLocaleString(locale, #{options.to_n})`
|
148
|
+
when :custom
|
149
|
+
`native_object.toLocaleString(locale, #{options.to_n})`
|
150
|
+
else
|
151
|
+
`native_object.toLocaleString(locale, #{options.to_n})`
|
152
|
+
end
|
153
|
+
else
|
154
|
+
raise "Unknown object type #{object.class} given to #l!"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
else # RUBY_ENGINE
|
158
|
+
def _send_i18n_method(method, args)
|
159
|
+
Isomorfeus.store.deferred_dispatch(type: 'I18N_LOAD', domain: i18n_domain, locale: current_locale, method: method, args: args)
|
160
|
+
result = Isomorfeus.store.dig(:i18n_state, i18n_domain, current_locale, method, JSON.dump(args))
|
161
|
+
result || ''
|
162
|
+
end
|
163
|
+
|
164
|
+
def l(object, format = :standard, _options = {})
|
165
|
+
Isomorfeus::I18n::Init.init
|
166
|
+
R18n.l(object, format)
|
167
|
+
end
|
168
|
+
end # RUBY_ENGINE
|
169
|
+
end
|
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:
|
4
|
+
version: 22.9.0.rc1
|
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-
|
11
|
+
date: 2022-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.0.
|
19
|
+
version: 7.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 7.0.
|
26
|
+
version: 7.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fast_gettext
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: 2.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
40
|
+
version: 2.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: http_accept_language
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.13.
|
61
|
+
version: 3.13.21
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.13.
|
68
|
+
version: 3.13.21
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: opal
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.5.
|
75
|
+
version: 1.5.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.5.
|
82
|
+
version: 1.5.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: opal-activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,56 +100,42 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.15.1
|
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.
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: isomorfeus-preact
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 10.7.2
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 10.7.2
|
110
|
+
version: 0.15.1
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: isomorfeus-redux
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- -
|
115
|
+
- - '='
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
117
|
+
version: 22.9.0.rc1
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- -
|
122
|
+
- - '='
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
124
|
+
version: 22.9.0.rc1
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: isomorfeus-transport
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - '='
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
131
|
+
version: 22.9.0.rc1
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - '='
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
138
|
+
version: 22.9.0.rc1
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: r18n-core
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +156,14 @@ dependencies:
|
|
170
156
|
requirements:
|
171
157
|
- - '='
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
159
|
+
version: 22.9.0.rc1
|
174
160
|
type: :development
|
175
161
|
prerelease: false
|
176
162
|
version_requirements: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - '='
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
166
|
+
version: 22.9.0.rc1
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: rake
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,15 +202,15 @@ files:
|
|
216
202
|
- README.md
|
217
203
|
- lib/isomorfeus-i18n.rb
|
218
204
|
- lib/isomorfeus/i18n/config.rb
|
205
|
+
- lib/isomorfeus/i18n/enhancer.rb
|
219
206
|
- lib/isomorfeus/i18n/fast_gettext/cache.rb
|
220
207
|
- lib/isomorfeus/i18n/fast_gettext/translation_repository/base.rb
|
221
|
-
- lib/isomorfeus/i18n/handler/locale_handler.rb
|
222
208
|
- lib/isomorfeus/i18n/init.rb
|
223
209
|
- lib/isomorfeus/i18n/middleware.rb
|
224
210
|
- lib/isomorfeus/i18n/missing_keys.rb
|
225
211
|
- lib/isomorfeus/i18n/reducer.rb
|
226
212
|
- lib/isomorfeus/i18n/version.rb
|
227
|
-
- lib/
|
213
|
+
- lib/lucid_i18n_mixin.rb
|
228
214
|
homepage: https://isomorfeus.com
|
229
215
|
licenses:
|
230
216
|
- MIT
|
@@ -242,9 +228,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
242
228
|
version: '0'
|
243
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
230
|
requirements:
|
245
|
-
- - "
|
231
|
+
- - ">"
|
246
232
|
- !ruby/object:Gem::Version
|
247
|
-
version:
|
233
|
+
version: 1.3.1
|
248
234
|
requirements: []
|
249
235
|
rubygems_version: 3.3.7
|
250
236
|
signing_key:
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Isomorfeus
|
4
|
-
module I18n
|
5
|
-
module Handler
|
6
|
-
class LocaleHandler < LucidHandler::Base
|
7
|
-
include FastGettext::Translation
|
8
|
-
include FastGettext::TranslationMultidomain
|
9
|
-
|
10
|
-
on_request do |response_agent|
|
11
|
-
Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
|
12
|
-
response_agent.agent_result = {}
|
13
|
-
# promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, method, [args])
|
14
|
-
response_agent.request.each_key do |domain|
|
15
|
-
if domain == 'init'
|
16
|
-
locale = response_agent.request[domain]
|
17
|
-
response_agent.agent_result['data'] = { 'available_locales' => FastGettext.available_locales,
|
18
|
-
'domain' => FastGettext.text_domain }
|
19
|
-
response_agent.agent_result['data']['locale'] = if Isomorfeus.available_locales.include?(locale)
|
20
|
-
Isomorfeus.current_locale = locale
|
21
|
-
else
|
22
|
-
Isomorfeus.current_locale = Isomorfeus.default_locale
|
23
|
-
end
|
24
|
-
else
|
25
|
-
response_agent.agent_result[domain] = {}
|
26
|
-
begin
|
27
|
-
if Isomorfeus.development?
|
28
|
-
Isomorfeus::I18n::Init.init
|
29
|
-
FastGettext.cache.reload_all!
|
30
|
-
end
|
31
|
-
FastGettext.with_domain(domain) do
|
32
|
-
response_agent.request[domain].each_key do |locale|
|
33
|
-
response_agent.agent_result[domain][locale] = {}
|
34
|
-
if Isomorfeus.current_locale != locale
|
35
|
-
if Isomorfeus.available_locales.include?(locale)
|
36
|
-
Isomorfeus.current_locale = locale
|
37
|
-
else
|
38
|
-
Isomorfeus.raise_error(message: "LocaleHandler: Locale #{locale} not available!")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
FastGettext.with_locale(locale) do
|
42
|
-
response_agent.request[domain][locale].each_key do |locale_method|
|
43
|
-
method_args = response_agent.request[domain][locale][locale_method]
|
44
|
-
method_result = case locale_method
|
45
|
-
when '_' then _(*method_args)
|
46
|
-
when 'n_' then n_(*method_args)
|
47
|
-
when 'np_' then np_(*method_args)
|
48
|
-
when 'ns_' then ns_(*method_args)
|
49
|
-
when 'p_' then p_(*method_args)
|
50
|
-
when 's_' then s_(*method_args)
|
51
|
-
when 'N_' then N_(*method_args)
|
52
|
-
when 'Nn_' then Nn_(*method_args)
|
53
|
-
when 'd_' then d_(*method_args)
|
54
|
-
when 'dn_' then dn_(*method_args)
|
55
|
-
when 'dnp_' then dnp_(*method_args)
|
56
|
-
when 'dns_' then dns_(*method_args)
|
57
|
-
when 'dp_' then dp_(*method_args)
|
58
|
-
when 'ds_' then ds_(*method_args)
|
59
|
-
when 'D_' then D_(*method_args)
|
60
|
-
when 'Dn_' then Dn_(*method_args)
|
61
|
-
when 'Dnp_' then Dnp_(*method_args)
|
62
|
-
when 'Dns_' then Dns_(*method_args)
|
63
|
-
when 'Dp_' then Dp_(*method_args)
|
64
|
-
when 'Ds_' then Ds_(*method_args)
|
65
|
-
else
|
66
|
-
Isomorfeus.raise_error(message: "No such locale method #{locale_method}")
|
67
|
-
end
|
68
|
-
response_agent.agent_result[domain][locale].deep_merge!(locale_method => { Oj.dump(method_args, mode: :strict) => method_result })
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
rescue Exception => e
|
74
|
-
response_agent.error = if Isomorfeus.production?
|
75
|
-
{ error: 'No such thing!' }
|
76
|
-
else
|
77
|
-
{ error: "Isomorfeus::I18n::Handler::LocaleHandler: #{e.message}" }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/lib/lucid_i18n/mixin.rb
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
module LucidI18n
|
2
|
-
module Mixin
|
3
|
-
CONTEXT_SEPARATOR = "\004"
|
4
|
-
NAMESPACE_SEPARATOR = '|'
|
5
|
-
NIL_BLOCK = -> { nil }
|
6
|
-
TRANSLATION_METHODS = [:_, :n_, :np_, :ns_, :p_, :s_]
|
7
|
-
|
8
|
-
def current_locale
|
9
|
-
Isomorfeus.current_locale
|
10
|
-
end
|
11
|
-
|
12
|
-
if RUBY_ENGINE == 'opal'
|
13
|
-
def _(*keys, &block)
|
14
|
-
domain = Isomorfeus.i18n_domain
|
15
|
-
locale = Isomorfeus.current_locale
|
16
|
-
Isomorfeus.raise_error(message: "I18n _(): no key given!") if keys.empty?
|
17
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, '_', keys)
|
18
|
-
return result if result
|
19
|
-
_promise_send_i18n_method(domain, locale, '_', keys)
|
20
|
-
block_given? ? block.call : ''
|
21
|
-
end
|
22
|
-
|
23
|
-
def n_(*keys, count, &block)
|
24
|
-
domain = Isomorfeus.i18n_domain
|
25
|
-
locale = Isomorfeus.current_locale
|
26
|
-
Isomorfeus.raise_error(message: "I18n n_(): no key given!") if keys.empty?
|
27
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, 'n_', keys + [count])
|
28
|
-
return result if result
|
29
|
-
_promise_send_i18n_method(domain, locale, 'n_', keys + [count])
|
30
|
-
block_given? ? block.call : ''
|
31
|
-
end
|
32
|
-
|
33
|
-
def np_(context, plural_one, *args, separator: nil, &block)
|
34
|
-
nargs = ["#{context}#{separator || CONTEXT_SEPARATOR}#{plural_one}"] + args
|
35
|
-
translation = n_(*nargs, &NIL_BLOCK)
|
36
|
-
return translation if translation
|
37
|
-
block_given? ? block.call : n_(plural_one, *args)
|
38
|
-
end
|
39
|
-
|
40
|
-
def ns_(*args, &block)
|
41
|
-
domain = Isomorfeus.i18n_domain
|
42
|
-
locale = Isomorfeus.current_locale
|
43
|
-
Isomorfeus.raise_error(message: "I18n ns_(): no args given!") if args.empty?
|
44
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, 'ns_', args)
|
45
|
-
return result if result
|
46
|
-
_promise_send_i18n_method(domain, locale, 'ns_', args)
|
47
|
-
block_given? ? block.call : n_(*args).split(NAMESPACE_SEPARATOR).last
|
48
|
-
end
|
49
|
-
|
50
|
-
def p_(namespace, key, separator = nil, &block)
|
51
|
-
domain = Isomorfeus.i18n_domain
|
52
|
-
locale = Isomorfeus.current_locale
|
53
|
-
args = separator ? [namespace, key, separator] : [namespace, key]
|
54
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, 'p_', args)
|
55
|
-
return result if result
|
56
|
-
_promise_send_i18n_method(domain, locale, 'p_', args)
|
57
|
-
block_given? ? block.call : ''
|
58
|
-
end
|
59
|
-
|
60
|
-
def s_(key, separator = nil, &block)
|
61
|
-
domain = Isomorfeus.i18n_domain
|
62
|
-
locale = Isomorfeus.current_locale
|
63
|
-
args = separator ? [key, separator] : [key]
|
64
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, 's_', args)
|
65
|
-
return result if result
|
66
|
-
_promise_send_i18n_method(domain, locale, 's_', args)
|
67
|
-
block_given? ? block.call : ''
|
68
|
-
end
|
69
|
-
|
70
|
-
def N_(translate)
|
71
|
-
translate
|
72
|
-
end
|
73
|
-
|
74
|
-
def Nn_(*keys)
|
75
|
-
keys
|
76
|
-
end
|
77
|
-
|
78
|
-
TRANSLATION_METHODS.each do |method|
|
79
|
-
define_method("d#{method}") do |domain, *args, &block|
|
80
|
-
old_domain = Isomorfeus.i18n_domain
|
81
|
-
begin
|
82
|
-
Isomorfeus.i18n_domain = domain
|
83
|
-
send(method, *args, &block)
|
84
|
-
ensure
|
85
|
-
Isomorfeus.i18n_domain = old_domain
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
define_method("D#{method}") do |*args, &block|
|
90
|
-
domain = Isomorfeus.i18n_domain
|
91
|
-
locale = Isomorfeus.current_locale
|
92
|
-
Isomorfeus.raise_error(message: "I18n D#{method}(): no args given!") if args.empty?
|
93
|
-
result = Redux.fetch_by_path(:i18n_state, domain, locale, "D#{method}", args)
|
94
|
-
return result if result
|
95
|
-
_promise_send_i18n_method(domain, locale, "D#{method}", args)
|
96
|
-
block_given? ? block.call : send(method, *args, &block)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def l(object, format = :standard, options = {})
|
101
|
-
c_name = object.class.to_s
|
102
|
-
locale = options.delete(:locale) { Isomorfeus.current_locale }
|
103
|
-
options = options.transform_keys { |k| `Opal.Preact.lower_camelize(k)` }
|
104
|
-
if object.is_a?(Numeric)
|
105
|
-
# options for number formatting:
|
106
|
-
# locale: locale string like 'de'
|
107
|
-
# currency: any currency code (like "EUR", "USD", "INR", etc.)
|
108
|
-
# currency_display or currencyDisplay: "symbol"(default) "code" "name"
|
109
|
-
# locale_matcher or localeMatcher: "best-fit"(default) "lookup"
|
110
|
-
# maximum_fraction_digits or maximumFractionDigits: A number from 0 to 20 (default is 3)
|
111
|
-
# maximum_significant_digits or maximumSignificantDigits: A number from 1 to 21 (default is 21)
|
112
|
-
# minimum_fraction_digits or minimumFractionDigits: A number from 0 to 20 (default is 3)
|
113
|
-
# minimum_integer_digits or minimumIntegerDigits: A number from 1 to 21 (default is 1)
|
114
|
-
# minimum_significant_digits or minimumSignificantDigits: A number from 1 to 21 (default is 21)
|
115
|
-
# style: "decimal"(default) "currency" "percent"
|
116
|
-
# use_grouping or useGrouping: true(default) false
|
117
|
-
`(object).toLocaleString(locale, #{options.to_n})`
|
118
|
-
elsif c_name == 'Date' || c_name == 'DateTime'
|
119
|
-
# options for date/time formating:
|
120
|
-
# format: "standard" "full"
|
121
|
-
# locale: locale string like 'de'
|
122
|
-
# time_zone or timeZone: timezone string like 'CET'
|
123
|
-
# time_zone_name or timeZoneName: "long" "short"
|
124
|
-
# date_style or dateStyle: "full" "long" "medium" "short"
|
125
|
-
# time_style or timeStyle: "full" "long" "medium" "short"
|
126
|
-
# format_matcher or formatMatcher: "best-fit"(default) "basic"
|
127
|
-
# locale_matcher or localeMatcher: "best-fit"(default) "lookup"
|
128
|
-
# hour12: false true
|
129
|
-
# hour_cycle hourCycle: "h11" "h12" "h23" "h24"
|
130
|
-
# hour: "2-digit" "numeric"
|
131
|
-
# minute: "2-digit" "numeric"
|
132
|
-
# second: "2-digit" "numeric"
|
133
|
-
# day "2-digit" "numeric"
|
134
|
-
# month: "2-digit" "numeric" "long" "short" "narrow"
|
135
|
-
# weekday: "long" "short" "narrow"
|
136
|
-
# year: "2-digit" "numeric"
|
137
|
-
native_object = object.to_n
|
138
|
-
case format
|
139
|
-
when :standard
|
140
|
-
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
141
|
-
when :full
|
142
|
-
options[:dateStyle] = 'long'
|
143
|
-
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
144
|
-
when :custom
|
145
|
-
`native_object.toLocaleString(locale, #{options.to_n})`
|
146
|
-
else
|
147
|
-
`native_object.toLocaleDateString(locale, #{options.to_n})`
|
148
|
-
end
|
149
|
-
elsif c_name == 'Time'
|
150
|
-
native_object = object.to_n
|
151
|
-
case format
|
152
|
-
when :standard
|
153
|
-
`native_object.toLocaleString(locale, #{options.to_n})`
|
154
|
-
when :full
|
155
|
-
options[:dateStyle] = 'long'
|
156
|
-
options[:timeStyle] = 'short'
|
157
|
-
`native_object.toLocaleString(locale, #{options.to_n})`
|
158
|
-
when :custom
|
159
|
-
`native_object.toLocaleString(locale, #{options.to_n})`
|
160
|
-
else
|
161
|
-
`native_object.toLocaleString(locale, #{options.to_n})`
|
162
|
-
end
|
163
|
-
else
|
164
|
-
raise "Unknown object type #{object.class} given to #l!"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def _promise_send_i18n_method(domain, locale, method, args)
|
171
|
-
if Isomorfeus::I18n::Init.initialized?
|
172
|
-
_promise_send_i18n_request(domain, locale, method, args)
|
173
|
-
else
|
174
|
-
Isomorfeus::I18n::Init.init_promise.then do
|
175
|
-
_promise_send_i18n_request(domain, locale, method, args)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def _promise_send_i18n_request(domain, locale, method, args)
|
181
|
-
Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', domain, locale, method, args).then do |agent|
|
182
|
-
_handle_i18n_response(agent, domain)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def _handle_i18n_response(agent, domain)
|
187
|
-
agent.process do
|
188
|
-
if on_browser?
|
189
|
-
Isomorfeus.store.collect_and_defer_dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
|
190
|
-
else
|
191
|
-
Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain => agent.response[domain] })
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
else # RUBY_ENGINE
|
196
|
-
class InternalTranslationProxy
|
197
|
-
extend FastGettext::Translation
|
198
|
-
extend FastGettext::TranslationMultidomain
|
199
|
-
end
|
200
|
-
|
201
|
-
def l(object, format = :standard, _options = {})
|
202
|
-
Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
|
203
|
-
R18n.l(object, format)
|
204
|
-
end
|
205
|
-
|
206
|
-
TRANSLATION_METHODS.each do |method|
|
207
|
-
define_method(method) do |domain, *args, &block|
|
208
|
-
Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
|
209
|
-
InternalTranslationProxy.send(method, domain, *args, &block)
|
210
|
-
end
|
211
|
-
|
212
|
-
define_method("d#{method}") do |domain, *args, &block|
|
213
|
-
Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
|
214
|
-
InternalTranslationProxy.send("d#{method}", domain, *args, &block)
|
215
|
-
end
|
216
|
-
|
217
|
-
define_method("D#{method}") do |*args, &block|
|
218
|
-
Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
|
219
|
-
InternalTranslationProxy.send("D#{method}", *args, &block)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end # RUBY_ENGINE
|
223
|
-
end
|
224
|
-
end
|