auto_locale 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -4
- data/.gitlab-ci.yml +42 -0
- data/.rubocop.yml +11 -0
- data/Gemfile +2 -0
- data/README.md +25 -0
- data/Rakefile +8 -0
- data/auto_locale.gemspec +23 -14
- data/lib/auto_locale.rb +4 -51
- data/lib/auto_locale/action_controller.rb +43 -0
- data/lib/auto_locale/version.rb +2 -17
- metadata +81 -10
- data/README.rdoc +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 752d8af8cc5bf2b52e9ccb8e7b4c85ff449ba3a477b403c054969d09c560b51d
|
4
|
+
data.tar.gz: b401139ab3942133039f286b29127eed74191f154319cabab3085f66eb3cb253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db97c5746e8c4cf5f4ac5693df981c89d62b291e3ce49356155f513c3ab41a36180ad6f3162545deb78386479d66e64a05d873934d30dd4985bfa6b18e3c964
|
7
|
+
data.tar.gz: 05ff123e7c51ba6c8f8e49370c692e6e22b17a5f4d651b8baa025dddbe581ff2ec3c3f81d1501ea07bfbad4d9def3367f7dfbd23d3855860ba71897c4763199c
|
data/.gitignore
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
.
|
3
|
-
|
4
|
-
pkg/*
|
1
|
+
/.bundle
|
2
|
+
/Gemfile.lock
|
3
|
+
/pkg
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
stages:
|
2
|
+
- build
|
3
|
+
- codequality
|
4
|
+
- security
|
5
|
+
|
6
|
+
build:
|
7
|
+
stage: build
|
8
|
+
image: ruby:2.6
|
9
|
+
script:
|
10
|
+
- gem install bundler --no-document
|
11
|
+
- bundle update
|
12
|
+
artifacts:
|
13
|
+
paths:
|
14
|
+
- Gemfile.lock
|
15
|
+
|
16
|
+
rubocop:
|
17
|
+
stage: codequality
|
18
|
+
image: ruby:2.6
|
19
|
+
script:
|
20
|
+
- gem install rubocop rubocop-performance --no-document
|
21
|
+
- rubocop
|
22
|
+
|
23
|
+
dependency_scanning:
|
24
|
+
stage: security
|
25
|
+
dependencies:
|
26
|
+
- build
|
27
|
+
image: docker:stable
|
28
|
+
variables:
|
29
|
+
DOCKER_DRIVER: overlay2
|
30
|
+
allow_failure: true
|
31
|
+
services:
|
32
|
+
- docker:stable-dind
|
33
|
+
script:
|
34
|
+
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
35
|
+
- docker run
|
36
|
+
--env DEP_SCAN_DISABLE_REMOTE_CHECKS="${DEP_SCAN_DISABLE_REMOTE_CHECKS:-false}"
|
37
|
+
--volume "$PWD:/code"
|
38
|
+
--volume /var/run/docker.sock:/var/run/docker.sock
|
39
|
+
"registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$SP_VERSION" /code
|
40
|
+
artifacts:
|
41
|
+
paths:
|
42
|
+
- gl-dependency-scanning-report.json
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# auto_locale
|
2
|
+
|
3
|
+
Automatically set the locale from the browsers HTTP_ACCEPT_LANGUAGE header.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'auto_locale'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install auto_locale
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/auto_locale.gemspec
CHANGED
@@ -1,18 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'auto_locale/version'
|
4
6
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'auto_locale'
|
9
|
+
spec.version = AutoLocale::VERSION
|
10
|
+
spec.authors = ['Florian Schwab']
|
11
|
+
spec.email = ['me@ydkn.de']
|
12
|
+
spec.homepage = 'https://gitlab.com/ydkn/auto_locale'
|
13
|
+
spec.summary = 'Automatically set the locale from the browsers HTTP_ACCEPT_LANGUAGE header'
|
14
|
+
spec.description = 'Automatically set the current locale from the browsers HTTP_ACCEPT_LANGUAGE header'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'actionpack'
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
18
27
|
end
|
data/lib/auto_locale.rb
CHANGED
@@ -1,53 +1,6 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2011 Florian Schwab
|
3
|
-
#
|
4
|
-
# This program is free software: you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU General Public License as published by
|
6
|
-
# the Free Software Foundation, either version 3 of the License, or
|
7
|
-
# (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1
|
+
# frozen_string_literal: true
|
16
2
|
|
3
|
+
require 'action_controller/base'
|
4
|
+
require 'auto_locale/action_controller'
|
17
5
|
|
18
|
-
|
19
|
-
|
20
|
-
module AutoLocale
|
21
|
-
def self.included(base)
|
22
|
-
base.before_action :set_auto_locale
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_auto_locale
|
26
|
-
available_locales = I18n.available_locales.map(&:to_s)
|
27
|
-
|
28
|
-
locales = request.accept_language.split(/\s*,\s*/).map do |l|
|
29
|
-
l += ';q=1.0' unless l =~ /;q=\d+\.\d+$/
|
30
|
-
l.split(';q=')
|
31
|
-
end.sort do |a, b|
|
32
|
-
b.last.to_f <=> a.last.to_f
|
33
|
-
end.map do |l|
|
34
|
-
l.first.downcase.gsub(/-[a-z]+$/i) { |c| c.upcase }
|
35
|
-
end
|
36
|
-
|
37
|
-
locales.each do |l|
|
38
|
-
available_locales.each do |al|
|
39
|
-
if l == al
|
40
|
-
I18n.locale = al.to_sym
|
41
|
-
return
|
42
|
-
elsif l.split('-', 2).first == al.split('-', 2).first
|
43
|
-
I18n.locale = al.to_sym
|
44
|
-
return
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
rescue
|
49
|
-
I18n.locale = I18n.default_locale
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
ActionController::Base.send :include, AutoLocale
|
6
|
+
ActionController::Base.send(:include, AutoLocale::ActionController)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AutoLocale
|
4
|
+
# Extension to ActionController
|
5
|
+
module ActionController
|
6
|
+
def self.included(base)
|
7
|
+
base.before_action :set_auto_locale
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_auto_locale
|
11
|
+
available_locales = I18n.available_locales.map(&:to_s)
|
12
|
+
|
13
|
+
auto_locale_request_locales.each do |l|
|
14
|
+
available_locales.each do |al|
|
15
|
+
if l == al
|
16
|
+
I18n.locale = al.to_sym
|
17
|
+
|
18
|
+
return nil
|
19
|
+
elsif l.split('-', 2).first == al.split('-', 2).first
|
20
|
+
I18n.locale = al.to_sym
|
21
|
+
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue StandardError
|
27
|
+
I18n.locale = I18n.default_locale
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def auto_locale_request_locales # rubocop:disable Metrics/AbcSize
|
33
|
+
locales = request.accept_language.split(/\s*,\s*/).map do |l|
|
34
|
+
l += ';q=1.0' unless l.match?(/;q=\d+\.\d+$/)
|
35
|
+
l.split(';q=')
|
36
|
+
end
|
37
|
+
|
38
|
+
locales.sort! { |a, b| b.last.to_f <=> a.last.to_f }
|
39
|
+
|
40
|
+
locales.map { |l| l.first.downcase.gsub(/-[a-z]+$/i, &:upcase) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/auto_locale/version.rb
CHANGED
@@ -1,20 +1,5 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2011 Florian Schwab
|
3
|
-
#
|
4
|
-
# This program is free software: you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU General Public License as published by
|
6
|
-
# the Free Software Foundation, either version 3 of the License, or
|
7
|
-
# (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
-
|
1
|
+
# frozen_string_literal: true
|
17
2
|
|
18
3
|
module AutoLocale
|
19
|
-
VERSION = '0.2.
|
4
|
+
VERSION = '0.2.1'
|
20
5
|
end
|
metadata
CHANGED
@@ -1,17 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_locale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Schwab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Automatically set the current locale from the browsers HTTP_ACCEPT_LANGUAGE
|
84
|
+
header
|
15
85
|
email:
|
16
86
|
- me@ydkn.de
|
17
87
|
executables: []
|
@@ -19,14 +89,17 @@ extensions: []
|
|
19
89
|
extra_rdoc_files: []
|
20
90
|
files:
|
21
91
|
- ".gitignore"
|
92
|
+
- ".gitlab-ci.yml"
|
93
|
+
- ".rubocop.yml"
|
22
94
|
- Gemfile
|
23
95
|
- LICENSE
|
24
|
-
- README.
|
96
|
+
- README.md
|
25
97
|
- Rakefile
|
26
98
|
- auto_locale.gemspec
|
27
99
|
- lib/auto_locale.rb
|
100
|
+
- lib/auto_locale/action_controller.rb
|
28
101
|
- lib/auto_locale/version.rb
|
29
|
-
homepage:
|
102
|
+
homepage: https://gitlab.com/ydkn/auto_locale
|
30
103
|
licenses: []
|
31
104
|
metadata: {}
|
32
105
|
post_install_message:
|
@@ -44,10 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
117
|
- !ruby/object:Gem::Version
|
45
118
|
version: '0'
|
46
119
|
requirements: []
|
47
|
-
|
48
|
-
rubygems_version: 2.5.1
|
120
|
+
rubygems_version: 3.0.3
|
49
121
|
signing_key:
|
50
122
|
specification_version: 4
|
51
123
|
summary: Automatically set the locale from the browsers HTTP_ACCEPT_LANGUAGE header
|
52
124
|
test_files: []
|
53
|
-
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
= AutoLocale
|
2
|
-
|
3
|
-
Automatically set the locale from the browsers HTTP_ACCEPT_LANGUAGE header.
|
4
|
-
|
5
|
-
|
6
|
-
== Installation
|
7
|
-
|
8
|
-
Add the dependency to the Gemfile of your application:
|
9
|
-
|
10
|
-
gem "auto_locale"
|
11
|
-
|
12
|
-
Then call <tt>bundle install</tt> on your console.
|
13
|
-
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2011-2016 Florian Schwab. See LICENSE for details.
|