isomorfeus-i18n 1.0.0.zeta25 → 2.0.0.rc1

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: ef67fdbeb036a0469a6b0d44e92b9a050e8d3b948395ad42aef8a167f6a7a9d8
4
- data.tar.gz: 6d212529b528f9e2f538ceb03b5e526e6f94acf96d2453122e3b19bd46734c54
3
+ metadata.gz: '0616647998f63549d2f48c23035307f64dd5f105d17cc2485b03b36e017fb169'
4
+ data.tar.gz: 5a721f11928088db37832399040223f36aa67c36b8d3a0fd84c8a155c219eda4
5
5
  SHA512:
6
- metadata.gz: d6e6210fc3a959afd9a653ebc9464214403c996fb16ea399ff64ffa7bd08e8bf523e9a2eaeafe05d1e77201d6235e83818ff2368426808aa8285825f289628cc
7
- data.tar.gz: b0cb9d2f03515a9ea9496fe2030a87c7d5e7c582e19cf4130a921bf6f8e391834530fa670f3c816b3c63748b7d3eefc759bb028b34f390b38838bb43f77f035b
6
+ metadata.gz: be79bb31aa4509ef9499de8a59d27f7d2b58f4bbf837d226528539c9b69f4dbf999d7363db96d05eb541cc3b9d3ce7d70780f23526e5b732ebbc0b9c09c30b96
7
+ data.tar.gz: 223575909f0de8f2028c673330652aebd0f3305c73af756fdbb4c87b036351da65280073a9a55a766cb29b33926c6ec1a450f88566bb7d1f56aed8d3365a0041
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2018-2019 Jan Biedermann
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2019 Jan Biedermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
- # isomorfeus-i18n
2
-
3
- Internationalization for Isomorfeus.
4
-
5
- ### Community and Support
6
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
-
8
- ### Usage
9
- Locale files go in my_app/isomorfeus/locales.
10
- Supported formats: .mo, .po, .yml
11
-
12
- Using fast_gettext internally.
13
-
14
- ## Usage
15
-
16
- In any class:
17
- ```
18
- include LucidTranslation::Mixin
19
- ```
20
-
21
- after which the _ gettext methods are available for translation.
22
- See https://github.com/grosser/fast_gettext and https://rubydoc.info/gems/gettext/
1
+ # isomorfeus-i18n
2
+
3
+ Internationalization for Isomorfeus.
4
+
5
+ ### Community and Support
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
+
8
+ ### Usage
9
+ Locale files go in my_app/isomorfeus/locales.
10
+ Supported formats: .mo, .po, .yml
11
+
12
+ Using fast_gettext internally.
13
+
14
+ ## Usage
15
+
16
+ In any class:
17
+ ```
18
+ include LucidTranslation::Mixin
19
+ ```
20
+
21
+ after which the _ gettext methods are available for translation.
22
+ See https://github.com/grosser/fast_gettext and https://rubydoc.info/gems/gettext/
@@ -1,78 +1,78 @@
1
- module Isomorfeus
2
- # available settings
3
- class << self
4
- attr_accessor :i18n_type
5
-
6
- if RUBY_ENGINE == 'opal'
7
- def available_locales
8
- result = Redux.fetch_by_path(:i18n_state, :available_locales)
9
- result ? result : ['en']
10
- end
11
-
12
- def i18n_domain
13
- result = Redux.fetch_by_path(:i18n_state, :domain)
14
- result ? result : 'app'
15
- end
16
-
17
- def i18n_domain=(domain)
18
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain: domain })
19
- domain
20
- end
21
-
22
- def locale
23
- result = Redux.fetch_by_path(:i18n_state, :locale)
24
- result ? result : available_locales.first
25
- end
26
-
27
- def locale=(loc)
28
- Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
29
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { locale: locale })
30
- loc
31
- end
32
-
33
- def negotiated_locale
34
- @negotiated_locale
35
- end
36
-
37
- def negotiated_locale=(l)
38
- @negotiated_locale = l
39
- end
40
- else
41
- def available_locales
42
- @available_locales
43
- end
44
-
45
- def available_locales=(locs_arr)
46
- FastGettext.available_locales = locs_arr
47
- @available_locales = locs_arr
48
- end
49
-
50
- def i18n_domain
51
- @i18n_domain
52
- end
53
-
54
- def i18n_domain=(domain)
55
- FastGettext.text_domain = domain
56
- @i18n_domain = domain
57
- end
58
-
59
- def locale
60
- @locale
61
- end
62
-
63
- def locale=(loc)
64
- Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
65
- FastGettext.locale = loc
66
- @locale = loc
67
- end
68
-
69
- def locale_path
70
- @locale_path
71
- end
72
-
73
- def locale_path=(path)
74
- @locale_path = path
75
- end
76
- end
77
- end
78
- end
1
+ module Isomorfeus
2
+ # available settings
3
+ class << self
4
+ attr_accessor :i18n_type
5
+
6
+ if RUBY_ENGINE == 'opal'
7
+ def available_locales
8
+ result = Redux.fetch_by_path(:i18n_state, :available_locales)
9
+ result ? result : ['en']
10
+ end
11
+
12
+ def i18n_domain
13
+ result = Redux.fetch_by_path(:i18n_state, :domain)
14
+ result ? result : 'app'
15
+ end
16
+
17
+ def i18n_domain=(domain)
18
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { domain: domain })
19
+ domain
20
+ end
21
+
22
+ def locale
23
+ result = Redux.fetch_by_path(:i18n_state, :locale)
24
+ result ? result : available_locales.first
25
+ end
26
+
27
+ def locale=(loc)
28
+ Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
29
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { locale: locale })
30
+ loc
31
+ end
32
+
33
+ def negotiated_locale
34
+ @negotiated_locale
35
+ end
36
+
37
+ def negotiated_locale=(l)
38
+ @negotiated_locale = l
39
+ end
40
+ else
41
+ def available_locales
42
+ @available_locales
43
+ end
44
+
45
+ def available_locales=(locs_arr)
46
+ FastGettext.available_locales = locs_arr
47
+ @available_locales = locs_arr
48
+ end
49
+
50
+ def i18n_domain
51
+ @i18n_domain
52
+ end
53
+
54
+ def i18n_domain=(domain)
55
+ FastGettext.text_domain = domain
56
+ @i18n_domain = domain
57
+ end
58
+
59
+ def locale
60
+ @locale
61
+ end
62
+
63
+ def locale=(loc)
64
+ Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
65
+ FastGettext.locale = loc
66
+ @locale = loc
67
+ end
68
+
69
+ def locale_path
70
+ @locale_path
71
+ end
72
+
73
+ def locale_path=(path)
74
+ @locale_path = path
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,76 +1,76 @@
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
- locale
21
- else
22
- FastGettext.locale
23
- end
24
- else
25
- response_agent.agent_result[domain] = {}
26
- begin
27
- FastGettext.with_domain(domain) do
28
- response_agent.request[domain].each_key do |locale|
29
- response_agent.agent_result[domain][locale] = {}
30
- Isomorfeus.raise_error(message: "Locale #{locale} not available!") unless Isomorfeus.available_locales.include?(locale)
31
- FastGettext.with_locale(locale) do
32
- response_agent.request[domain][locale].each_key do |locale_method|
33
- method_args = response_agent.request[domain][locale][locale_method]
34
- method_result = case locale_method
35
- when '_' then _(*method_args)
36
- when 'n_' then n_(*method_args)
37
- when 'np_' then np_(*method_args)
38
- when 'ns_' then ns_(*method_args)
39
- when 'p_' then p_(*method_args)
40
- when 's_' then s_(*method_args)
41
- when 'N_' then N_(*method_args)
42
- when 'Nn_' then Nn_(*method_args)
43
- when 'd_' then d_(*method_args)
44
- when 'dn_' then dn_(*method_args)
45
- when 'dnp_' then dnp_(*method_args)
46
- when 'dns_' then dns_(*method_args)
47
- when 'dp_' then dp_(*method_args)
48
- when 'ds_' then ds_(*method_args)
49
- when 'D_' then D_(*method_args)
50
- when 'Dn_' then Dn_(*method_args)
51
- when 'Dnp_' then Dnp_(*method_args)
52
- when 'Dns_' then Dns_(*method_args)
53
- when 'Dp_' then Dp_(*method_args)
54
- when 'Ds_' then Ds_(*method_args)
55
- else
56
- Isomorfeus.raise_error(message: "No such locale method #{locale_method}")
57
- end
58
- response_agent.agent_result[domain][locale].deep_merge!(locale_method => { Oj.dump(method_args, mode: :strict) => method_result })
59
- end
60
- end
61
- end
62
- end
63
- rescue Exception => e
64
- response_agent.error = if Isomorfeus.production?
65
- { error: 'No such thing!' }
66
- else
67
- { error: "Isomorfeus::I18n::Handler::LocaleHandler: #{e.message}" }
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
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
+ locale
21
+ else
22
+ FastGettext.locale
23
+ end
24
+ else
25
+ response_agent.agent_result[domain] = {}
26
+ begin
27
+ FastGettext.with_domain(domain) do
28
+ response_agent.request[domain].each_key do |locale|
29
+ response_agent.agent_result[domain][locale] = {}
30
+ Isomorfeus.raise_error(message: "Locale #{locale} not available!") unless Isomorfeus.available_locales.include?(locale)
31
+ FastGettext.with_locale(locale) do
32
+ response_agent.request[domain][locale].each_key do |locale_method|
33
+ method_args = response_agent.request[domain][locale][locale_method]
34
+ method_result = case locale_method
35
+ when '_' then _(*method_args)
36
+ when 'n_' then n_(*method_args)
37
+ when 'np_' then np_(*method_args)
38
+ when 'ns_' then ns_(*method_args)
39
+ when 'p_' then p_(*method_args)
40
+ when 's_' then s_(*method_args)
41
+ when 'N_' then N_(*method_args)
42
+ when 'Nn_' then Nn_(*method_args)
43
+ when 'd_' then d_(*method_args)
44
+ when 'dn_' then dn_(*method_args)
45
+ when 'dnp_' then dnp_(*method_args)
46
+ when 'dns_' then dns_(*method_args)
47
+ when 'dp_' then dp_(*method_args)
48
+ when 'ds_' then ds_(*method_args)
49
+ when 'D_' then D_(*method_args)
50
+ when 'Dn_' then Dn_(*method_args)
51
+ when 'Dnp_' then Dnp_(*method_args)
52
+ when 'Dns_' then Dns_(*method_args)
53
+ when 'Dp_' then Dp_(*method_args)
54
+ when 'Ds_' then Ds_(*method_args)
55
+ else
56
+ Isomorfeus.raise_error(message: "No such locale method #{locale_method}")
57
+ end
58
+ response_agent.agent_result[domain][locale].deep_merge!(locale_method => { Oj.dump(method_args, mode: :strict) => method_result })
59
+ end
60
+ end
61
+ end
62
+ end
63
+ rescue Exception => e
64
+ response_agent.error = if Isomorfeus.production?
65
+ { error: 'No such thing!' }
66
+ else
67
+ { error: "Isomorfeus::I18n::Handler::LocaleHandler: #{e.message}" }
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,47 +1,47 @@
1
- module Isomorfeus
2
- module I18n
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
14
- end
15
- end
16
-
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])
25
- end
26
- @initializing = false
27
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
28
- end
29
- end
30
- end
31
-
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
43
- end
44
- end
45
- end
46
- end
47
- end
1
+ module Isomorfeus
2
+ module I18n
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
14
+ end
15
+ end
16
+
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])
25
+ end
26
+ @initializing = false
27
+ Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
28
+ end
29
+ end
30
+ end
31
+
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
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,38 +1,38 @@
1
- module Isomorfeus
2
- module I18n
3
- module Reducer
4
- def self.add_reducer_to_store
5
- i18n_reducer = Redux.create_reducer do |prev_state, action|
6
- action_type = action[:type]
7
- if action_type.JS.startsWith('I18N_')
8
- case action_type
9
- when 'I18N_STATE'
10
- if action.key?(:set_state)
11
- action[:set_state]
12
- else
13
- prev_state
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
25
- else
26
- prev_state
27
- end
28
- else
29
- prev_state
30
- end
31
- end
32
-
33
- Redux::Store.preloaded_state_merge!(i18n_state: {})
34
- Redux::Store.add_reducer(i18n_state: i18n_reducer)
35
- end
36
- end
37
- end
38
- end
1
+ module Isomorfeus
2
+ module I18n
3
+ module Reducer
4
+ def self.add_reducer_to_store
5
+ i18n_reducer = Redux.create_reducer do |prev_state, action|
6
+ action_type = action[:type]
7
+ if action_type.JS.startsWith('I18N_')
8
+ case action_type
9
+ when 'I18N_STATE'
10
+ if action.key?(:set_state)
11
+ action[:set_state]
12
+ else
13
+ prev_state
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
25
+ else
26
+ prev_state
27
+ end
28
+ else
29
+ prev_state
30
+ end
31
+ end
32
+
33
+ Redux::Store.preloaded_state_merge!(i18n_state: {})
34
+ Redux::Store.add_reducer(i18n_state: i18n_reducer)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
- module Isomorfeus
2
- module I18n
3
- VERSION = '1.0.0.zeta25'
4
- end
1
+ module Isomorfeus
2
+ module I18n
3
+ VERSION = '2.0.0.rc1'
4
+ end
5
5
  end