rails_set_locale 0.1.0 → 0.2.0

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: de1579113ae159463d28aa5d35c8ed7efa83da3a
4
- data.tar.gz: 645650446a0815fd6514a099df5b80f3feb84fd8
3
+ metadata.gz: 023a690fec4f556d36ab2211169bdd2fe38cad94
4
+ data.tar.gz: 2ade8ac27e36e5977ec5cf6e131babac019c9aa0
5
5
  SHA512:
6
- metadata.gz: 12a378588673b90dd0c67d0274ba690a30aa1dc52a40aed95a4fed60c96848d73cd9c0c720216f94811dd444a8de89500d6f768453c85ab77eb3679dee30c0a6
7
- data.tar.gz: 5af97bc5d5c2ea7979f6cfb345dbc1e0ac967537dc0012d80815c179a65291a0f8f668002ff208f64951bdaed35ae9e77920bb47104b44968caf79945a2d52f2
6
+ metadata.gz: e79eee79e53a00a7bfb58c928623b6a0b804a76a0e003321042df07f5210ef2949a1ca2620e5959d8b48deace04bdfcf3f5fcc0c78f2c3b71eca0bb9a6921424
7
+ data.tar.gz: 1bf0032bb1dd9a94456ea28d0b7f3185022a4d6229097fb13dd025e19d9646ec68821f0acc798a3394f4b833dee41f057c3c437e3e5e7c9f31224a8c1fa1cb73
data/README.md CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ ### Setting the Locale By Reading Various Runtime Parameters
25
+
24
26
  You application controller needs to include the module:
25
27
 
26
28
  ```
@@ -39,6 +41,28 @@ Note that the gem is still in progress. Currently, it specifies the locale from
39
41
  it saves it in the session. I plan to expand the functionality of this gem to pick up the locale from the `current_user.locale`
40
42
  or from whatever the hosting application wants the locale specification to be.
41
43
 
44
+ ### Setting the Locale Using /set_locale end-point
45
+
46
+ You can set the locale by letting your users visiting the URL:
47
+
48
+ `/set_locale`
49
+
50
+ with param `locale` specifying the new locale.
51
+
52
+ For example:
53
+
54
+ `/set_locale?locale=el`
55
+
56
+ will set the locale to the Greek locale.
57
+
58
+ The controller implemented by the `RailsSetLocale` gem, is setting the `session[:locale]` to the locale requested.
59
+
60
+ In order to implement this feature, you will have to mount the `RailsSetLocale` engine. In your routes include this:
61
+
62
+ ``` ruby
63
+ mount RailsSetLocale::Engine => "/set_locale", as: :set_locale
64
+ ```
65
+
42
66
  ## Development
43
67
 
44
68
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run `rubocop` and tests.
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSetLocale
4
+ class ApplicationController < ActionController::Base
5
+ protect_from_forgery with: :exception
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency 'rails_set_locale/application_controller'
4
+
5
+ module RailsSetLocale
6
+ class LocaleController < ApplicationController
7
+ # GET "/set_locale?locale=XX&current_path=XXXXX"
8
+ def set_locale
9
+ new_locale = params[:locale].to_sym
10
+ I18n.locale = new_locale
11
+ session[:locale] = new_locale
12
+ redirect_to params[:return_back_to] || request.referer || root_url
13
+ end
14
+ end
15
+ end
data/bin/rails ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ #!/usr/bin/env ruby
4
+ # This command will automatically be run when you run "rails" with Rails gems
5
+ # installed from the root of your application.
6
+
7
+ ENGINE_ROOT = File.expand_path('..', __dir__)
8
+ ENGINE_PATH = File.expand_path('../lib/rails_set_locale/engine', __dir__)
9
+ APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
10
+
11
+ # Set up gems listed in the Gemfile.
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
13
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
14
+
15
+ require 'rails/all'
16
+ require 'rails/engine/commands'
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RailsSetLocale::Engine.routes.draw do
4
+ root to: 'locale#set_locale'
5
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails_set_locale/version'
4
+ require 'rails_set_locale/engine'
4
5
  require 'http_accept_language'
5
6
 
6
7
  # All the functionality of this gem will be exposed
@@ -9,7 +10,7 @@ require 'http_accept_language'
9
10
  module RailsSetLocale
10
11
  def self.included(base)
11
12
  base.before_action :set_locale
12
- base.include HttpAcceptLanguage::EasyAccess unless base.included_modules.include?(HttpAcceptLanguage::EasyAccess)
13
+ base.include HttpAcceptLanguage::EasyAccess unless base.included_modules.include?(HttpAcceptLanguage::EasyAccess)
13
14
  base.include InstanceMethods
14
15
  end
15
16
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSetLocale
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace RailsSetLocale
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSetLocale
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_set_locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Panos Matsinopoulos
@@ -129,6 +129,7 @@ email:
129
129
  - panagiotis@matsinopoulos.gr
130
130
  executables:
131
131
  - console
132
+ - rails
132
133
  - setup
133
134
  extensions: []
134
135
  extra_rdoc_files: []
@@ -142,9 +143,14 @@ files:
142
143
  - LICENSE.txt
143
144
  - README.md
144
145
  - Rakefile
146
+ - app/controllers/rails_set_locale/application_controller.rb
147
+ - app/controllers/rails_set_locale/locale_controller.rb
145
148
  - bin/console
149
+ - bin/rails
146
150
  - bin/setup
151
+ - config/routes.rb
147
152
  - lib/rails_set_locale.rb
153
+ - lib/rails_set_locale/engine.rb
148
154
  - lib/rails_set_locale/version.rb
149
155
  - rails_set_locale.gemspec
150
156
  homepage: https://pmatsinopoulos.github.io