auto_locale 0.2.0 → 0.2.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
- SHA1:
3
- metadata.gz: 1f6b511354e15ff95bc45356a341afcb97a45ceb
4
- data.tar.gz: 9d0883e0911dd3db1ac246119aa1e366a6453014
2
+ SHA256:
3
+ metadata.gz: 752d8af8cc5bf2b52e9ccb8e7b4c85ff449ba3a477b403c054969d09c560b51d
4
+ data.tar.gz: b401139ab3942133039f286b29127eed74191f154319cabab3085f66eb3cb253
5
5
  SHA512:
6
- metadata.gz: 5025078d64d10e06921b97e0284f3f660e18320ce2d5d55328cadbe8508eb9b5db4059bb64a1370e5db8e2c72bb9684df0394b8ef8dac0fdb7cf78e174ea8897
7
- data.tar.gz: cd31bfcb685047eaf5b7454a8de1dbfe5cc180b46288d48768a092550114707fbe704d2843b15754778d453d4f1db24010f74b7f4d85c59b5e95eaf494aef14a
6
+ metadata.gz: 3db97c5746e8c4cf5f4ac5693df981c89d62b291e3ce49356155f513c3ab41a36180ad6f3162545deb78386479d66e64a05d873934d30dd4985bfa6b18e3c964
7
+ data.tar.gz: 05ff123e7c51ba6c8f8e49370c692e6e22b17a5f4d651b8baa025dddbe581ff2ec3c3f81d1501ea07bfbad4d9def3367f7dfbd23d3855860ba71897c4763199c
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /pkg
@@ -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
@@ -0,0 +1,11 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.4
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Metrics/MethodLength:
11
+ Max: 15
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in auto_locale.gemspec
@@ -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
@@ -1 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -1,18 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
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 |s|
6
- s.name = 'auto_locale'
7
- s.version = AutoLocale::VERSION
8
- s.authors = ['Florian Schwab']
9
- s.email = ['me@ydkn.de']
10
- s.homepage = 'http://github.com/ydkn/auto_locale'
11
- s.summary = %q{Automatically set the locale from the browsers HTTP_ACCEPT_LANGUAGE header}
12
- s.description = %q{Use this gem to automatically set the current locale from the browsers HTTP_ACCEPT_LANGUAGE header}
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
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ['lib']
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
@@ -1,53 +1,6 @@
1
- # AutoLocale
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
- require 'auto_locale/version'
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
@@ -1,20 +1,5 @@
1
- # AutoLocale
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.0'
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.0
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: 2016-07-11 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Use this gem to automatically set the current locale from the browsers
14
- HTTP_ACCEPT_LANGUAGE header
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.rdoc
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: http://github.com/ydkn/auto_locale
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
- rubyforge_project:
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:
@@ -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.