vesper-rails 0.3.0 → 0.4.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/CHANGELOG.md +4 -0
- data/lib/locale/detect.rb +35 -0
- data/lib/vesper/version.rb +1 -1
- data/lib/vesper-rails.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de6203b948c6a03a13aad3cc41561e49f839e7b9517f6e2312717d0265ec92f9
|
|
4
|
+
data.tar.gz: a0a77db569e811c834c6fb477399f450ff4b413575a6cab70f48fe9aefabae90
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb1994482957dba4e175b7fd49aa9ebd00c1c91190e59df45f363419f89b45593dd0ddad0ec5ddc804f1ef25068e77a4525ec283faae4ad32233a55fd47e34a8
|
|
7
|
+
data.tar.gz: '08400e7168130e1958b5c962fc910c32974b23db9685ce66b3bd2ac3ebb8d03e01ae33287712b935ee4206237ec787f247ba66ddd601551ffe91b011cfce804e'
|
data/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Locale::Detect module
|
|
4
|
+
module Locale
|
|
5
|
+
module Detect
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
before_action :switch_locale
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
protected
|
|
13
|
+
|
|
14
|
+
def switch_locale
|
|
15
|
+
I18n.locale = locale.to_sym
|
|
16
|
+
# logger.debug "* Locale set to '#{locale}'"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def browser_locale
|
|
22
|
+
request.env["HTTP_ACCEPT_LANGUAGE"]&.scan(/^(?:[a-z]{2}-[A-Z]{2}|[a-z]{2}-[0-9]+|[a-z]{2})/)&.first || ""
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def browser_short_locale
|
|
26
|
+
browser_locale&.split("-")[0] || ""
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def locale
|
|
30
|
+
available_locales = I18n.available_locales
|
|
31
|
+
available_locales.include?(browser_locale.to_sym) || available_locales.include?(browser_short_locale.to_sym) ?
|
|
32
|
+
browser_locale : I18n.default_locale
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/vesper/version.rb
CHANGED
data/lib/vesper-rails.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vesper-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yasumasa Ashida
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- app/controllers/vesper/controller.rb
|
|
94
94
|
- lib/date_util.rb
|
|
95
95
|
- lib/json_util.rb
|
|
96
|
+
- lib/locale/detect.rb
|
|
96
97
|
- lib/vesper-rails.rb
|
|
97
98
|
- lib/vesper/api/error/renderable.rb
|
|
98
99
|
- lib/vesper/api/renderable.rb
|