isomorfeus-i18n 1.0.0.zeta23 → 2.0.0.rc2

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: 4e69010c5deaf30f403d170dc57dba3020da4236ba40df78950cdb16e5b89b1a
4
- data.tar.gz: 71ccc91befe2d5d699f9bac50ee3ce172c5499422697920f064907488d30b9c1
3
+ metadata.gz: da916597e3c7a4d88acf9e202d84202d61cd19dfaa6cd527dc3ecc071d95c013
4
+ data.tar.gz: 55fac42ff4cc421705127c0bc28060553d7f96ed19928499824a61af4fd8c022
5
5
  SHA512:
6
- metadata.gz: 5b0b0aecd626e4c435db28edfd5931d4181fe0054add4ee076af200401265ba8385334149aefb35f7ae4eccb98b64575a648b6e9939fa434d4b6eaa863099dd3
7
- data.tar.gz: '083e94aaa20be606d271c293cd124036c9ecae596e8bf1c18d4b4b91f96148b2c81da87d36c258b71d575fb673e9c139670b0ee66b8e091f537b6cf8c3626399'
6
+ metadata.gz: 751d1a5e11e8c45aab9943d01ee595ada7812e9be41fb8e1770b170715d9d3e87dbb6755051f42e1eb2997a5f30e54244f9959f98ee3eb2526fc131973743978
7
+ data.tar.gz: b786c55171b9d450c386885f22b4e68ae5b949cc3c4b89e72c0881b57657092b8e06be53abf5bee4604b89de06bdcad94073531363c06b7e40c8a0da5258a0e2
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,48 +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
- `console.error(#{agent.response[:error].to_n})`
25
- Isomorfeus.raise_error(message: agent.response[:error])
26
- end
27
- @initializing = false
28
- Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
29
- end
30
- end
31
- end
32
-
33
- def self.initialized?
34
- result = Redux.fetch_by_path(:i18n_state, :available_locales)
35
- result ? true : false
36
- end
37
- else
38
- def self.init
39
- FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
40
- FastGettext.available_locales = Isomorfeus.available_locales
41
- FastGettext.text_domain = Isomorfeus.i18n_domain
42
- FastGettext.locale = Isomorfeus.locale
43
- Thread.current[:isomorfeus_i18n_initialized] = true
44
- end
45
- end
46
- end
47
- end
48
- 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,31 +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
- result = prev_state.deep_merge(action[:data])
17
- result == prev_state ? prev_state : result
18
- else
19
- prev_state
20
- end
21
- else
22
- prev_state
23
- end
24
- end
25
-
26
- Redux::Store.preloaded_state_merge!(i18n_state: {})
27
- Redux::Store.add_reducer(i18n_state: i18n_reducer)
28
- end
29
- end
30
- end
31
- 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.zeta23'
4
- end
1
+ module Isomorfeus
2
+ module I18n
3
+ VERSION = '2.0.0.rc2'
4
+ end
5
5
  end