flame-r18n 2.1.1 → 2.3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b7d001944f9fef5e69d11ad22da551cb97eeadc
4
- data.tar.gz: 3bcd0bf0b1c0ca1efe7f3ec1c654c0370b9922cd
3
+ metadata.gz: a867492f6e510e22cb18fd39fa30335f5bedb3f0
4
+ data.tar.gz: 0c5c533e7ab6280659c2f2c531f8364ddca7a80a
5
5
  SHA512:
6
- metadata.gz: ef0821ee8537a20fdb64165d1b7b3ca8c6a9e7e5297c3c7394f069286a0313cc86ed4cd55843b549f57461f5a26c74c21146dcec329080b582871df631cbe328
7
- data.tar.gz: 176715bf76a7a9fdcc9019770f244a9e208137f91794fbd37e271952a0eb7fc0dea157b23e37fa25dc5ea3aa9f62f1f1c079005315259af7b21e25c41254237c
6
+ metadata.gz: 53e79eca73945d353098a250eca7f99051ea2c3ad803fcf845471e858cd30df38c61c6750f4299e91176190164286dd3efbccd4b1a0a59f1b72244ea3de40595
7
+ data.tar.gz: f76bbac42b1cfd6b619f5c7981302a316ec6cc15c629090c3c716375e06b16e8b34551bfe0d66df0b7a597d4d9f00b1cfe5a7c217bfb877e2814fab7751a1277
@@ -4,3 +4,4 @@ require 'r18n-core'
4
4
 
5
5
  require_relative './r18n/configuration'
6
6
  require_relative './r18n/initialization'
7
+ require_relative './r18n/locale_in_path'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flame
4
+ module R18n
5
+ ## Module for including to controllers, mounted with `:locale` param in path
6
+ module LocaleInPath
7
+ include Flame::R18n::Initialization
8
+
9
+ protected
10
+
11
+ def execute(method)
12
+ unless request_path_with_available_locale?
13
+ return redirect_with_preferred_locale_in_path
14
+ end
15
+ super
16
+ end
17
+
18
+ private
19
+
20
+ def path_to(*args)
21
+ args << {} unless args.last.is_a? Hash
22
+ args.last[:locale] = r18n.locale.code unless args.last.include?(:locale)
23
+ super
24
+ end
25
+
26
+ def request_path_with_available_locale?
27
+ available_locale_codes.include?(request.path.parts.first.to_s)
28
+ end
29
+
30
+ def redirect_with_preferred_locale_in_path
31
+ path_with_locale = Flame::Path.merge(
32
+ nil, r18n.locale.code, request.fullpath
33
+ )
34
+ path_with_locale.sub!(%r{(\/)+$}, '')
35
+ redirect path_with_locale, 301
36
+ end
37
+
38
+ def path_without_locale
39
+ return request.path.to_s unless request_path_with_available_locale?
40
+ Flame::Path.merge(
41
+ request.path.parts[1..-1].unshift('/')
42
+ )
43
+ end
44
+
45
+ def fullpath_with_specific_locale(locale)
46
+ fullpath_parts = request.fullpath.to_s.split('/')
47
+ fullpath_parts[1] = locale.code
48
+ Flame::Path.merge fullpath_parts
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: 2.1.1
4
+ version: 2.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flame
@@ -55,6 +55,7 @@ files:
55
55
  - lib/flame/r18n.rb
56
56
  - lib/flame/r18n/configuration.rb
57
57
  - lib/flame/r18n/initialization.rb
58
+ - lib/flame/r18n/locale_in_path.rb
58
59
  homepage: https://github.com/AlexWayfer/flame-r18n
59
60
  licenses:
60
61
  - MIT
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  version: '0'
76
77
  requirements: []
77
78
  rubyforge_project:
78
- rubygems_version: 2.6.11
79
+ rubygems_version: 2.6.13
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: R18n plugin for Flame-framework