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 +4 -4
- data/lib/flame/r18n.rb +1 -0
- data/lib/flame/r18n/locale_in_path.rb +52 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a867492f6e510e22cb18fd39fa30335f5bedb3f0
|
4
|
+
data.tar.gz: 0c5c533e7ab6280659c2f2c531f8364ddca7a80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53e79eca73945d353098a250eca7f99051ea2c3ad803fcf845471e858cd30df38c61c6750f4299e91176190164286dd3efbccd4b1a0a59f1b72244ea3de40595
|
7
|
+
data.tar.gz: f76bbac42b1cfd6b619f5c7981302a316ec6cc15c629090c3c716375e06b16e8b34551bfe0d66df0b7a597d4d9f00b1cfe5a7c217bfb877e2814fab7751a1277
|
data/lib/flame/r18n.rb
CHANGED
@@ -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.
|
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-
|
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.
|
79
|
+
rubygems_version: 2.6.13
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: R18n plugin for Flame-framework
|