flame-r18n 1.3.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: c5fe2146f9f4b7a918d01b3686420378f58ecc2a
4
- data.tar.gz: 18f7f0478fd922587f1aa7dd6a24d56a5b7037a7
3
+ metadata.gz: 2061beaf8e72a910714e93a68e08e7361cde88a4
4
+ data.tar.gz: 44068fc8d3ee0ccd7719060605f0212bf2a1de92
5
5
  SHA512:
6
- metadata.gz: 43072cf755dac06280a4a38910701573f09ce97af58178b21b6937aa99c57d3c42650e8f0673de9b3dcdc1a8cad5d767395470e565526ef62b800caa4f7a3401
7
- data.tar.gz: 93201ac10ad284aee53450e6b377bed8ee54d4c06c794a62f0458179b57a945a72c000028dafe585a4a1740a36febaf50fd472fb64c4d7ffbb58a8f55b248599
6
+ metadata.gz: ef3a05d013d66162ad43da9315397ba57e95c46305ef72fc2537309cb9eb2c99988ca28e2271b890ecb9031170f4e3657e5d32af9efacbbd49d521eb4a9bdd3c
7
+ data.tar.gz: b5f1e2e753fad2f3476de0985d1d15dcec077319b086a7d7987068b4ea9208629e4ba382b54196885608074a29064d662e18f04c10153a7158ff92eda55c991c
@@ -1,59 +1,6 @@
1
- require 'r18n-core'
2
-
3
- module Flame
4
- # Module for Flame::R18n extension with helper methods and base class
5
- module R18n
6
- include ::R18n::Helpers
7
-
8
- def self.config(app)
9
- app.config[:default_locale] = proc { ::R18n::I18n.default }
10
- app.config[:locales] = proc { ::R18n.default_places }
11
- app.config[:locales_dir] = proc do
12
- File.join(app.config[:root_dir], 'locales')
13
- end
14
-
15
- ::R18n.default_places { app.config[:locales_dir] }
16
- end
17
-
18
- def execute(method)
19
- load_r18n
20
- session[:locale] = ::R18n.get.locale.code
21
- super
22
- end
23
-
24
- def init_r18n(locale)
25
- ::R18n::I18n.new(
26
- Array(locale) | locales_from_env,
27
- ::R18n.default_places,
28
- off_filters: :untranslated,
29
- on_filters: :untranslated_html
30
- )
31
- end
1
+ # frozen_string_literal: true
32
2
 
33
- def thread_locale=(locale)
34
- ::R18n.thread_set init_r18n locale
35
- end
36
-
37
- private
38
-
39
- def locales_from_env
40
- ::R18n::I18n.parse_http(request.env['HTTP_ACCEPT_LANGUAGE'])
41
- end
42
-
43
- def preferred_locale
44
- return super if defined? super
45
- params[:locale] || session[:locale]
46
- end
47
-
48
- def load_r18n
49
- ::R18n.clear_cache! if config[:environment] == 'development'
50
-
51
- ::R18n.thread_set do
52
- default_locale = config[:default_locale]
53
- ::R18n::I18n.default = default_locale if default_locale
3
+ require 'r18n-core'
54
4
 
55
- init_r18n preferred_locale
56
- end
57
- end
58
- end
59
- end
5
+ require_relative './r18n/configuration'
6
+ require_relative './r18n/initialization'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flame
4
+ module R18n
5
+ ## Module for adding Flame::R18n properties into application configuration
6
+ module Configuration
7
+ def self.included(app)
8
+ app.config[:default_locale] = proc { ::R18n::I18n.default }
9
+ app.config[:locales] = proc { ::R18n.default_places }
10
+ app.config[:locales_dir] = proc do
11
+ File.join(app.config[:root_dir], 'locales')
12
+ end
13
+
14
+ ::R18n.default_places { app.config[:locales_dir] }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'r18n-core'
4
+
5
+ module Flame
6
+ module R18n
7
+ ## Module for R18n in thread initialization with helper methods
8
+ module Initialization
9
+ include ::R18n::Helpers
10
+
11
+ def initialize(*)
12
+ super
13
+ load_r18n
14
+ session[:locale] = r18n.locale.code
15
+ end
16
+
17
+ def init_r18n(locale)
18
+ ::R18n::I18n.new(
19
+ Array(locale) | locales_from_env,
20
+ ::R18n.default_places,
21
+ off_filters: :untranslated,
22
+ on_filters: :untranslated_html
23
+ )
24
+ end
25
+
26
+ def thread_locale=(locale)
27
+ ::R18n.thread_set init_r18n locale
28
+ end
29
+
30
+ private
31
+
32
+ def locales_from_env
33
+ ::R18n::I18n.parse_http(request.env['HTTP_ACCEPT_LANGUAGE'])
34
+ end
35
+
36
+ def preferred_locale
37
+ params[:locale] || session[:locale]
38
+ end
39
+
40
+ def load_r18n
41
+ ::R18n.clear_cache! if config[:environment] == 'development'
42
+
43
+ ::R18n.thread_set do
44
+ default_locale = config[:default_locale]
45
+ ::R18n::I18n.default = default_locale if default_locale
46
+
47
+ init_r18n preferred_locale
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame-r18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flame
@@ -53,6 +53,8 @@ extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
55
  - lib/flame/r18n.rb
56
+ - lib/flame/r18n/configuration.rb
57
+ - lib/flame/r18n/initialization.rb
56
58
  homepage: https://github.com/AlexWayfer/flame-r18n
57
59
  licenses:
58
60
  - MIT
@@ -73,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  version: '0'
74
76
  requirements: []
75
77
  rubyforge_project:
76
- rubygems_version: 2.5.1
78
+ rubygems_version: 2.6.11
77
79
  signing_key:
78
80
  specification_version: 4
79
81
  summary: R18n plugin for Flame-framework